Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getUserObject.

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:org.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java

/**
 * <p><!-- Method description --></p>
 *
 *
 * @param node/*from  w ww. j a  v  a 2 s .co  m*/
 *
 * @return
 */
public String getNodeTextToSearch(final DefaultMutableTreeNode node) {
    final Object userObject = node.getUserObject();
    final StringBuffer conceptName = new StringBuffer();

    // Objects whos children have not been loaded yet will return a Boolean
    // as a user object. We should ignore these as much as we can.
    if (userObject instanceof TreeConcept) {
        final TreeConcept concept = (TreeConcept) node.getUserObject();
        final Concept c = concept.getConcept();

        /*
         * The text is actually a composite of all names,
         * including primary, secondary, and common
         */
        final String[] names = c.getConceptNamesAsStrings();

        for (int i = 0; i < names.length; i++) {
            conceptName.append(names[i]);
            conceptName.append(" ");
        }
    }

    return conceptName.toString();
}

From source file:org.mbari.aved.ui.classifier.knowledgebase.SearchableConceptTreePanel.java

/**
 * Loads the branch of a particular concept. This method does the following
 * <ol>//from   w w w .  ja v a2s.co  m
 *      <li>Walks from the concept up the tree to the root concept, storing
 *      the concepts in a list. (This is very fast)</li>
 *  <li>Starts walking from the root down (using lazyExpand), searching each
 *      childnode for a matching primary name (which was stored in the first
 *      step</li>
 *  <li>If a matching primary name is found this stops otherwise
 *              it opens the next level and searches for the next mathc in the list.</li>
 *  <li></li>
 * </ol>
 * @param concept
 */
private void openNode(final Concept concept) {
    if (log.isDebugEnabled()) {
        log.debug("Opening node containing " + concept);
    }

    if (concept == null) {
        return;
    }

    // Get the list of concepts up to root
    final LinkedList conceptList = new LinkedList();
    Concept c = concept;

    while (c != null) {
        conceptList.add(c);
        c = (Concept) c.getParentConcept();
    }

    // Walk the tree from root on down opening nodes as we go
    final ListIterator i = conceptList.listIterator(conceptList.size());

    // Skip the root
    i.previous();

    final JTree tree = getJTree();
    final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    TreePath path = new TreePath(rootNode.getPath());

    tree.setSelectionPath(path);

    DefaultMutableTreeNode parentNode = rootNode;

    while (i.hasPrevious()) {
        c = (Concept) i.previous();

        final TreeConcept parentTreeConcept = (TreeConcept) parentNode.getUserObject();

        parentTreeConcept.lazyExpand(parentNode);

        // treeModel.reload(parentNode);
        final Enumeration enm = parentNode.children();

        while (enm.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) enm.nextElement();
            final TreeConcept tc = (TreeConcept) node.getUserObject();

            if (tc.getName().equals(c.getPrimaryConceptNameAsString())) {
                parentNode = node;

                break;
            }
        }
    }

    final TreeNode _parentNode = parentNode;

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            treeModel.reload(_parentNode);
            tree.scrollPathToVisible(new TreePath(_parentNode));
        }
    });
}

From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java

public void dataNodeChanged(DataNodeEvent e) {

    DefaultMutableTreeNode node = getProjectModel()
            .getNodeForObjectPath(new Object[] { mediator.getCurrentDataDomain(), e.getDataNode() });

    if (node != null) {

        if (e.isNameChange()) {
            positionNode((DefaultMutableTreeNode) node.getParent(), node,
                    Comparators.getDataDomainChildrenComparator());
            showNode(node);//from  w w w.  jav a 2 s  . c  o m
        } else {

            getProjectModel().nodeChanged(node);

            // check for DataMap additions/removals...

            Object[] maps = e.getDataNode().getDataMaps().toArray();
            int mapCount = maps.length;

            // DataMap was linked
            if (mapCount > node.getChildCount()) {

                for (int i = 0; i < mapCount; i++) {
                    boolean found = false;
                    for (int j = 0; j < node.getChildCount(); j++) {
                        DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j);
                        if (maps[i] == child.getUserObject()) {
                            found = true;
                            break;
                        }
                    }

                    if (!found) {
                        DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode(maps[i], false);
                        positionNode(node, newMapNode, Comparators.getNamedObjectComparator());
                        break;
                    }
                }
            }
            // DataMap was unlinked
            else if (mapCount < node.getChildCount()) {
                for (int j = 0; j < node.getChildCount(); j++) {
                    boolean found = false;
                    DefaultMutableTreeNode child;
                    child = (DefaultMutableTreeNode) node.getChildAt(j);
                    Object obj = child.getUserObject();
                    for (int i = 0; i < mapCount; i++) {
                        if (maps[i] == obj) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        removeNode(child);
                        break;
                    }
                }
            }
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.CreateConsentServiceServlet.java

/**
 * This method provides upon request the root of the organisation-tree and
 * the first batch of it's children.//  www.  j  a v a2  s.com
 */
@SuppressWarnings("rawtypes")
private void requestTypeTreeRoot() {

    try {

        DefaultMutableTreeNode node = ccService.getOIDTreeRoot();

        Vector<JSONObject> vjbo = new Vector<JSONObject>();

        for (Enumeration e = node.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            JSONObject jso = new JSONObject();
            jso.put("name", ((OIDObject) n.getUserObject()).getName());
            jso.put("identifier", ((OIDObject) n.getUserObject()).getIdentifier());
            jso.put("hasChildren", !n.isLeaf());
            jso.put("isActive", ((OIDObject) n.getUserObject()).isActive());

            vjbo.add(jso);
        }

        JSONObject root = new JSONObject();
        root.put("name", ((OIDObject) node.getUserObject()).getName());
        root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
        root.put("hasChildren", !node.isLeaf());
        root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
        root.put("children", new JSONArray(vjbo));

        writeJSONObject(root);

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.CreateConsentServiceServlet.java

/**
 * This method handles requests asking for all nodes containing the given
 * String// www.jav a 2  s . c  om
 * 
 */
private void requestTypeSearchTree() {

    String searchString = request.getParameter("searchstring").trim();

    if (searchString.equalsIgnoreCase("")) {

        requestTypeTreeRoot();

    } else {
        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ccService.getOIDTreeNodes(searchString)
                    .getRoot();

            ConsentCreatorUtilities consentCreatorUtilities = ConsentCreatorUtilities.getInstance();

            Vector<JSONObject> vjbo = consentCreatorUtilities.traverseTreeForExpand(node);

            JSONObject root = new JSONObject();
            root.put("name", ((OIDObject) node.getUserObject()).getName());
            root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
            root.put("hasChildren", !node.isLeaf());
            root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
            root.put("children", new JSONArray(vjbo));

            writeJSONObject(root);

        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.controller.PrivilegedCreateConsentServiceServlet.java

/**
 * This method handles requests asking for all nodes containing the given
 * String/*  w  w w.j  a  v a  2 s. c  o  m*/
 * 
 */
private void requestTypeSearchTree() {

    String searchString = request.getParameter("searchstring").trim();

    if (searchString.equalsIgnoreCase("")) {

        requestTypeTreeRoot();

    } else {

        try {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ccService.getOIDTreeNodes(searchString)
                    .getRoot();

            ConsentCreatorUtilities consentCreatorUtilities = ConsentCreatorUtilities.getInstance();

            Vector<JSONObject> vjbo = consentCreatorUtilities.traverseTreeForExpand(node);

            JSONObject root = new JSONObject();
            root.put("name", ((OIDObject) node.getUserObject()).getName());
            root.put("identifier", ((OIDObject) node.getUserObject()).getIdentifier());
            root.put("hasChildren", !node.isLeaf());
            root.put("isActive", ((OIDObject) node.getUserObject()).isActive());
            root.put("children", new JSONArray(vjbo));

            writeJSONObject(root);

        } catch (Exception e) {
            Logger.getLogger(this.getClass()).error(e);
        }
    }
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorService.java

/**
 * Returns all children of the TreeNode with the given ID.
 * //  w  ww  . j a v  a2  s.c o m
 * @param oid
 * @return
 */
@SuppressWarnings("rawtypes")
public Vector<OIDObject> getOIDTreeNodeChildren(String oid) {

    Vector<OIDObject> children = new Vector<OIDObject>();

    DefaultMutableTreeNode soughtNode = consentCreatorUtilites.traverseTreeOID(oid, getOIDTreeRoot());

    if (soughtNode != null) {
        for (Enumeration e = soughtNode.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode lon = (DefaultMutableTreeNode) e.nextElement();
            OIDObject o = new OIDObject(((OIDObject) lon.getUserObject()).getIdentifier(),
                    ((OIDObject) lon.getUserObject()).getName(), ((OIDObject) lon.getUserObject()).isActive());
            o.setHasChildren(!lon.isLeaf());
            children.add(o);
        }
    }
    return children;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Constructs a Vector from the given Node and it's sub-Nodes
 * //from   w w  w .j  a v  a 2s .  c  om
 * @param node
 * @return
 */
public Vector<JSONObject> traverseTreeForExpand(DefaultMutableTreeNode node) {

    try {

        Vector<JSONObject> vjbo = new Vector<JSONObject>();

        for (Enumeration e = node.children(); e.hasMoreElements();) {

            DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
            JSONObject jso = new JSONObject();
            jso.put("name", ((OIDObject) n.getUserObject()).getName());
            jso.put("identifier", ((OIDObject) n.getUserObject()).getIdentifier());
            jso.put("hasChildren", !n.isLeaf());
            jso.put("isActive", ((OIDObject) n.getUserObject()).isActive());

            if (n.getChildCount() != 0) {
                Vector<JSONObject> retvjo = traverseTreeForExpand(n);
                jso.put("children", retvjo);
            }
            vjbo.add(jso);
        }
        return vjbo;

    } catch (Exception e) {
        Logger.getLogger(this.getClass()).error(e);
    }
    return null;

}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Searches for the given oid in the given node and it's children.
 * If the node is found, it is returned.
 * /* www.java  2 s  .c o m*/
 * @param oid
 * @param node
 * @return
 */
@SuppressWarnings("rawtypes")
public DefaultMutableTreeNode traverseTreeOID(String oid, DefaultMutableTreeNode node) {
    DefaultMutableTreeNode ret = null;

    Enumeration e = node.children();
    while (e.hasMoreElements() && ret == null) {
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
        if (((OIDObject) n.getUserObject()).getIdentifier().equalsIgnoreCase(oid)) {
            ret = n;
        } else if (containsOID(oid, ((OIDObject) n.getUserObject()).getIdentifier())) {
            ret = traverseTreeOID(oid, n);
        }
    }
    return ret;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Searches for the given oid in the given node and it's children.
 * If the node is found, it is returned.
 * //from   w w w .j  a va2s.c o m
 * @param oid
 * @param node
 * @return
 */
@SuppressWarnings("rawtypes")
public DefaultMutableTreeNode traverseTreeString(String query, DefaultMutableTreeNode searchNode,
        DefaultMutableTreeNode realNode) {
    DefaultMutableTreeNode ret = null;

    Enumeration e = realNode.children();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
        if (((OIDObject) n.getUserObject()).getName().toLowerCase().contains(query)) {
            ret = n;
            TreeNode[] path = n.getPath();
            addNodeToModel(path, searchNode, 1);

        }
        if (n.getChildCount() != 0) {
            traverseTreeString(query, searchNode, n);
        }
    }
    return ret;
}