Search in sources :

Example 1 with XmlTreeDiff

use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.

the class XmlHelper method compareMerge.

/**
 * compareMerge method comment.
 */
public static cbit.xml.merge.XmlTreeDiff compareMerge(String xmlBaseString, String xmlModifiedString, DiffConfiguration comparisonSetting, boolean ignoreVersionInfo) throws XmlParseException {
    try {
        if (xmlBaseString == null || xmlModifiedString == null || xmlBaseString.length() == 0 || xmlModifiedString.length() == 0 || (!DiffConfiguration.COMPARE_DOCS_SAVED.equals(comparisonSetting) && !DiffConfiguration.COMPARE_DOCS_OTHER.equals(comparisonSetting))) {
            throw new XmlParseException("Invalid XML comparison params.");
        }
        XMLSource xmlBaseSource = new XMLSource(xmlBaseString);
        XMLSource xmlModifiedSource = new XMLSource(xmlModifiedString);
        // default setting, no validation
        Element baselineRoot = xmlBaseSource.getXmlDoc().getRootElement();
        Element modifiedRoot = xmlModifiedSource.getXmlDoc().getRootElement();
        // Merge the Documents
        XmlTreeDiff merger = new XmlTreeDiff(ignoreVersionInfo);
        @SuppressWarnings("unused") NodeInfo top = merger.merge(baselineRoot.getDocument(), modifiedRoot.getDocument(), comparisonSetting);
        // return the tree-diff instead of the root node.
        return merger;
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new XmlParseException(e);
    }
}
Also used : NodeInfo(cbit.xml.merge.NodeInfo) Element(org.jdom.Element) XmlTreeDiff(cbit.xml.merge.XmlTreeDiff) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 2 with XmlTreeDiff

use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.

the class BioModelEditorApplicationsPanel method compareButtonPressed.

private void compareButtonPressed() {
    int[] rows = table.getSelectedRows();
    if (rows == null || rows.length != 2) {
        return;
    }
    try {
        SimulationContext simContext1 = tableModel.getValueAt(rows[0]);
        SimulationContext simContext2 = tableModel.getValueAt(rows[1]);
        BioModel bioModel = simContext1.getBioModel();
        MathMappingCallback callback = new MathMappingCallback() {

            @Override
            public void setProgressFraction(float fractionDone) {
                Thread.dumpStack();
                System.out.println("---> stdout mathMapping: progress = " + (fractionDone * 100.0) + "% done");
            }

            @Override
            public void setMessage(String message) {
                Thread.dumpStack();
                System.out.println("---> stdout mathMapping: message = " + message);
            }

            @Override
            public boolean isInterrupted() {
                return false;
            }
        };
        simContext1.refreshMathDescription(callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
        simContext2.refreshMathDescription(callback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
        Xmlproducer xmlProducer = new Xmlproducer(false);
        String simContext1XML = XmlUtil.xmlToString(xmlProducer.getXML(simContext1, bioModel));
        String simContext2XML = XmlUtil.xmlToString(xmlProducer.getXML(simContext2, bioModel));
        DiffConfiguration comparisonSetting = DiffConfiguration.COMPARE_DOCS_OTHER;
        XmlTreeDiff diffTree = XmlHelper.compareMerge(simContext1XML, simContext2XML, comparisonSetting, true);
        String baselineDesc = "application " + simContext1.getName();
        String modifiedDesc = "application " + simContext2.getName();
        TMLPanel comparePanel = new TMLPanel();
        comparePanel.setXmlTreeDiff(diffTree);
        comparePanel.setBaselineVersionDescription(baselineDesc);
        comparePanel.setModifiedVersionDescription(modifiedDesc);
        ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(this);
        String title = "comparing application " + simContext1.getName() + " and " + simContext2.getName();
        ChildWindow childWindow = childWindowManager.addChildWindow(comparePanel, diffTree, title, true);
        childWindow.setSize(new Dimension(600, 600));
        childWindow.show();
    } catch (XmlParseException e) {
        e.printStackTrace();
        DialogUtils.showErrorDialog(this, "failed to compare applications: \n\n" + e.getMessage());
    }
}
Also used : DiffConfiguration(cbit.xml.merge.XmlTreeDiff.DiffConfiguration) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) Xmlproducer(cbit.vcell.xml.Xmlproducer) XmlTreeDiff(cbit.xml.merge.XmlTreeDiff) ChildWindowManager(cbit.vcell.client.ChildWindowManager) Dimension(java.awt.Dimension) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContext(cbit.vcell.mapping.SimulationContext) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) TMLPanel(cbit.xml.merge.gui.TMLPanel) BioModel(cbit.vcell.biomodel.BioModel)

Example 3 with XmlTreeDiff

use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.

the class MathDebuggerPanel method compareTree.

private void compareTree() throws PropertyVetoException, XmlParseException {
    MathModel mathModel1 = getMathModel1();
    MathModel mathModel2 = getMathModel2();
    if (mathModel1 != null && mathModel2 != null) {
        String math1XML = XmlHelper.mathModelToXML(mathModel1);
        String math2XML = XmlHelper.mathModelToXML(mathModel2);
        boolean ignoreVersion = true;
        XmlTreeDiff diffTree = cbit.vcell.xml.XmlHelper.compareMerge(math1XML, math2XML, DiffConfiguration.COMPARE_DOCS_OTHER, ignoreVersion);
        getTMLPanel().setXmlTreeDiff(diffTree);
    } else {
        DialogUtils.showErrorDialog(MathDebuggerPanel.this, "failed");
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) XmlTreeDiff(cbit.xml.merge.XmlTreeDiff)

Example 4 with XmlTreeDiff

use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.

the class TMLPanel method associate.

/**
 * This function associates two NodeInfo nodes if they share the same type and parent.
 */
private void associate() {
    TreePath[] paths = getTree().getSelectionPaths();
    if (getTree().getSelectionCount() != 2) {
        throw new IllegalArgumentException("Invalid number of selected paths: " + getTree().getSelectionCount());
    }
    // get the two selected nodes
    NodeInfo firstNode = (NodeInfo) paths[0].getLastPathComponent();
    NodeInfo secondNode = (NodeInfo) paths[1].getLastPathComponent();
    NodeInfo parent = (NodeInfo) firstNode.getParent();
    if (firstNode.isAttribute() || secondNode.isAttribute()) {
        displayMessage(this, "Can only merge elements, not attributes.");
    }
    if (parent == secondNode.getParent()) {
        if (firstNode.getName().equalsIgnoreCase(secondNode.getName())) {
            if (firstNode.getStatus() != secondNode.getStatus()) {
                // merge the two nodes
                NodeInfo result = null;
                try {
                    // this diff tree is different from the instance variable.
                    XmlTreeDiff partialDiffTree = XmlHelper.compareMerge(firstNode.toXmlString(), secondNode.toXmlString(), DiffConfiguration.COMPARE_DOCS_SAVED, fieldDiffTree.isIgnoringVersionInfo());
                    result = partialDiffTree.getMergedRootNode();
                } catch (Throwable e) {
                    // 
                    // can give more feedback ... like a JOptionPane.showMessage()
                    // 
                    handleException(e);
                }
                if (result != null) {
                    // erase the original nodes
                    DefaultTreeModel defaultTreeModel = (DefaultTreeModel) (getTree().getModel());
                    defaultTreeModel.removeNodeFromParent(firstNode);
                    defaultTreeModel.removeNodeFromParent(secondNode);
                    // add the resulting node
                    parent.add(result);
                    defaultTreeModel.reload(parent);
                } else {
                    displayMessage(this, "The merge operation could not be performed!");
                }
            } else {
                displayMessage(this, "Can only merge nodes with different status!");
            }
        } else {
            // they do not have the same type!
            displayMessage(this, "These nodes cannot be merged because they do not have the same type!");
        }
    } else {
        // they do not have the same parent!
        displayMessage(this, "These nodes cannot be merged because they do not share the same node parent!");
    }
}
Also used : TreePath(javax.swing.tree.TreePath) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) XmlTreeDiff(cbit.xml.merge.XmlTreeDiff) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 5 with XmlTreeDiff

use of cbit.xml.merge.XmlTreeDiff in project vcell by virtualcell.

the class ClientRequestManager method compareDocuments.

private XmlTreeDiff compareDocuments(final VCDocument doc1, final VCDocument doc2, DiffConfiguration comparisonSetting) throws Exception {
    VCellThreadChecker.checkCpuIntensiveInvocation();
    if ((DiffConfiguration.COMPARE_DOCS_SAVED != comparisonSetting) && (DiffConfiguration.COMPARE_DOCS_OTHER != comparisonSetting)) {
        throw new RuntimeException("Unsupported comparison setting: " + comparisonSetting);
    }
    if (doc1.getDocumentType() != doc2.getDocumentType()) {
        throw new RuntimeException("Only comparison of documents of the same type is currently supported");
    }
    String doc1XML = null;
    String doc2XML = null;
    switch(doc1.getDocumentType()) {
        case BIOMODEL_DOC:
            {
                doc1XML = XmlHelper.bioModelToXML((BioModel) doc1);
                doc2XML = XmlHelper.bioModelToXML((BioModel) doc2);
                break;
            }
        case MATHMODEL_DOC:
            {
                doc1XML = XmlHelper.mathModelToXML((MathModel) doc1);
                doc2XML = XmlHelper.mathModelToXML((MathModel) doc2);
                break;
            }
        case GEOMETRY_DOC:
            {
                doc1XML = XmlHelper.geometryToXML((Geometry) doc1);
                doc2XML = XmlHelper.geometryToXML((Geometry) doc2);
                break;
            }
    }
    final XmlTreeDiff diffTree = XmlHelper.compareMerge(doc1XML, doc2XML, comparisonSetting, true);
    return diffTree;
}
Also used : XmlTreeDiff(cbit.xml.merge.XmlTreeDiff)

Aggregations

XmlTreeDiff (cbit.xml.merge.XmlTreeDiff)7 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 NodeInfo (cbit.xml.merge.NodeInfo)2 Hashtable (java.util.Hashtable)2 BioModel (cbit.vcell.biomodel.BioModel)1 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 MathMappingCallback (cbit.vcell.mapping.SimulationContext.MathMappingCallback)1 MathModel (cbit.vcell.mathmodel.MathModel)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1 Xmlproducer (cbit.vcell.xml.Xmlproducer)1 ChangedNodeInfo (cbit.xml.merge.ChangedNodeInfo)1 DiffConfiguration (cbit.xml.merge.XmlTreeDiff.DiffConfiguration)1 TMLPanel (cbit.xml.merge.gui.TMLPanel)1 Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 TreePath (javax.swing.tree.TreePath)1