From: <yva...@us...> - 2014-07-16 08:26:44
|
Revision: 1879 http://sourceforge.net/p/jsbml/code/1879 Author: yvazirabad Date: 2014-07-16 08:26:36 +0000 (Wed, 16 Jul 2014) Log Message: ----------- CD/JSBML Synchronization additions in AbstractCellDesignerPlugin few methods changed in PluginSBMLReader to protected visibility from private SwingWork renamed to CellDesignerModelConverter Modified Paths: -------------- trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/AbstractCellDesignerPlugin.java trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/PluginSBMLReader.java Added Paths: ----------- trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/CellDesignerModelConverter.java Modified: trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/AbstractCellDesignerPlugin.java =================================================================== --- trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/AbstractCellDesignerPlugin.java 2014-07-15 22:31:25 UTC (rev 1878) +++ trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/AbstractCellDesignerPlugin.java 2014-07-16 08:26:36 UTC (rev 1879) @@ -23,18 +23,34 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.SwingWorker; import javax.xml.stream.XMLStreamException; import jp.sbi.celldesigner.plugin.CellDesignerPlugin; +import jp.sbi.celldesigner.plugin.PluginCompartment; import jp.sbi.celldesigner.plugin.PluginModel; +import jp.sbi.celldesigner.plugin.PluginReaction; import jp.sbi.celldesigner.plugin.PluginSBase; +import jp.sbi.celldesigner.plugin.PluginSpecies; +import jp.sbi.celldesigner.plugin.PluginSpeciesAlias; +import org.sbml.jsbml.Compartment; import org.sbml.jsbml.Model; +import org.sbml.jsbml.Reaction; import org.sbml.jsbml.SBMLDocument; +import org.sbml.jsbml.Species; +import org.sbml.jsbml.ext.layout.Layout; +import org.sbml.jsbml.ext.layout.LayoutModelPlugin; +import org.sbml.jsbml.util.TreeNodeChangeListener; /** * A basic implementation of a CellDesigner plug-in that takes care of @@ -65,7 +81,7 @@ /** * Map of CellDesigner PluginModels and JSBML Models */ - protected Map<PluginModel, Model> modelMap= new HashMap<PluginModel, Model>(); + protected final Map<PluginModel, Model> modelMap = Collections.synchronizedMap(new HashMap<PluginModel, Model>()); /** * @@ -78,11 +94,7 @@ reader = new PluginSBMLReader(); writer = new PluginSBMLWriter(this); } catch (Throwable t) { - t.printStackTrace(); - Throwable cause = t.getCause(); - if (cause != null) { - cause.printStackTrace(); - } + new GUIErrorConsole(t); } } @@ -107,15 +119,16 @@ public void startPlugin() throws XMLStreamException { setStarted(true); // Synchronize changes from this plug-in to CellDesigner: - if (!modelMap.containsKey(getSelectedModel())) { - SwingWorker<SBMLDocument, Throwable> worker = new SwingWork(getReader(), getSelectedModel()); + if (!compareModels(getSelectedModel())) { + SwingWorker<SBMLDocument, Throwable> worker = new CellDesignerModelConverter(getReader(), getSelectedModel()); final AbstractCellDesignerPlugin plugin = this; worker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state") && evt.getNewValue().equals(SwingWorker.StateValue.DONE)) { try { - SwingWork swing = (SwingWork)evt.getSource(); + CellDesignerModelConverter swing = (CellDesignerModelConverter)evt.getSource(); + //JOptionPane.showMessageDialog(null, new JScrollPane(new JTextArea("Called inside startPlugin"))); document = swing.get(); document.addTreeNodeChangeListener(new PluginChangeListener(plugin)); modelMap.put(swing.getPluginModel(), document.getModel()); @@ -138,6 +151,43 @@ return document; } + public boolean compareModels(PluginModel sbase) + { + for (PluginModel key : modelMap.keySet()) { + PluginModel pModel = key; + // JOptionPane.showMessageDialog(null, new JScrollPane(new JTextArea("checkSize of the mapInside: "+modelMap.size()+"\t"+sbase.getId().trim()+"\t"+pModel.getId().trim()+ + // "\t"+pModel.getId().trim().equals(sbase.getId().trim())))); + if (pModel.getId().trim().equals(sbase.getId().trim())) + { + return true; + } + } + return false; + } + + public Model getAssociatedModel(PluginModel pModel) + { + for (Map.Entry<PluginModel, Model> entry : modelMap.entrySet()) { + PluginModel pluginModel = entry.getKey(); + Model model = entry.getValue(); + if (pluginModel.getId().equals(pModel.getId())) { + return model; + } + } + return null; + } + + public void printMap() + { + String output = ""; + for (Map.Entry<PluginModel, Model> entry : modelMap.entrySet()) { + PluginModel pModel = entry.getKey(); + Model model = entry.getValue(); + output += pModel.getId() + "\tmodel Id: " + model.getId() + "\tSize of the map: "+modelMap.size()+"\n"; + } + JOptionPane.showMessageDialog(null, new JScrollPane(new JTextArea(output))); + } + /* (non-Javadoc) * @see jp.sbi.celldesigner.plugin.CellDesignerPlug#modelClosed(jp.sbi.celldesigner.plugin.PluginSBase) */ @@ -154,8 +204,18 @@ */ @Override public void modelOpened(PluginSBase sbase) { - // TODO Auto-generated method stub - System.out.println("modelOpened " + sbase); + if (sbase instanceof PluginModel) + { + PluginModel pModel = (PluginModel) sbase; + SwingWorker<SBMLDocument, Throwable> worker = new CellDesignerModelConverter(getReader(), pModel); + if (!compareModels(pModel)) { + try { + modelMap.put(pModel, reader.convertModel(pModel).getModel()); + } catch (XMLStreamException e) { + new GUIErrorConsole(e); + } + } + } } /* (non-Javadoc) @@ -163,8 +223,10 @@ */ @Override public void modelSelectChanged(PluginSBase sbase) { - // TODO Auto-generated method stub - System.out.println("modelSelectChanged " + sbase); + if (sbase instanceof PluginModel) + { + PluginModel pModel = (PluginModel)sbase; + } } /* (non-Javadoc) @@ -181,8 +243,68 @@ */ @Override public void SBaseChanged(PluginSBase sbase) { - // TODO Auto-generated method stub - System.out.println("SBaseChanged " + sbase); + PluginModel currentModel = getSelectedModel(); + Model associatedJSBMLModel = getAssociatedModel(currentModel); + Layout layout = ((LayoutModelPlugin)associatedJSBMLModel.getExtension("layout")).getLayout(0); + List<TreeNodeChangeListener> treeNodeList = new ArrayList<TreeNodeChangeListener>(); + document = new SBMLDocument(associatedJSBMLModel.getLevel(), associatedJSBMLModel.getVersion()); + document.setModel(associatedJSBMLModel); + + treeNodeList.addAll(document.getListOfTreeNodeChangeListeners()); + document.removeAllTreeNodeChangeListeners(); + + if (sbase instanceof PluginCompartment) + { + PluginCompartment pCompartment = (PluginCompartment)sbase; + Compartment newCompartment = null; + try { + newCompartment = reader.readCompartment(pCompartment); + } catch (XMLStreamException e) { + new GUIErrorConsole(e); + } + + layout.removeCompartmentGlyph("cGlyph_" + pCompartment.getId()); + layout.removeTextGlyph("tGlyph_" + pCompartment.getId()); + LayoutConverter.extractLayout((PluginCompartment)sbase, layout); + associatedJSBMLModel.removeCompartment(newCompartment.getId()); + associatedJSBMLModel.addCompartment(newCompartment); + } + else if (sbase instanceof PluginSpecies) + { + PluginSpecies pSpecies = (PluginSpecies) sbase; + Species newSpecies = null; + try { + newSpecies = reader.readSpecies(pSpecies); + } catch (XMLStreamException e) { + new GUIErrorConsole(e); + } + associatedJSBMLModel.removeSpecies(pSpecies.getId()); + associatedJSBMLModel.addSpecies(newSpecies); + } + else if (sbase instanceof PluginSpeciesAlias) + { + PluginSpeciesAlias pSpeciesAlias = (PluginSpeciesAlias) sbase; + layout.removeSpeciesGlyph("sGlyph_" + pSpeciesAlias.getSpecies().getId()); + layout.removeTextGlyph("tGlyph_" + pSpeciesAlias.getSpecies().getId()); + LayoutConverter.extractLayout(pSpeciesAlias, layout); + } + else if (sbase instanceof PluginReaction) + { + PluginReaction pReaction = (PluginReaction) sbase; + Reaction newReaction = null; + try { + newReaction = reader.readReaction(pReaction); + } catch (XMLStreamException e) { + new GUIErrorConsole(e); + } + layout.removeReactionGlyph("rGlyph_" + pReaction.getId()); + layout.removeTextGlyph("tGlyph_" + pReaction.getId()); + LayoutConverter.extractLayout(pReaction, layout); + associatedJSBMLModel.removeReaction(newReaction.getId()); + associatedJSBMLModel.addReaction(newReaction); + } + document.setModel(associatedJSBMLModel); + document.addAllChangeListeners(treeNodeList); } /* (non-Javadoc) Copied: trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/CellDesignerModelConverter.java (from rev 1868, trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/SwingWork.java) =================================================================== --- trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/CellDesignerModelConverter.java (rev 0) +++ trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/CellDesignerModelConverter.java 2014-07-16 08:26:36 UTC (rev 1879) @@ -0,0 +1,81 @@ +/* + * $Id$ + * $URL$ + * ---------------------------------------------------------------------------- + * This file is part of JSBML. Please visit <http://sbml.org/Software/JSBML> + * for the latest version of JSBML and more information about SBML. + * + * Copyright (C) 2009-2014 jointly by the following organizations: + * 1. The University of Tuebingen, Germany + * 2. EMBL European Bioinformatics Institute (EBML-EBI), Hinxton, UK + * 3. The California Institute of Technology, Pasadena, CA, USA + * 4. The University of California, San Diego, La Jolla, CA, USA + * 5. The Babraham Institute, Cambridge, UK + * 6. Marquette University, Milwaukee, WI, USA + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation. A copy of the license agreement is provided + * in the file named "LICENSE.txt" included with this software distribution + * and also available online as <http://sbml.org/Software/JSBML/License>. + * ---------------------------------------------------------------------------- + */ +package org.sbml.jsbml.celldesigner; + +import javax.swing.SwingWorker; + +import jp.sbi.celldesigner.plugin.PluginModel; + +import org.sbml.jsbml.Model; +import org.sbml.jsbml.SBMLDocument; +import org.sbml.jsbml.ext.layout.LayoutConstants; +import org.sbml.jsbml.ext.render.RenderConstants; + + +/** + * @author Ibrahim Vazirabad + * @version $Rev$ + * @since 1.0 + * @date Jun 10, 2014 + */ +public class CellDesignerModelConverter extends SwingWorker<SBMLDocument, Throwable> { + + private PluginSBMLReader sbmlReader; + private PluginModel pluginModel; + + + /** + * @return the pluginModel + */ + public PluginModel getPluginModel() { + return pluginModel; + } + + /** + * @param reader + * @param selectedModel + */ + public CellDesignerModelConverter(PluginSBMLReader reader, PluginModel selectedModel) { + sbmlReader=reader; + pluginModel=selectedModel; + } + + @Override + protected SBMLDocument doInBackground() throws Exception { + try{ + Model model = sbmlReader.convertModel(pluginModel); + SBMLDocument doc = new SBMLDocument(model.getLevel(), model.getVersion()); + doc.addNamespace(LayoutConstants.shortLabel, "xmlns", LayoutConstants.getNamespaceURI(doc.getLevel(), doc.getVersion())); + doc.addNamespace(RenderConstants.shortLabel, "xmlns", RenderConstants.getNamespaceURI(doc.getLevel(), doc.getVersion())); + doc.getSBMLDocumentAttributes().put(LayoutConstants.shortLabel + ":required", "false"); + doc.getSBMLDocumentAttributes().put(RenderConstants.shortLabel + ":required", "false"); + doc.setModel(model); + return doc; + } + catch (Throwable e) + { + publish(e); + } + return null; + } +}; Modified: trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/PluginSBMLReader.java =================================================================== --- trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/PluginSBMLReader.java 2014-07-15 22:31:25 UTC (rev 1878) +++ trunk/modules/celldesigner/src/org/sbml/jsbml/celldesigner/PluginSBMLReader.java 2014-07-16 08:26:36 UTC (rev 1879) @@ -233,7 +233,7 @@ * @return * @throws XMLStreamException */ - private Compartment readCompartment(PluginCompartment compartment) throws XMLStreamException { + protected Compartment readCompartment(PluginCompartment compartment) throws XMLStreamException { Compartment c = new Compartment(compartment.getId(), level, version); PluginUtils.transferNamedSBaseProperties(compartment, c); if ((compartment.getOutside() != null) && (compartment.getOutside().length() > 0) && (c.getLevel() < 3)) { @@ -480,7 +480,7 @@ PluginCompartment pCompartment = originalModel.getCompartment(i); model.addCompartment(readCompartment(pCompartment)); LayoutConverter.extractLayout(pCompartment, layout); - RenderConverter.extractRenderInformation(pCompartment, renderPlugin); + //RenderConverter.extractRenderInformation(pCompartment, renderPlugin, layout); //gets the compartment size layout.createDimensions("Layout_Size", originalModel.getCompartment(i).getWidth(), originalModel.getCompartment(i).getHeight(), 1d); @@ -609,7 +609,7 @@ * @return * @throws XMLStreamException */ - private Reaction readReaction(PluginReaction reac) throws XMLStreamException { + protected Reaction readReaction(PluginReaction reac) throws XMLStreamException { logger.debug("Translating reaction " + reac.getId()); Reaction reaction = new Reaction(reac.getId(), level, version); PluginUtils.transferNamedSBaseProperties(reac, reaction); @@ -675,7 +675,7 @@ * @return * @throws XMLStreamException */ - private Species readSpecies(PluginSpecies species) throws XMLStreamException { + protected Species readSpecies(PluginSpecies species) throws XMLStreamException { Species s = new Species(level, version); PluginUtils.transferNamedSBaseProperties(species, s); int sbo = SBO.convertAlias2SBO(species.getSpeciesAlias(0).getType()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |