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.repositorytree.RepositoryTree.java

@Override
public void dragGestureRecognized(DragGestureEvent event) {
    if (getSelectionPath() != null) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) getSelectionPath()
                .getLastPathComponent();

        if (isSuiteTest(selectedNode)) {
            TestSuite testSuite = (TestSuite) getParentUserObject(selectedNode);

            if (testSuite != null) {
                event.startDrag(DragSource.DefaultCopyNoDrop,
                        new RepositoryTransferable<TestSuite, SuiteTest>(
                                new RepositoryTransferData(testSuite, selectedNode.getUserObject()),
                                DndHelper.getTestOrderDataFlavor()),
                        new RepositoryDragSourceAdapter());
            }//from w ww .jav a2  s . c  om
        }
    }
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private Object getParentUserObject(DefaultMutableTreeNode childNode) {
    Object retval = null;// w ww .  j  a v  a 2s .  c o  m
    if (childNode.getParent() != null) {
        DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) childNode.getParent();
        retval = pnode.getUserObject();
    }

    return retval;
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private boolean isSuiteTest(DefaultMutableTreeNode node) {
    return ((node != null) && (node.getUserObject() != null) && (node.getUserObject() instanceof SuiteTest));
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

/**
 *
 * @param dataFlavor/*  ww w  .  j  ava  2  s. c om*/
 * @param data
 * @param dropNode
 */
public void handleDataDrop(DataFlavor dataFlavor, RepositoryTransferData data,
        DefaultMutableTreeNode dropNode) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("dataFlavor: " + dataFlavor.toString() + ", targetType: " + data.getClass().getName()
                + ", targetName: " + getDropTargetName(dropNode.getUserObject()));
    }

    if (DndHelper.getTestDataFlavor().equals(dataFlavor)) {
        addSuiteTests(dropNode, (List<String>) data.getData());
    } else if (DndHelper.getTestOrderDataFlavor().equals(dataFlavor)) {
        moveSuiteTest(dropNode, (SuiteTest) data.getData());
    }

    getMainframe().getSaveConfigurationButton().setEnabled(configuration.getModified());
    getMainframe().getSaveConfigurationMenuItem().setEnabled(configuration.getModified());
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private void addSuiteTests(DefaultMutableTreeNode testSuiteNode, List<String> testNames) {
    TestSuite inputTestSuite = (TestSuite) testSuiteNode.getUserObject();
    if (inputTestSuite != null) {
        Platform platform = Utils.findPlatform(configuration, inputTestSuite.getPlatformName());
        TestSuite testSuite = Utils.findTestSuite(configuration, inputTestSuite.getPlatformName(),
                inputTestSuite.getName());
        if ((platform != null) && (testSuite != null) && (testNames != null) && !testNames.isEmpty()) {
            SuiteTests suiteTests = testSuite.getSuiteTests();
            if (suiteTests == null) {
                suiteTests = testSuite.addNewSuiteTests();
            }//from  w  w  w  .  j a v  a2 s  .  c o  m

            List<SuiteTest> newSuiteTests = new ArrayList<SuiteTest>();
            for (String testName : testNames) {
                TestHeader testHeader = Utils.findTestHeaderByName(platform, testName);

                if (testHeader != null) {
                    SuiteTest suiteTest = suiteTests.addNewSuiteTest();
                    TestHeader th = (TestHeader) testHeader.copy();
                    th.setTestSuiteName(testSuite.getName());
                    suiteTest.setTestHeader(th);
                    suiteTest.setIndex(suiteTests.sizeOfSuiteTestArray());
                    suiteTest.setActive(true);
                    newSuiteTests.add(suiteTest);
                }
            }

            addRepositoryNodes(testSuiteNode, newSuiteTests);
            getMainframe().getSaveConfigurationButton().setEnabled(true);
            getMainframe().getSaveConfigurationMenuItem().setEnabled(true);
        }
    }
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

private void moveSuiteTest(DefaultMutableTreeNode suiteTestTargetNode, SuiteTest suiteTest) {
    if (suiteTestTargetNode != null) {
        DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) suiteTestTargetNode.getParent();

        if (pnode != null) {
            DefaultMutableTreeNode nodeToMove = findSuiteTestNode(suiteTest);

            if ((nodeToMove != null) && (nodeToMove != suiteTestTargetNode)) {
                TestSuite testSuite = (TestSuite) pnode.getUserObject();

                SuiteTest[] tests = testSuite.getSuiteTests().getSuiteTestArray();

                int pos1 = Utils.getSuiteTestArrayIndex(tests, suiteTest);
                int pos2 = Utils.getSuiteTestArrayIndex(tests, (SuiteTest) suiteTestTargetNode.getUserObject());
                ;//from   w w  w.  j  a  v  a2s .  co m

                if ((pos1 > -1) && (pos2 > -1) && (pos1 != pos2)) {
                    SuiteTest save = (SuiteTest) tests[pos1].copy();

                    if (pos1 > pos2) {
                        for (int i = pos2; i < pos1; ++i) {
                            tests[i + 1].set(tests[i]);
                        }
                    } else if (pos1 < pos2) {
                        for (int i = pos1; i < pos2; ++i) {
                            tests[i].set(tests[i + 1]);
                        }
                    }

                    tests[pos2].set(save);

                    getModel().removeNodeFromParent(nodeToMove);
                    getModel().insertNodeInto(nodeToMove, pnode, pnode.getIndex(suiteTestTargetNode));

                    int indx = 1;
                    for (SuiteTest t : testSuite.getSuiteTests().getSuiteTestArray()) {
                        t.setIndex(indx++);
                    }

                    getMainframe().getSaveConfigurationButton().setEnabled(true);
                    getMainframe().getSaveConfigurationMenuItem().setEnabled(true);
                }
            }
        }
    }
}

From source file:org.kuali.test.ui.components.repositorytree.RepositoryTree.java

/**
 *
 * @param platformName//from w w  w  .  j a va  2s  .c om
 * @return
 */
public Platform selectPlatformByName(String platformName) {
    Platform retval = null;
    Enumeration<DefaultMutableTreeNode> e = getRootNode().children();

    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = e.nextElement();

        Platform p = (Platform) node.getUserObject();

        if (p.getName().equals(platformName)) {
            getSelectionModel().setSelectionPath(new TreePath(node.getPath()));
            retval = p;
            break;
        }
    }

    return retval;
}

From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java

private boolean isCircularReference(DefaultMutableTreeNode node) {
    boolean retval = false;

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

    while (!retval && (pnode != null)) {
        if (pnode.getUserObject() instanceof TableData) {
            TableData tdata = (TableData) pnode.getUserObject();
            retval = td.getDbTableName().equals(tdata.getDbTableName());
        }/*w w w  .  j  av a 2  s  .c  o m*/

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

    return retval;
}

From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java

private void loadSelectedDbObjects(DefaultMutableTreeNode node, List<TableData> selectedDbObjects) {
    if (node.getUserObject() instanceof TableData) {
        TableData td = (TableData) node.getUserObject();

        if (hasSelectedColumns(td)) {
            selectedDbObjects.add(td);//from w  ww .  j a v  a  2s  .  c o  m
        }
    }

    for (int i = 0; i < node.getChildCount(); ++i) {
        loadSelectedDbObjects((DefaultMutableTreeNode) node.getChildAt(i), selectedDbObjects);
    }
}

From source file:org.kuali.test.ui.components.sqlquerypanel.DatabasePanel.java

private TableData getParentTableData(TableData td) {
    TableData retval = null;// ww  w.  j a  v  a  2 s.  c  o m

    if (td.getTreeNode() != null) {
        DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) td.getTreeNode().getParent();

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

    return retval;
}