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.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java

private List<TableData> buildCompleteQueryTableList() {
    List<TableData> retval = new ArrayList<TableData>();

    Set<TableData> hs = new HashSet<TableData>();

    for (SelectColumnData scd : sqlSelectPanel.getColumnData()) {
        TableData td = scd.getTableData();
        hs.add(td);/* w  w  w  .j av a 2  s . co m*/

        if (td.getTreeNode() != null) {
            // run up the tree for each table to make sure
            // we have all linking tables even if no columns selected
            // for intermediate tables
            DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) td.getTreeNode().getParent();

            while (pnode != null) {
                if (pnode.getUserObject() instanceof TableData) {
                    hs.add((TableData) pnode.getUserObject());
                }

                pnode = (DefaultMutableTreeNode) pnode.getParent();
            }
        }
    }

    for (WhereColumnData wcd : sqlWherePanel.getColumnData()) {
        TableData td = wcd.getTableData();
        hs.add(td);

        if (td.getTreeNode() != null) {
            // run up the tree for each table to make sure
            // we have all linking tables even if no columns selected
            // for intermediate tables
            DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) td.getTreeNode().getParent();

            while (pnode != null) {
                if (pnode.getUserObject() instanceof TableData) {
                    hs.add((TableData) pnode.getUserObject());
                }

                pnode = (DefaultMutableTreeNode) pnode.getParent();
            }
        }
    }

    retval.addAll(hs);

    Collections.sort(retval, new SqlHierarchyComparator());

    if (LOG.isDebugEnabled()) {
        for (TableData td : retval) {
            int level = -1;
            if (td.getTreeNode() != null) {
                level = td.getTreeNode().getLevel();
            }

            LOG.debug("table=" + td.getName() + ", level=" + level);
        }
    }

    return retval;
}

From source file:org.kuali.test.ui.components.sqlquerytree.SqlQueryTree.java

/**
 *
 * @param node// w w w . j av  a2 s  . c o  m
 * @return
 */
@Override
public String getTooltip(DefaultMutableTreeNode node) {
    String retval = null;

    if (node.getUserObject() instanceof TableData) {
        TableData td = (TableData) node.getUserObject();
        DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) node.getParent();

        if ((pnode != null) && (pnode.getUserObject() instanceof TableData)) {
            TableData pdata = (TableData) pnode.getUserObject();

            if (StringUtils.isNotBlank(td.getForeignKeyName())) {
                StringBuilder buf = new StringBuilder(128);
                buf.append("<html>");
                buf.append(Utils.buildHtmlStyle(Constants.HTML_BOLD_UNDERLINE_STYLE,
                        dbPanel.getTableDisplayName(pdata.getName()) + " -> "
                                + dbPanel.getTableDisplayName(td.getName())));

                buf.append(Constants.HTML_LINE_BREAK);

                for (String[] s : td.getLinkColumns()) {
                    buf.append(dbPanel.getColumnDisplayName(pdata.getName(), s[0], false));
                    buf.append("=");
                    buf.append(dbPanel.getColumnDisplayName(td.getName(), s[1], false));
                    buf.append(Constants.HTML_LINE_BREAK);
                }

                buf.append("</html>");

                retval = buf.toString();
            }
        }
    }

    return retval;
}

From source file:org.kuali.test.ui.components.sqlquerytree.SqlQueryTree.java

@Override
public void mousePressed(MouseEvent e) {
    TreePath path = getPathForLocation(e.getX(), e.getY());
    if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (node != null) {
            if (node.getUserObject() instanceof ColumnData) {
                ColumnData cd = (ColumnData) node.getUserObject();

                if (cd.isSelected()) {
                    columnsSelected--;//  w w w.  ja va 2  s  . com
                } else {
                    columnsSelected++;
                }

                cd.setSelected(!cd.isSelected());
                getComponentAt(e.getPoint()).repaint();
                e.consume();
            }
        }
    }
}

From source file:org.kuali.test.ui.dnd.RepositoryDropTargetAdapter.java

private boolean canDrop(DropTargetEvent dte) {
    boolean retval = false;
    try {// ww w  . j av a  2s  .  c om
        if (dte.getDropTargetContext().getComponent() == repositoryTree) {
            Point pt = null;
            Transferable t = null;
            int ops = -1;
            DataFlavor dataFlavor = null;
            if (dte instanceof DropTargetDragEvent) {
                pt = ((DropTargetDragEvent) dte).getLocation();
                t = ((DropTargetDragEvent) dte).getTransferable();
                ops = ((DropTargetDragEvent) dte).getSourceActions();
                dataFlavor = ((DropTargetDragEvent) dte).getCurrentDataFlavors()[0];
            } else if (dte instanceof DropTargetDropEvent) {
                pt = ((DropTargetDropEvent) dte).getLocation();
                t = ((DropTargetDropEvent) dte).getTransferable();
                ops = ((DropTargetDropEvent) dte).getSourceActions();
                dataFlavor = ((DropTargetDropEvent) dte).getCurrentDataFlavors()[0];
            }

            if ((pt != null) && (t != null)) {
                if (isTestLinkTransfer(t, ops, dataFlavor)) {
                    DefaultMutableTreeNode node = getNodeAtPoint(pt);
                    if (node != null) {
                        Object uo = node.getUserObject();

                        if (uo != null) {
                            if (uo instanceof TestSuite) {
                                TestSuite testSuite = (TestSuite) uo;
                                RepositoryTransferData<Platform, List<String>> data = (RepositoryTransferData<Platform, List<String>>) t
                                        .getTransferData(dataFlavor);

                                retval = (StringUtils.equalsIgnoreCase(data.getTarget().getName(),
                                        testSuite.getPlatformName()));
                            }
                        }
                    }
                } else if (isTestOrderTransfer(t, ops, dataFlavor)) {
                    DefaultMutableTreeNode node = getNodeAtPoint(pt);
                    if (node != null) {
                        Object uo = node.getUserObject();
                        if (uo != null) {
                            if (uo instanceof SuiteTest) {
                                SuiteTest targetSuiteTest = (SuiteTest) uo;
                                RepositoryTransferData<TestSuite, SuiteTest> data = (RepositoryTransferData<TestSuite, SuiteTest>) t
                                        .getTransferData(dataFlavor);

                                retval = (StringUtils.equalsIgnoreCase(data.getTarget().getPlatformName(),
                                        targetSuiteTest.getTestHeader().getPlatformName())
                                        && !StringUtils.equalsIgnoreCase(
                                                targetSuiteTest.getTestHeader().getTestName(),
                                                data.getData().getTestHeader().getTestName())
                                        && (targetSuiteTest.getIndex() != data.getData().getIndex()));
                            }
                        }
                    }
                }
            }
        }
    }

    catch (Exception ex) {
        LOG.warn(ex.toString(), ex);
    }

    return retval;
}

From source file:org.kuali.test.utils.Utils.java

/**
 *
 * @param configuration/*from www.  jav  a2 s.  c  o m*/
 * @param node
 * @return
 */
public static Platform getPlatformForNode(KualiTestConfigurationDocument.KualiTestConfiguration configuration,
        DefaultMutableTreeNode node) {
    Platform retval = null;

    if (node != null) {
        Object userObject = node.getUserObject();

        if (userObject != null) {
            if (userObject instanceof Platform) {
                retval = (Platform) userObject;
            } else if (userObject instanceof TestSuite) {
                TestSuite testSuite = (TestSuite) userObject;
                retval = findPlatform(configuration, testSuite.getPlatformName());
            } else if (userObject instanceof SuiteTest) {
                SuiteTest test = (SuiteTest) userObject;
                retval = findPlatform(configuration, test.getTestHeader().getPlatformName());
            }
        }
    }

    return retval;
}

From source file:org.kuali.test.utils.Utils.java

/**
 *
 * @param configuration//from w  ww  .  j a  va  2  s  .  c o  m
 * @param node
 * @return
 */
public static boolean removeRepositoryNode(KualiTestConfigurationDocument.KualiTestConfiguration configuration,
        DefaultMutableTreeNode node) {
    boolean retval = false;

    if (node != null) {
        Object userObject = node.getUserObject();

        if (userObject != null) {
            if (userObject instanceof SuiteTest) {
                retval = removeSuiteTest(configuration, (SuiteTest) userObject);
            } else if (userObject instanceof TestSuite) {
                retval = removeTestSuite(configuration, (TestSuite) userObject);
            } else if (userObject instanceof DatabaseConnection) {
                retval = removeDatabaseConnection(configuration, (DatabaseConnection) userObject);
            } else if (userObject instanceof WebService) {
                retval = removeWebService(configuration, (WebService) userObject);
            } else if (userObject instanceof JmxConnection) {
                retval = removeJmxConnection(configuration, (JmxConnection) userObject);
            }
        }
    }

    return retval;
}

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

/**
 * Expands all tree nodes from the root down to the specified node name. Does
 * not expand the final node as that node may not have any children.
 *
 * @param  name   The name of the final node.
 * @return    The final node, which itself has not been expanded.
 *//*from   ww  w.j  a va  2s.  c om*/
DefaultMutableTreeNode expandDownToNode(String name) {

    /*
     * Get a list of the family tree for the parameter concept. This list is
     * used to travel down the tree to the desired concept node.
     */
    List list = null;

    try {
        list = KnowledgeBaseCache.getInstance().findConceptFamilyTree(name);
    } catch (DAOException e) {
        if (log.isErrorEnabled()) {
            log.error("Call to knowledgebase cache failed");
        }

        AppFrameDispatcher.showErrorDialog(
                "There was a problem talking" + " to the database. Unable to open '" + name + "' in the tree.");
    }

    Iterator familyTree = list.iterator();

    // Pop the root Concept off the stack since it is the degenerative case.
    familyTree.next();

    // Then walk down the family tree, starting at the root node.
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) getModel().getRoot();

    while (familyTree.hasNext()) {
        String nextConceptName = ((Concept) familyTree.next()).getPrimaryConceptNameAsString();

        // Need to ensure the tree node for the current family name is expanded.
        TreeConcept treeConcept = (TreeConcept) treeNode.getUserObject();

        treeConcept.lazyExpand(treeNode);

        // Find the child node for the next family member.
        boolean found = false;
        Enumeration childrenNodes = treeNode.children();

        while (!found && childrenNodes.hasMoreElements()) {
            treeNode = (DefaultMutableTreeNode) childrenNodes.nextElement();
            treeConcept = (TreeConcept) treeNode.getUserObject();

            if (nextConceptName.equals(treeConcept.getName())) {
                found = true;
            }
        }
    }

    /*
     * RxNOTE The final value of treeNode drops out of the above while loop
     * without a call to lazyExpand. This is purposeful as the final node may
     * or may not have children. We are only expanding down to the node, not
     * expanding the node itself.
     */
    return treeNode;
}

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

/**
 * Gets the name of the <code>Concept</code> represented by the currently
 * selected node./*w  w w  . j a  v  a  2  s.co m*/
 *
 * @return    The name of the <code>Concept</code> represented by the currently
 *  selected node.
 */
public String getSelectedName() {
    String name = null;
    DefaultMutableTreeNode node = getSelectedNode();

    if (node != null) {
        name = ((TreeConcept) node.getUserObject()).getName();
    }

    return name;
}

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

/**
 * Makes the children nodes under the specified node visible.
 *
 * @param  node   The node on which to act.
 *//*from  w  w w  .  j a  v a 2  s.c  o m*/
private void makeChildrenVisible(DefaultMutableTreeNode node) {

    // RxTBD wcpr The Java API interaction of using TreeNodes and TreePaths
    // doesn't seem to make sense. There should be a cleaner way to implement
    // this method.
    if (node.isLeaf()) {
        return;
    }

    // Expand the node
    TreeConcept treeConcept = (TreeConcept) node.getUserObject();

    treeConcept.lazyExpand(node);

    boolean allChildrenAreLeaves = true;
    Enumeration children = node.children();

    while (children.hasMoreElements()) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();

        if (!childNode.isLeaf()) {
            makeChildrenVisible(childNode);
            allChildrenAreLeaves = false;
        }
    }

    if (allChildrenAreLeaves) {
        DefaultMutableTreeNode lastNode = (DefaultMutableTreeNode) node.getLastChild();
        TreeNode[] nodesFromRoot = node.getPath();
        TreePath pathFromRoot = new TreePath(nodesFromRoot).pathByAddingChild(lastNode);

        makeVisible(pathFromRoot);
    }
}

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

/**
 * Sets the parent node of the currently selected node to be the node
 * representing the <code>Concept</code> of the specified name.
 *
 * @param  newParentName   The name of the <code>Concept</code> for which the currently selected
 *  node is to become a child./*  w  ww .j a  v a  2s . c  o m*/
 */
public void updateTreeNodeParent(String newParentName) {

    // Get the node being moved
    DefaultMutableTreeNode conceptNode = (DefaultMutableTreeNode) getSelectionPath().getLastPathComponent();
    String conceptNodeName = ((TreeConcept) conceptNode.getUserObject()).getName();
    DefaultTreeModel treeModel = (DefaultTreeModel) getModel();

    // Remove node from current parent node and update structure
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) conceptNode.getParent();

    parentNode.remove(conceptNode);
    treeModel.nodeStructureChanged(parentNode);

    // Get the new parent node
    DefaultMutableTreeNode newParentNode = expandDownToNode(newParentName);
    TreeConcept treeConcept = (TreeConcept) newParentNode.getUserObject();
    boolean parentNeededExpanding = treeConcept.lazyExpand(newParentNode);

    // Branch on whether parent needed expanding:
    // - The parent node needed to be expanded. The call to lazyExpand()
    // updates the parent node's children so we don't need to explicitly add
    // the new child node. Find and select the new child node.
    // - The parent node is already expanded, so insert the new child node in
    // the appropriate slot and select the new child node.
    if (parentNeededExpanding) {
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (nodeName.equals(conceptNodeName)) {
                setSelectionPath(new TreePath(node.getPath()));

                break;
            }
        }
    } else {

        // Insert the node at the appropriate point in the new parent node.
        int insertPosition = 0;
        Enumeration children = newParentNode.children();

        while (children.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
            String nodeName = ((TreeConcept) node.getUserObject()).getName();

            if (0 < nodeName.compareTo(conceptNodeName)) {
                break;
            } else {
                insertPosition++;
            }
        }

        treeModel.insertNodeInto(conceptNode, newParentNode, insertPosition);
        setSelectionPath(new TreePath(conceptNode.getPath()));
    }
}