Search in sources :

Example 6 with NodeInfo

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

the class TMLPanel method disassociate.

/**
 * Allows a node to split into two, thus the 'changed' node type can have their different attributes in two different elements.
 */
private void disassociate(Object lastSelected) {
    if (lastSelected instanceof NodeInfo) {
        NodeInfo selected = (NodeInfo) lastSelected;
        // for now, cannot split the root element.
        if (selected.isRoot()) {
            displayMessage(this, "Cannot split the root element.");
            return;
        }
        // for now, only split elements, not attributes.
        if (selected.isAttribute()) {
            displayMessage(this, "Can only split whole elements, not individual attributes.");
            return;
        }
        // create the two new nodes
        NodeInfo baseLineNode = extract(selected, NodeInfo.STATUS_REMOVED);
        NodeInfo modifiednode = extract(selected, NodeInfo.STATUS_NEW);
        // erase the original one
        NodeInfo parent = (NodeInfo) selected.getParent();
        ((DefaultTreeModel) (getTree().getModel())).removeNodeFromParent(selected);
        // add the two new nodes
        parent.add(baseLineNode);
        parent.add(modifiednode);
        ((DefaultTreeModel) (getTree().getModel())).reload(parent);
    }
}
Also used : NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 7 with NodeInfo

use of cbit.xml.merge.NodeInfo 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 8 with NodeInfo

use of cbit.xml.merge.NodeInfo 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 9 with NodeInfo

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

the class TMLPanel method updateParents.

// parentNode is not necessarily the direct parent.
private void updateParents(javax.swing.tree.TreeNode parentnode, javax.swing.tree.TreeNode node) {
    if (parentnode == null) {
        // nothing to update.
        return;
    }
    boolean ok = true;
    // Check the children, unless there is no need to.
    if (parentnode != node) {
        for (java.util.Enumeration mychilds = parentnode.children(); mychilds.hasMoreElements(); ) {
            NodeInfo childNode = (NodeInfo) mychilds.nextElement();
            if (childNode == node) {
                // same reference; the status of this one has already been set
                continue;
            }
            if (childNode.getStatus() != NodeInfo.STATUS_NORMAL) {
                ok = false;
                break;
            }
        }
    }
    // If evrything is OK, then change the status to Normal
    if (ok) {
        ((NodeInfo) parentnode).setStatus(NodeInfo.STATUS_NORMAL);
        ((javax.swing.tree.DefaultTreeModel) (getTree().getModel())).nodeChanged(parentnode);
        updateParents(parentnode.getParent(), parentnode);
    }
}
Also used : Enumeration(java.util.Enumeration) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 10 with NodeInfo

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

the class TMLPanel method getCurrentBaselineText.

private String getCurrentBaselineText() {
    Object object = getTree().getLastSelectedPathComponent();
    String baselineText = "";
    if (object instanceof NodeInfo) {
        NodeInfo node = (NodeInfo) object;
        if (node != null && node.getStatus() != NodeInfo.STATUS_NEW) {
            baselineText = node.getValue() != null ? node.getValue() : "";
        }
    }
    return (baselineText);
}
Also used : NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo)

Aggregations

NodeInfo (cbit.xml.merge.NodeInfo)13 ChangedNodeInfo (cbit.xml.merge.ChangedNodeInfo)10 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)6 Enumeration (java.util.Enumeration)4 XmlTreeDiff (cbit.xml.merge.XmlTreeDiff)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 Element (org.jdom.Element)2 ExpressionException (cbit.vcell.parser.ExpressionException)1 XmlReader (cbit.vcell.xml.XmlReader)1 IOException (java.io.IOException)1 JLabel (javax.swing.JLabel)1 TreePath (javax.swing.tree.TreePath)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Document (org.jdom.Document)1 SBMLException (org.sbml.jsbml.SBMLException)1 SbmlException (org.vcell.sbml.SbmlException)1 VCDocument (org.vcell.util.document.VCDocument)1