Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

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

Introduction

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

Prototype

public DefaultMutableTreeNode() 

Source Link

Document

Creates a tree node that has no parent and no children, but which allows children.

Usage

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);//  www .j  ava2  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 void addFileSystemRoot(FileSystemObject fso, boolean recursive, boolean isEditingEntity,
        String pathToDisplay) {//from w  ww  .j  av a 2  s .c om
    fso.setSortBy(manualDepositFrame.getCurrentSortBy());
    String pathWanted = pathToDisplay;
    if (pathWanted != null) {
        File fileWanted = new File(pathWanted);
        while (fileWanted != null && !fileWanted.exists()) {
            fileWanted = fileWanted.getParentFile();
        }
        if (fileWanted != null) {
            pathWanted = fileWanted.getAbsolutePath();
        }
    }
    manualDepositFrame.setCurrentDirectory(pathWanted);
    manualDepositFrame.checkButtons();
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    rootNode.setUserObject(fso);
    DepositTreeModel model;
    if (theFileSystemTree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) theFileSystemTree.getModel();
        model.setRoot(rootNode);
    } else {
        model = new DepositTreeModel(rootNode, ETreeType.FileSystemTree);
        theFileSystemTree.setModel(model);
    }
    LOG.debug("addFileSystemRoot");
    addChildFiles(rootNode, fso.getChildren(), model, pathWanted, theFileSystemTree);
    if (buildIE_Worker == null) {
        expandNode(theFileSystemTree, rootNode, recursive);
    }
    updateWorkerProgress(80);
    theFileSystemTree.repaint();
    theEntityTree.repaint();
}

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);/*  w  ww .j  av a 2 s .co  m*/
    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 addIntellectualEntities(List<FileGroupCollection> entities) {
    updateWorkerProgress(50);//from  w  w w  .  j  av  a2 s .  c  o m
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    DepositTreeModel model;
    if (theEntityTree.getModel() instanceof DepositTreeModel) {
        model = (DepositTreeModel) theEntityTree.getModel();
        model.setRoot(rootNode);
    } else {
        model = new DepositTreeModel(rootNode, ETreeType.EntityTree);
        theEntityTree.setModel(model);
    }
    if (entities == null) {
        rootNode.setUserObject("Intellectual Entity");
    } else {
        // Set folder as Root
        if (entities.size() == 1) {
            FileGroupCollection collection = entities.get(0);
            rootNode.setUserObject(collection);
            for (int i = 0; collection.getFileGroupList() != null
                    && i < collection.getFileGroupList().size(); i++) {
                addIntellectualEntity(rootNode, collection.getFileGroupList().get(i), false);
            }
        }
        // Set each file as IE
        else {
            rootNode.setUserObject(theFsoRoot.getDescription());
            for (FileGroupCollection entity : entities) {
                DefaultMutableTreeNode childNode = new DefaultMutableTreeNode();
                childNode.setUserObject(entity);
                model.insertNodeInto(childNode, rootNode, rootNode.getChildCount());
                for (int i = 0; entity.getFileGroupList() != null
                        && i < entity.getFileGroupList().size(); i++) {
                    addIntellectualEntity(childNode, entity.getFileGroupList().get(i), false);
                }
            }
        }
    }
    // When the Swing Worker is used, expanding the leaf nodes has been moved to the end of the IE building process. Now located in the Swing Worker's Done() method.
    if (buildIE_Worker == null) {
        expandNode(theEntityTree, rootNode, true);
    }
    updateWorkerProgress(60);
    theEntityTree.repaint();
}

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);
    }/*from  www  . jav  a2s . c  o  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  w w  w  .j a  va  2s  .  co m
    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.ManualDepositPresenter.java

public void addStructMap(StructMapCollection structure) {
    if (theStructMapTree == null) {
        return;//from  w  w w.  j  a va 2  s. co m
    }
    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;//from   ww  w  .ja v a2 s  . com
    /*
     * _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;/* w  w w .  j  ava 2 s.c om*/
    FileSystemObject root = new FileSystemObject(description, theFile, theChildren);
    node.setUserObject(root);
    depositPresenter.setEntityRoot(node);
    return root;
}

From source file:op.care.med.structure.PnlMed.java

private void initDialog() {
    prepareSearchArea();/*from ww w. j  a  v a 2 s. c om*/
    product = null;
    treeMed.setModel(new DefaultTreeModel(new DefaultMutableTreeNode()));
    treeMed.setVisible(false);
}