Example usage for javax.swing.tree DefaultMutableTreeNode setUserObject

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

Introduction

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

Prototype

public void setUserObject(Object userObject) 

Source Link

Document

Sets the user object for this node to userObject.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

public void addStructMap(StructMapCollection structure) {
    if (theStructMapTree == null) {
        return;//from  w  w  w .ja  va 2 s.c om
    }
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    rootNode.setUserObject("Structure Map");
    DepositTreeModel model;
    if (theStructMapTree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) theStructMapTree.getModel();
        model.setRoot(rootNode);
    } else {
        model = new DepositTreeModel(rootNode, ETreeType.StructMapTree);
        theStructMapTree.setModel(model);
    }

    for (int i = 0; structure != null && i < structure.size(); i++) {
        addStructMapItem(structure.get(i), rootNode, false);
    }
    // If Struct Map is not being built through the Swing Worker Thread.
    if (buildIE_Worker == null) {
        expandNode(theStructMapTree, rootNode, true);
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java

@Test
public final void testSetup() {
    isVisible = false;//  w w w  .j a v a  2s  . c om
    /*
     * _includeCMS2Search = false; _includeCMS1Search = false;
     * _includeNoCMSOption = false;
     */
    try {
        depositPresenter.setupScreen();
        loginPresenter.login(LOGIN_NAME, LOGIN_PASSWORD);
    } catch (Exception ex) {
        fail();
    }
    assertTrue(isVisible);
    /*
     * assertTrue(_includeCMS2Search); assertTrue(_includeCMS1Search);
     * assertTrue(_includeNoCMSOption);
     */

    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    File test = new File(RESOURCES_INPUT_PATH);
    FileSystemObject fso = FileSystemObject.create("Input", test, null);
    rootNode.setUserObject(fso);
    DepositTreeModel model = new DepositTreeModel(rootNode, ETreeType.EntityTree);
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) theFrame.treeFileSystem
            .getLastSelectedPathComponent();
    assertTrue(selectedNode == null);
    theFrame.treeFileSystem.setModel(model);
    // _presenter.selectIEFile(fso);
    depositPresenter.selectNode(fso, ETreeType.EntityTree);
    selectedNode = (DefaultMutableTreeNode) theFrame.treeFileSystem.getLastSelectedPathComponent();
    assertTrue(selectedNode.equals(rootNode));
    assertFalse(theFrame.cursorIsWaiting);
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenterTest.java

private final FileSystemObject setRoot() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    String description = "NamedStuff";
    File theFile = new File(RESOURCES_INPUT_PATH_NAMED);
    FSOCollection theChildren = null;//from  www. j  av  a  2  s . com
    FileSystemObject root = new FileSystemObject(description, theFile, theChildren);
    node.setUserObject(root);
    depositPresenter.setEntityRoot(node);
    return root;
}

From source file:org.icefaces.application.showcase.view.builder.ApplicationBuilder.java

/**
 * Gets/searches for a node that has the specified id and returns a fully
 * contstructed DefaultTreeModel for the found nodes children.
 *
 * @param nodeId unique id for a given node
 * @return found Node, otherwise null//from  w w  w  .j ava2 s .c o  m
 */
public DefaultTreeModel getChildNodeTree(String nodeId) {
    Node parentNode = nodeSearch(application.getNavigation().getNode(), nodeId);
    // if we have a node build up our tree. 
    if (parentNode != null) {
        // create root node, which will be hidden by component attribute
        // settings.
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
        NavigationTreeNode userObject = new NavigationTreeNode(rootNode);
        userObject.setText("rootNode");
        userObject.setExpanded(true);
        rootNode.setUserObject(userObject);

        // build a tree based on child nodes of parentNode.
        buildChildNodes(rootNode, parentNode.getNode());
        return new DefaultTreeModel(rootNode);
    }
    return null;
}

From source file:org.icefaces.application.showcase.view.builder.ApplicationBuilder.java

private void buildChildNodes(DefaultMutableTreeNode parentNode, List<Node> childNodes) {

    DefaultMutableTreeNode treeNode;
    NavigationTreeNode navNode;//from w w w .j  av a  2 s . c o m

    for (Node node : childNodes) {
        treeNode = new DefaultMutableTreeNode();
        navNode = new NavigationTreeNode(treeNode);
        navNode.setText(node.getLabel());
        navNode.setNodeId(node.getId());
        navNode.setExpanded(node.isExpanded());
        treeNode.setUserObject(navNode);
        navNode.setLeaf(node.isLeaf());
        parentNode.add(treeNode);

        if (node.getNode() != null && node.getNode().size() > 0) {
            buildChildNodes(treeNode, node.getNode());
        }
    }
}

From source file:org.jbpcc.admin.beans.navigation.TreeBean.java

/**
 * Initialises tree root and calls method to build tree of configuration schema changes
 *///from  www  .ja  v a 2 s .co m
public TreeBean() {

    DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
    UrlNodeUserObject rootObject = new UrlNodeUserObject(rootTreeNode, this);
    rootObject.setText("Empty root");
    rootObject.setExpanded(true);

    Document dom = readDOM();
    Element docElement = dom.getDocumentElement(); // get root element

    if (!docElement.getNodeName().equals(ELEM_APP)) {
        throw new IllegalArgumentException("Illegal tree menu configuration");
    }

    rootObject.setUrl(APP_CONTEXT_PATH + docElement.getAttribute(ATTR_URL));
    rootObject.setIconUrl(docElement.getAttribute(ATTR_ICON));
    rootObject.setSelectedNode(true);
    rootTreeNode.setUserObject(rootObject);
    rootNodeObject = (UrlNodeUserObject) rootTreeNode.getUserObject();
    rootNodeObject.setSelectedNode(true);

    model = new DefaultTreeModel(rootTreeNode);

    buildTree(rootTreeNode, docElement);
}

From source file:org.jbpcc.admin.beans.navigation.TreeBean.java

private DefaultMutableTreeNode createParentMenuItem(Element itemElement) {
    DefaultMutableTreeNode menuItem = new DefaultMutableTreeNode();
    UrlNodeUserObject menuObject = new UrlNodeUserObject(menuItem, this);

    if (itemElement.hasChildNodes()) {
        menuObject.setExpanded(true);/*from   w  w  w  .j a va  2s  .co  m*/
    } else {
        menuObject.setLeaf(true);
    }

    menuObject.setText(getLabelResource(itemElement));

    String value = itemElement.getAttribute(ATTR_URL);
    if (StringUtils.isNotBlank(value)) {
        value = APP_CONTEXT_PATH + value;
        menuObject.setUrl(value);
    }

    value = itemElement.getAttribute(ATTR_ICON);
    if (StringUtils.isNotBlank(value)) {
        menuObject.setIconUrl(value);
    }

    menuItem.setUserObject(menuObject);

    return menuItem;
}

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

/**
 *  Description of the Method/*from www  . ja v a2s .  co m*/
 */
void updateTreeNode() {
    DefaultMutableTreeNode selectedNode = getSelectedNode();

    selectedNode
            .setUserObject(new TreeConcept((Concept) Dispatcher.getDispatcher(Concept.class).getValueObject()));

    /*
     * Announcing the node structure change triggers the necessary repaint to
     * display the effects of changes.
     */
    DefaultTreeModel model = (DefaultTreeModel) getModel();

    model.nodeStructureChanged(selectedNode);
}

From source file:ser321.media.MediaJavaClient.java

/**
 * create and initialize nodes in the JTree of the left pane.
 * buildInitialTree is called by MediaLibraryGui to initialize the JTree.
 * Classes that extend MediaLibraryGui should override this method to 
 * perform initialization actions specific to the extended class.
 * The default functionality is to set base as the label of root.
 * In your solution, you will probably want to initialize by deserializing
 * your library and displaying the categories and subcategories in the
 * tree./*from  w w  w.j  a  v  a2s.  c o  m*/
 * @param root Is the root node of the tree to be initialized.
 * @param base Is the string that is the root node of the tree.
 */
public void buildInitialTree(DefaultMutableTreeNode root, String base) {
    //set up the context and base name
    try {
        root.setUserObject(base);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "exception initial tree:" + ex);
        ex.printStackTrace();
    }
}

From source file:wilos.presentation.web.tree.TreeBean.java

/**
 * Sets PROJECT_ID attribute to DEFAULT_PROJECT_ID and cleans tree and node
 * to show Must be called at participant logout
 *///from w  w w  . jav  a2  s  .  c  o  m

public DefaultMutableTreeNode getDefaultTree() {
    DefaultMutableTreeNode defaultTree = new DefaultMutableTreeNode();
    WilosObjectNode iceUserObject = new WilosObjectNode(defaultTree);

    ResourceBundle bundle = ResourceBundle.getBundle("wilos.resources.messages",
            FacesContext.getCurrentInstance().getApplication().getDefaultLocale());
    iceUserObject.setText(bundle.getString("navigation.tree.defaulttreenodetext"));
    defaultTree.setUserObject(iceUserObject);
    return defaultTree;
}