Example usage for javax.swing.tree DefaultMutableTreeNode getPath

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

Introduction

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

Prototype

public TreeNode[] getPath() 

Source Link

Document

Returns the path from the root, to get to this node.

Usage

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

public void selectNode(Object nodeObject, ETreeType treeType) {
    JTree tree = getTree(treeType);
    DepositTreeModel model = (DepositTreeModel) tree.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot();
    DefaultMutableTreeNode node = findNode(rootNode, nodeObject);
    if (node != null) {
        LOG.debug("selectNode Node object found");
        TreePath path = new TreePath(node.getPath());
        tree.scrollPathToVisible(path);/*from  w  ww. j  a va 2s.  c om*/
        tree.setSelectionPath(path);
    } else {
        LOG.debug("selectNode Node object not found");
    }
}

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

public void expandNode(JTree whichTree, DefaultMutableTreeNode node, boolean recurse) {

    whichTree.expandPath(new TreePath(node.getPath()));
    if (recurse && node.getChildCount() > 0) {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
            expandNode(whichTree, child, recurse);
        }/*from  w  w  w . ja  v  a2  s . com*/
    }
}

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

public void addChildFiles(DefaultMutableTreeNode rootNode, FSOCollection children, DepositTreeModel model,
        String pathToDisplay, JTree whichTree) {
    LOG.debug("addChildFiles, root: " + rootNode.getUserObject());
    model.reload(rootNode);//from   w w  w .ja  va 2  s  . co m
    /*      for (FileSystemObject fso : children) {
             if (fso.getFile() == null) {
    LOG.debug("add child (file is null): " + fso.getDescription());
             } else {
    LOG.debug("add child (file is not null): "
          + fso.getDescription());
             }
             if ((!model.getTreeType().equals(ETreeType.FileSystemTree))
       || (!fso.getIsFile()) || (!fileIsInEntity(fso))) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode();
    node.setUserObject(fso);
    model.insertNodeInto(node, rootNode, rootNode.getChildCount());
    addChildFiles(node, fso.getChildren(), model, pathToDisplay,
          whichTree);
    if ((pathToDisplay != null)
          && (pathToDisplay.equals(fso.getFullPath()))) {
       expandNode(whichTree, node, false);
       whichTree.scrollPathToVisible(new TreePath(node.getPath()));
    }
             }
          }*/
    for (int i = 0; i < children.size(); i++) {
        FileSystemObject fso = children.get(i);
        if (fso.getFile() == null) {
            LOG.debug("add child (file is null): " + fso.getDescription());
        } else {
            LOG.debug("add child (file is not null): " + fso.getDescription());
        }
        if ((!model.getTreeType().equals(ETreeType.FileSystemTree)) || (!fso.getIsFile())
                || (!fileIsInEntity(fso))) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode();
            node.setUserObject(fso);
            model.insertNodeInto(node, rootNode, rootNode.getChildCount());
            addChildFiles(node, fso.getChildren(), model, pathToDisplay, whichTree);
            if ((pathToDisplay != null) && (pathToDisplay.equals(fso.getFullPath()))) {
                expandNode(whichTree, node, false);
                whichTree.scrollPathToVisible(new TreePath(node.getPath()));
            }
        }
    }
}

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

public DefaultMutableTreeNode addIntellectualEntity(DefaultMutableTreeNode rootNode, FileGroup entity,
        boolean editEntry) {
    DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel();
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(entity);//www  . j  a  v  a  2 s. c  om
    model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    if (entity.getChildren() == null) {
        entity.setChildren(FSOCollection.create());
    }
    addChildFiles(newNode, entity.getChildren(), model, null, null);
    TreePath newPath = new TreePath(newNode.getPath());
    theEntityTree.scrollPathToVisible(newPath);
    theEntityTree.setSelectionPath(newPath);
    theEntityTree.repaint();
    if (editEntry) {
        editEntity();
    }
    return newNode;
}

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

public void addStructMapItem(StructMap structMapItem, DefaultMutableTreeNode rootNode, boolean editEntry) {
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(structMapItem);
    DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel();
    model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    for (int i = 0; structMapItem.getChildren() != null && i < structMapItem.getChildren().size(); i++) {
        addStructMapItem(structMapItem.getChildren().get(i), newNode, false);
    }// w  ww  .ja  v a 2  s  . co m
    for (int i = 0; structMapItem.getFiles() != null && i < structMapItem.getFiles().size(); i++) {
        DefaultMutableTreeNode newFileNode = new DefaultMutableTreeNode();
        newFileNode.setUserObject(structMapItem.getFiles().get(i));
        model.insertNodeInto(newFileNode, newNode, newNode.getChildCount());
    }
    TreePath newPath = new TreePath(newNode.getPath());
    theStructMapTree.scrollPathToVisible(newPath);
    theStructMapTree.setSelectionPath(newPath);
    if (editEntry) {
        editStructMap();
    }
}

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

public void addFileToStructMap(FileSystemObject fso, DefaultMutableTreeNode rootNode, int nodeIndex,
        boolean editEntry) {
    // Assumes that the structure has already been created - this is just UI
    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode();
    newNode.setUserObject(fso);//from   www .j  a va 2s  .  com
    DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel();
    // The specified index is now passed to insertNodeInto, to put the newNode into the correct position
    //model.insertNodeInto(newNode, rootNode, rootNode.getChildCount());
    model.insertNodeInto(newNode, rootNode, nodeIndex);
    TreePath newPath = new TreePath(newNode.getPath());
    theStructMapTree.scrollPathToVisible(newPath);
    theStructMapTree.setSelectionPath(newPath);
    if (editEntry) {
        editStructMap();
    }
}

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

@Test
//Temporarily adding ignore as this testcase has some defect and fails
// all the time. This has to be fixed in the next release.
@Ignore/*from   w w w . j a  v  a2 s .  com*/
public final void testHeapsOfStuff() {
    /**
     * Test a lot of the entity creation / deletion Tests hot keys also
     */
    depositPresenter.refreshFileList();
    DepositTreeModel fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    assertTrue(rootNode.getChildCount() > 0);
    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertTrue(childNode.getChildCount() == 1); // Should be a placeholder
    DefaultMutableTreeNode grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
    assertTrue(grandChildNode.getUserObject() instanceof FileSystemObject);
    FileSystemObject fso = (FileSystemObject) grandChildNode.getUserObject();
    assertTrue(fso.getIsPlaceholder());
    TreePath currentTreePath = new TreePath(childNode.getPath());
    depositPresenter.expandFileSystemTree(currentTreePath);
    if (childNode.getChildCount() > 0) {
        grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
        assertTrue(grandChildNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) grandChildNode.getUserObject();
        assertFalse(fso.getIsPlaceholder());
    }
    try {
        setUp();
    } catch (Exception ex) {
        fail();
    }
    // After setup the model will have changed - but it shouldn't change
    // again after this
    fileSystemModel = (DepositTreeModel) theFrame.treeFileSystem.getModel();
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();

    TreePath[] selectionPaths = loadEntity(RESOURCES_INPUT_PATH_NAMED);
    // Entity root not set yet - should be able to get a menu
    JPopupMenu menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the root
    menu = depositPresenter.processFileTreeKeyPress('s', selectionPaths);
    DepositTreeModel entityModel = (DepositTreeModel) theFrame.treeEntities.getModel();
    DepositTreeModel structMapModel = (DepositTreeModel) theFrame.treeStructMap.getModel();
    assertTrue(menu == null);
    // The digital original should already have been added automatically
    // Only one allowed, so this should fail.
    assertFalse(depositPresenter.canAddRepresentationType('d'));
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('p'));
    // multiple allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('a'));
    // multiple allowed, two added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('m'));

    // While we've got the named stuff loaded, might as well check the move
    // up/down
    DefaultMutableTreeNode ieRootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    // Right - we should have one DO & 2 AC
    assertTrue(ieRootNode.getChildCount() == 3);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) ieRootNode.getChildAt(0);
    assertTrue(node.getUserObject() instanceof FileGroup);
    FileGroup group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.DigitalOriginal));
    int childNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(childNo);
    assertTrue(childNode.getUserObject() instanceof FileSystemObject);
    fso = (FileSystemObject) childNode.getUserObject();
    // while (fso.getFileName().equalsIgnoreCase(".svn")) {
    // childNo++;
    // childNode = (DefaultMutableTreeNode)node.getChildAt(childNo);
    // assertTrue(childNode.getUserObject() instanceof FileSystemObject);
    // fso = (FileSystemObject)childNode.getUserObject();
    // }
    // childNo = 0;
    fso.setSortBy(SortBy.UserArranged);
    while (!fso.getFileName().equalsIgnoreCase("Chapter1")) {
        childNo++;
        childNode = (DefaultMutableTreeNode) node.getChildAt(childNo);
        assertTrue(childNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) childNode.getUserObject();
    }
    doIEMoveTest(childNo, node.getChildCount(), fso, group);

    childNo = 0;
    DefaultMutableTreeNode subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
    assertTrue(subChildNode.getUserObject() instanceof FileSystemObject);
    FileSystemObject fsoChild = (FileSystemObject) subChildNode.getUserObject();
    fsoChild.setSortBy(SortBy.UserArranged);
    while (!fsoChild.getFileName().equalsIgnoreCase("test_87_archive_1_P_1.jpg")) {
        childNo++;
        subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
        assertTrue(subChildNode.getUserObject() instanceof FileSystemObject);
        fsoChild = (FileSystemObject) subChildNode.getUserObject();
    }
    fso.setSortBy(SortBy.UserArranged);
    fsoChild.setSortBy(SortBy.UserArranged);
    // doIEMoveTest(childNo, childNode.getChildCount(), fsoChild, fso);

    node = (DefaultMutableTreeNode) ieRootNode.getChildAt(1);
    assertTrue(node.getUserObject() instanceof FileGroup);
    group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.AccessCopy));
    node = (DefaultMutableTreeNode) ieRootNode.getChildAt(2);
    assertTrue(node.getUserObject() instanceof FileGroup);
    group = (FileGroup) node.getUserObject();
    assertTrue(group.getEntityType().equals(RepresentationTypes.AccessCopy));

    DefaultMutableTreeNode structRootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    childNo = 0;
    childNode = (DefaultMutableTreeNode) structRootNode.getChildAt(childNo);
    assertTrue(childNode.getUserObject() instanceof StructMap);
    StructMap map = (StructMap) childNode.getUserObject();
    while (!map.getStructureName().equalsIgnoreCase("Chapter1")) {
        childNo++;
        childNode = (DefaultMutableTreeNode) structRootNode.getChildAt(childNo);
        assertTrue(childNode.getUserObject() instanceof StructMap);
        map = (StructMap) childNode.getUserObject();
    }
    doStructMoveTest(childNo, structRootNode.getChildCount(), map, structRootNode.getUserObject());
    childNo = 0;
    subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
    assertTrue(subChildNode.getUserObject() instanceof StructMap);
    map = (StructMap) subChildNode.getUserObject();
    while (!map.getStructureName().equalsIgnoreCase("Page 1")) {
        childNo++;
        subChildNode = (DefaultMutableTreeNode) childNode.getChildAt(childNo);
        assertTrue(subChildNode.getUserObject() instanceof StructMap);
        map = (StructMap) subChildNode.getUserObject();
    }
    doStructMoveTest(childNo, structRootNode.getChildCount(), map, childNode.getUserObject());
    childNo = 0;
    DefaultMutableTreeNode subSubChildNode = (DefaultMutableTreeNode) subChildNode.getChildAt(childNo);
    assertTrue(subSubChildNode.getUserObject() instanceof FileSystemObject);
    fso = (FileSystemObject) subSubChildNode.getUserObject();
    while (!fso.getFileName().equalsIgnoreCase("test_87_view_1_P_1.jpg")) {
        childNo++;
        subSubChildNode = (DefaultMutableTreeNode) subChildNode.getChildAt(childNo);
        assertTrue(subSubChildNode.getUserObject() instanceof FileSystemObject);
        fso = (FileSystemObject) subSubChildNode.getUserObject();
    }
    doStructMoveTest(childNo, subChildNode.getChildCount(), fso, subChildNode.getUserObject());

    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    FSOCollection coll = FSOCollection.create();
    coll.add((FileSystemObject) rootNode.getUserObject());
    FileSystemObject child = coll.getFSOByFullFileName("test_87_view_1_P_1.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());

    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    depositPresenter.selectNode(rootNode.getUserObject(), ETreeType.EntityTree);
    assertFalse(depositPresenter.canCreateAutoStructItem());
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    depositPresenter.selectNode(node.getUserObject(), ETreeType.EntityTree);
    assertFalse(depositPresenter.canCreateAutoStructItem());

    // Delete all the struct map & entity nodes so we can re-add them using
    // hot keys
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    int nodeNo = 0;
    node = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
    map = (StructMap) node.getUserObject();
    while (!map.getStructureName().equals("Chapter1")) {
        nodeNo++;
        node = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
        map = (StructMap) node.getUserObject();
    }
    nodeNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
    map = (StructMap) childNode.getUserObject();
    while (!map.getStructureName().equals("Page 1")) {
        nodeNo++;
        childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
        map = (StructMap) childNode.getUserObject();
    }
    assertTrue(childNode.getChildCount() == 3);
    grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(0);
    TreePath path = new TreePath(grandChildNode.getPath());
    theFrame.treeStructMap.setSelectionPath(path);
    Object nodeObject = grandChildNode.getUserObject();
    // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
    assertTrue(depositPresenter.canDeleteStructItem());
    depositPresenter.deleteStructMapItem();
    assertTrue(childNode.getChildCount() == 2);
    int noOfNodes = node.getChildCount();
    path = new TreePath(childNode.getPath());
    theFrame.treeStructMap.setSelectionPath(path);
    nodeObject = childNode.getUserObject();
    // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
    assertTrue(depositPresenter.canDeleteStructItem());
    depositPresenter.deleteStructMapItem();
    assertTrue(node.getChildCount() == noOfNodes - 1);

    noOfNodes = rootNode.getChildCount();
    for (int i = 0; i < noOfNodes; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
        path = new TreePath(node.getPath());
        theFrame.treeStructMap.setSelectionPath(path);
        nodeObject = node.getUserObject();
        // _presenter.selectNode(nodeObject, ETreeType.StructMapTree);
        assertTrue(depositPresenter.canDeleteStructItem());
        depositPresenter.deleteStructMapItem();
        assertTrue(rootNode.getChildCount() == noOfNodes - i - 1);
        if (rootNode.getChildCount() > 0) {
            node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
            assertFalse(node.getUserObject().equals(nodeObject));
        }
    }
    assertTrue(rootNode.getChildCount() == 0);

    // Struct map should be clear now - clear IE
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    nodeNo = 0;
    childNode = (DefaultMutableTreeNode) node.getChildAt(nodeNo);
    fso = (FileSystemObject) childNode.getUserObject();
    while (!fso.getDescription().equals("Chapter1")) {
        nodeNo++;
        childNode = (DefaultMutableTreeNode) rootNode.getChildAt(nodeNo);
        fso = (FileSystemObject) childNode.getUserObject();
    }
    nodeNo = 0;
    grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(nodeNo);
    fso = (FileSystemObject) grandChildNode.getUserObject();
    while (!fso.getFileName().equals("test_87_archive_1_P_1.jpg")) {
        nodeNo++;
        grandChildNode = (DefaultMutableTreeNode) childNode.getChildAt(nodeNo);
        fso = (FileSystemObject) grandChildNode.getUserObject();
    }
    noOfNodes = childNode.getChildCount();
    path = new TreePath(grandChildNode.getPath());
    JPopupMenu pop = depositPresenter.getEntityMenu(grandChildNode);
    assertTrue(pop.getSubElements().length == 3);
    pop = depositPresenter.getEntityMenu(childNode);
    assertTrue(pop.getSubElements().length == 2);
    pop = depositPresenter.getEntityMenu(node);
    assertTrue(pop.getSubElements().length == 1);
    pop = depositPresenter.getEntityMenu(rootNode);
    assertTrue(pop.getSubElements().length == 3);

    theFrame.treeEntities.setSelectionPath(path);
    // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
    assertTrue(depositPresenter.canDeleteEntityItem());
    depositPresenter.deleteEntity();
    assertTrue(childNode.getChildCount() == noOfNodes - 1);
    noOfNodes = node.getChildCount();
    path = new TreePath(childNode.getPath());
    theFrame.treeEntities.setSelectionPath(path);
    // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
    assertTrue(depositPresenter.canDeleteEntityItem());
    depositPresenter.deleteEntity();
    assertTrue(node.getChildCount() == noOfNodes - 1);

    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    noOfNodes = rootNode.getChildCount();
    for (int i = 0; i < noOfNodes; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
        path = new TreePath(node.getPath());
        theFrame.treeEntities.setSelectionPath(path);
        nodeObject = node.getUserObject();
        // _presenter.selectNode(nodeObject, ETreeType.EntityTree);
        assertTrue(depositPresenter.canDeleteEntityItem());
        depositPresenter.deleteEntity();
        assertTrue(rootNode.getChildCount() == noOfNodes - i - 1);
        if (rootNode.getChildCount() > 0) {
            node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
            assertFalse(node.getUserObject().equals(nodeObject));
        }
        rootNode = (DefaultMutableTreeNode) entityModel.getRoot(); // Make
        // sure
        // we
        // have
        // the
        // right
        // root
        // node
        // - it
        // changes
    }
    assertTrue(rootNode.getChildCount() == 0);
    depositPresenter.resetScreen();

    // Adding an auto structure item from a single file
    // should result in all three representation types being there
    selectionPaths = loadEntity(RESOURCES_INPUT_MANUAL);
    // Entity root not set yet - should be able to get a menu
    menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the root
    menu = depositPresenter.processFileTreeKeyPress('s', selectionPaths);
    assertTrue(menu == null);
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('d'));
    // Only one allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('p'));
    // multiple allowed, but none added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('a'));
    // multiple allowed, two added so far, so this should succeed.
    assertTrue(depositPresenter.canAddRepresentationType('m'));

    // Create DO
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    String[] fileNames = { "File1.jpg", "File1.tif", "File1.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames,
            RepresentationTypes.DigitalOriginal);

    // Create AC 1
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    fileNames = new String[] { "File2.jpg", "File2.tif", "File2.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames, RepresentationTypes.AccessCopy);

    // Create AC 2
    rootNode = (DefaultMutableTreeNode) fileSystemModel.getRoot();
    fileNames = new String[] { "File3.jpg", "File3.tif", "File3.tn" };
    addFilesToEntityAndCheckResults(fileSystemModel, entityModel, fileNames, RepresentationTypes.AccessCopy);

    // Should now have a completely populated IE - test Struct map
    // Adding an auto structure item from a single file
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    coll = FSOCollection.create();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    group = (FileGroup) node.getUserObject();
    coll = group.getChildren();
    child = coll.getFSOByFullFileName("File1.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());
    theFrame.setInputResult("First Test");
    depositPresenter.createAutoStructItem(true);
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    assertTrue(rootNode.getChildCount() == 1);
    node = (DefaultMutableTreeNode) rootNode.getChildAt(0);
    assertTrue(node.getChildCount() == 3);
    assertTrue(node.getUserObject() instanceof StructMap);
    map = (StructMap) node.getUserObject();
    assertTrue(map.getStructureName().equalsIgnoreCase("First Test"));
    node = (DefaultMutableTreeNode) node.getChildAt(0);
    ;
    assertTrue(node.getUserObject().equals(child));

    // Adding an auto structure item NOT from a single file
    // should result in only one representation type being there - the one
    // selected
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    coll = FSOCollection.create();
    node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    group = (FileGroup) node.getUserObject();
    coll = group.getChildren();
    child = coll.getFSOByFullFileName("File2.jpg", true);
    depositPresenter.selectNode(child, ETreeType.EntityTree);
    assertTrue(depositPresenter.canCreateAutoStructItem());
    theFrame.setInputResult("Second Test");
    depositPresenter.createAutoStructItem(false);
    rootNode = (DefaultMutableTreeNode) structMapModel.getRoot();
    assertTrue(rootNode.getChildCount() == 2);
    node = (DefaultMutableTreeNode) rootNode.getChildAt(1);
    assertTrue(node.getChildCount() == 1);
    assertTrue(node.getUserObject() instanceof StructMap);
    map = (StructMap) node.getUserObject();
    assertTrue(map.getStructureName().equalsIgnoreCase("Second Test"));
    node = (DefaultMutableTreeNode) node.getChildAt(0);
    ;
    assertTrue(node.getUserObject().equals(child));

    depositPresenter.resetScreen();
    selectionPaths = loadEntity(RESOURCES_INPUT_MULTIPLE);
    // Entity root should now be unset - should be able to get a menu
    menu = depositPresenter.processFileTreeKeyPress('m', selectionPaths);
    assertTrue(menu != null);
    // Set the multiple root
    menu = depositPresenter.processFileTreeKeyPress('e', selectionPaths);
    assertTrue(menu == null);
    rootNode = (DefaultMutableTreeNode) entityModel.getRoot();
    LOG.debug("ChildCount: " + rootNode.getChildCount());
    assertTrue(rootNode.getChildCount() >= 3); // 3 on local PC, 4 on
    // server. Gah!
    for (int i = 0; i < 3; i++) {
        node = (DefaultMutableTreeNode) rootNode.getChildAt(i);
        assertTrue(node.getUserObject() instanceof FileGroupCollection);
    }
}

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

public void currentObjectsChanged(MultipleObjectsDisplayEvent e, Application application) {
    if (e.getSource() == this || e.getParentNode() == null) {
        return;/*from  www  .  j a v  a  2  s.  c  om*/
    }

    ConfigurationNode[] nodes = e.getNodes();
    TreePath[] treePaths = new TreePath[nodes.length];

    for (int i = 0; i < nodes.length; i++) {
        DefaultMutableTreeNode treeNode = getProjectModel()
                .getNodeForObjectPath(new Object[] { e.getParentNode(), nodes[i] });
        if (treeNode != null) {
            treePaths[i] = new TreePath(treeNode.getPath());
        } else if (e.getParentNode() == nodes[i]) {
            treeNode = getProjectModel().getNodeForObjectPath(new Object[] { e.getParentNode() });
            treePaths[i] = new TreePath(treeNode.getPath());
        }
    }

    if (!isVisible(treePaths[0])) {
        makeVisible(treePaths[0]);

        Rectangle bounds = getPathBounds(treePaths[0]);
        if (bounds != null) {
            bounds.height = getVisibleRect().height;
            scrollRectToVisible(bounds);
        }
    }

    setSelectionPaths(treePaths);
}

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

/** Makes node current, visible and selected. */
protected void showNode(DefaultMutableTreeNode node) {
    TreePath path = new TreePath(node.getPath());

    if (!isVisible(path)) {
        makeVisible(path);//from  w w  w  .  j a v  a 2  s . c  om

        Rectangle bounds = getPathBounds(path);
        if (bounds != null) {
            bounds.height = getVisibleRect().height;
            scrollRectToVisible(bounds);
        }
    }

    setSelectionPath(path);
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java

public TreePath getTreePath(DefaultMutableTreeNode node, ModelGraph graph) {
    if (node.getUserObject().equals(graph)) {
        return new TreePath(node.getPath());
    } else {/*from  w  w w.ja v a  2  s .  co m*/
        for (int i = 0; i < node.getChildCount(); i++) {
            // System.out.println("i: " + ((DefaultMutableTreeNode)
            // node.getChildAt(i)).getUserObject());
            TreePath treePath = this.getTreePath((DefaultMutableTreeNode) node.getChildAt(i), graph);
            if (treePath != null) {
                return treePath;
            }
        }
        return null;
    }
}