Search in sources :

Example 1 with NodeInfo

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

the class MyRenderer method getTreeCellRendererComponent.

/**
 * This method modifies the way the nodes are represented upon their status and type.
 * Creation date: (7/27/2000 6:41:57 PM)
 * @return java.awt.Component
 */
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    // 
    if (value instanceof NodeInfo) {
        NodeInfo nodeInfo = (NodeInfo) value;
        // Check the kind of node to decide which icon to use
        if (nodeInfo.isAttribute()) {
            switch(nodeInfo.getStatus()) {
                case NodeInfo.STATUS_NORMAL:
                    component.setIcon(this.fieldAttributeIcon);
                    setToolTipText(null);
                    break;
                case NodeInfo.STATUS_NEW:
                    component.setIcon(this.fieldNewAttributeIcon);
                    component.setForeground(java.awt.Color.blue);
                    setToolTipText("New " + nodeInfo.getName());
                    break;
                case NodeInfo.STATUS_REMOVED:
                    component.setIcon(this.fieldRemovedAttributeIcon);
                    component.setForeground(java.awt.Color.red);
                    setToolTipText("Removed " + nodeInfo.getName());
                    break;
                case NodeInfo.STATUS_CHANGED:
                    component.setIcon(this.fieldChangedAttributeIcon);
                    component.setForeground(java.awt.Color.gray);
                    setToolTipText("Altered " + nodeInfo.getName());
                    break;
                default:
                    component.setIcon(this.fieldBadAttributeIcon);
                    setToolTipText(null);
            }
        } else {
            // is an element
            switch(nodeInfo.getStatus()) {
                case NodeInfo.STATUS_NORMAL:
                    component.setIcon(this.fieldFolderIcon);
                    setToolTipText(null);
                    break;
                case NodeInfo.STATUS_NEW:
                    component.setIcon(this.fieldNewFolderIcon);
                    component.setForeground(java.awt.Color.blue);
                    setToolTipText("New " + nodeInfo.getName());
                    break;
                case NodeInfo.STATUS_REMOVED:
                    component.setIcon(this.fieldRemovedFolderIcon);
                    component.setForeground(java.awt.Color.red);
                    setToolTipText("Removed " + nodeInfo.getName());
                    break;
                case NodeInfo.STATUS_CHANGED:
                    component.setIcon(this.fieldChangedFolderIcon);
                    component.setForeground(java.awt.Color.gray);
                    setToolTipText("Altered " + nodeInfo.getName());
                    break;
                default:
                    component.setIcon(this.fieldBadFolderIcon);
                    setToolTipText(null);
            }
        }
    }
    return component;
}
Also used : NodeInfo(cbit.xml.merge.NodeInfo) JLabel(javax.swing.JLabel)

Example 2 with NodeInfo

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

the class TMLPanel method extract.

/**
 * This method extracts from the given NodeInfo node, the nodes with the given status.
 * Creation date: (9/12/2001 4:40:12 PM)
 * @return cbit.xml.merge.NodeInfo
 * @param originalNode cbit.xml.merge.NodeInfo
 * @param status int
 */
private NodeInfo extract(NodeInfo original, int status) {
    NodeInfo newNode = null;
    if ((original.getName().equals(XMLTags.VersionTag) || original.getName().equals(XMLTags.KeyValueAttrTag)) && fieldDiffTree.isIgnoringVersionInfo()) {
        if (status == NodeInfo.STATUS_REMOVED) {
            // i.e. represents the baseline
            status = NodeInfo.STATUS_NORMAL;
            newNode = new NodeInfo(original.getName(), original.getValue(), status, original.isAttribute());
        } else if (status == NodeInfo.STATUS_NEW) {
            // i.e. represents the modified
            // ignore version info for the modified
            newNode = null;
        }
    } else {
        // process himself
        if (original.getStatus() == NodeInfo.STATUS_CHANGED) {
            // create the copy
            if (status == NodeInfo.STATUS_REMOVED) {
                newNode = new NodeInfo(original.getName(), original.getValue(), status, original.isAttribute());
            } else {
                if (status == NodeInfo.STATUS_NEW) {
                    newNode = new NodeInfo(original.getName(), ((ChangedNodeInfo) original).getModified(), status, original.isAttribute());
                } else {
                    throw new IllegalArgumentException("Invalid option: " + status);
                }
            }
        } else {
            if (original.getStatus() == status || original.getStatus() == NodeInfo.STATUS_NORMAL || original.getStatus() == NodeInfo.STATUS_PROBLEM) {
                newNode = new NodeInfo(original.getName(), original.getValue(), status, original.isAttribute());
            }
        }
    }
    // Now process its children
    if (newNode != null) {
        Enumeration enum1 = original.children();
        // copy children
        while (enum1.hasMoreElements()) {
            NodeInfo temp = extract((NodeInfo) enum1.nextElement(), status);
            if (temp != null) {
                newNode.add(temp);
            }
        }
    }
    return newNode;
}
Also used : Enumeration(java.util.Enumeration) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo)

Example 3 with NodeInfo

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

the class TMLPanel method setNodeInfo.

/**
 * Sets the nodeInfo property (cbit.xml.merge.NodeInfo) value.
 * @param nodeInfo The new value for the property.
 * @see #getNodeInfo
 */
private void setNodeInfo(NodeInfo nodeInfo) {
    NodeInfo oldValue = fieldNodeInfo;
    fieldNodeInfo = nodeInfo;
    getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    if (nodeInfo != null) {
        getTree().setModel(new DefaultTreeModel(getNodeInfo(), false));
    } else {
        getTree().setModel(null);
    }
    firePropertyChange("nodeInfo", oldValue, nodeInfo);
}
Also used : NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 4 with NodeInfo

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

the class TMLPanel method keepModified.

/**
 * This method processes the subnodes of the given Node so that it keeps the Modified remaining nodes.
 * Creation date: (9/11/2001 4:55:11 PM)
 * @param object java.lang.Object
 */
private void keepModified(Object object) {
    if (object instanceof NodeInfo) {
        NodeInfo currentNode = (NodeInfo) object;
        if (currentNode.getStatus() != NodeInfo.STATUS_REMOVED) {
            // process himself
            currentNode.setStatus(NodeInfo.STATUS_NORMAL);
            if (currentNode instanceof ChangedNodeInfo) {
                String temp = ((ChangedNodeInfo) currentNode).getValue();
                ((ChangedNodeInfo) currentNode).setValue(((ChangedNodeInfo) currentNode).getModified());
                ((ChangedNodeInfo) currentNode).setModified(temp);
            }
            ((javax.swing.tree.DefaultTreeModel) (getTree().getModel())).nodeChanged(currentNode);
            // process its subnodes
            LinkedList subNodes = new LinkedList();
            for (Enumeration enumNodes = currentNode.children(); enumNodes.hasMoreElements(); ) {
                subNodes.add(enumNodes.nextElement());
            }
            Iterator iterator = subNodes.iterator();
            while (iterator.hasNext()) {
                NodeInfo tempNode = (NodeInfo) iterator.next();
                keepModified(tempNode);
            }
            // update parents of the change
            updateParents(currentNode.getParent(), currentNode);
        } else {
            NodeInfo parentNode = currentNode;
            // track the farest parent who has as a status of REMOVED
            while ((parentNode.getParent() != null) && (((NodeInfo) parentNode.getParent()).getStatus() == NodeInfo.STATUS_REMOVED)) {
                parentNode = (NodeInfo) parentNode.getParent();
            }
            // update parents of the change
            updateParents(parentNode, currentNode);
            // eliminate that node and its subtree (remove the node of interest, not the parent one).
            ((DefaultTreeModel) (getTree().getModel())).removeNodeFromParent(currentNode);
        }
    } else {
        throw new IllegalArgumentException("KeepModified found an unknown type of node:" + object.getClass().getName());
    }
}
Also used : Enumeration(java.util.Enumeration) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) Iterator(java.util.Iterator) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) LinkedList(java.util.LinkedList)

Example 5 with NodeInfo

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

the class TMLPanel method processComparisonResult.

// process events for loading the model displayed in the comparison panel
public VCDocument processComparisonResult() throws Exception {
    try {
        NodeInfo root = (NodeInfo) getTree().getModel().getRoot();
        // if (!isNormal(root)) {
        // displayMessage(this, "Please resolve all tagged elements/attributes before proceeding.");
        // }
        String xmlStr = root.toXmlString();
        // System.out.println(xmlStr);
        Element rootElement = (XmlUtil.stringToXML(xmlStr, null)).getRootElement();
        // ?
        XmlReader reader = new XmlReader(true);
        String rootName = rootElement.getName();
        Document doc = rootElement.getDocument();
        VCDocument vcDoc = null;
        if (rootName.equals(XMLTags.BioModelTag)) {
            String docSoftwareVersion = rootElement.getAttributeValue(XMLTags.SoftwareVersionAttrTag);
            vcDoc = reader.getBioModel(rootElement, (docSoftwareVersion == null ? null : VCellSoftwareVersion.fromString(docSoftwareVersion)));
        } else if (rootName.equals(XMLTags.MathModelTag)) {
            vcDoc = reader.getMathModel(rootElement);
        } else if (rootName.equals(XMLTags.GeometryTag)) {
            vcDoc = reader.getGeometry(rootElement);
        } else {
            throw new Exception("Invalid root for the tree");
        }
        return vcDoc;
    } catch (java.lang.Exception ivjExc) {
        handleException(ivjExc);
        throw ivjExc;
    }
}
Also used : VCDocument(org.vcell.util.document.VCDocument) NodeInfo(cbit.xml.merge.NodeInfo) ChangedNodeInfo(cbit.xml.merge.ChangedNodeInfo) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) VCDocument(org.vcell.util.document.VCDocument) Document(org.jdom.Document)

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