List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public boolean canCreateAutoStructItem() { boolean canCreate = false; if ((theEntityTree != null) && (theEntityTree.getSelectionCount() > 0)) { TreePath[] paths = theEntityTree.getSelectionPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if (node.getUserObject() instanceof FileSystemObject) { canCreate = true;//w w w . j ava 2 s.c o m break; } } } return canCreate; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private void getMatchingFiles(String baseFileName, DefaultMutableTreeNode rootNode, FSOCollection files) { if (rootNode.getUserObject() instanceof FileSystemObject) { FileSystemObject fso = (FileSystemObject) rootNode.getUserObject(); if (fso.getFileNameWithoutRepTypeOrSuffix().equals(baseFileName)) { files.add(fso);// w w w. j a va 2s. c o m } } for (int i = 0; i < rootNode.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) rootNode.getChildAt(i); getMatchingFiles(baseFileName, node, files); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void createAutoStructItem(boolean fromSingleFile) { if (canCreateAutoStructItem()) { JTree tree = getTree(ETreeType.EntityTree); if ((tree != null) && (tree.getSelectionCount() > 0)) { String structNodeName = getNewStructNodeName(); if (structNodeName == null) { return; }// w ww . ja v a 2 s . com StructMapCollection structure = getStructures(); FSOCollection files = new FSOCollection(); if (fromSingleFile) { // Complex one - need to recurse through tree & get all // matching files TreePath[] paths = tree.getSelectionPaths(); DefaultMutableTreeNode nodeSource = null; for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if (node.getUserObject() instanceof FileSystemObject) { nodeSource = node; break; } } if (nodeSource != null) { DepositTreeModel model = (DepositTreeModel) tree.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); FileSystemObject fso = (FileSystemObject) nodeSource.getUserObject(); String baseFileName = fso.getFileNameWithoutRepTypeOrSuffix(); getMatchingFiles(baseFileName, rootNode, files); } } else { TreePath[] paths = tree.getSelectionPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fso = (FileSystemObject) node.getUserObject(); files.add(fso); } } } files.setSortBy(manualDepositFrame.getCurrentSortBy()); files.reSortList(); int structSortOrder = 0; for (FileSystemObject fso : files) { fso.setStructSortOrder(structSortOrder); structSortOrder++; } StructMap map = StructMap.create(structNodeName, null, files, 0); structure.add(map); addStructMap(structure); } } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void setEntityRoot(DefaultMutableTreeNode node) { if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fsoRoot = (FileSystemObject) node.getUserObject(); FileSystemObject fsoRootFile = null; if (fsoRoot.getIsFile()) { DefaultMutableTreeNode nodeParent = (DefaultMutableTreeNode) node.getParent(); fsoRootFile = fsoRoot;// w w w . j a va2s.c o m fsoRoot = (FileSystemObject) nodeParent.getUserObject(); } setEntityRoot(fsoRoot, fsoRootFile); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void setMultipleRoot(DefaultMutableTreeNode node) { if ((userGroupData != null && userGroupData.isIncludeMultiEntityMenuItem()) && (node.getUserObject() instanceof FileSystemObject)) { theFsoRoot = (FileSystemObject) node.getUserObject(); setMultipleRoot_startThread();/*from ww w . j a v a 2 s . c om*/ } }
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 . c o 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 editEntity() { DefaultMutableTreeNode node = (DefaultMutableTreeNode) theEntityTree.getSelectionPath() .getLastPathComponent();//from w w w . j a v a 2 s . c om if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fso = (FileSystemObject) node.getUserObject(); fso.setIsEditing(true); } theEntityTree.startEditingAtPath(theEntityTree.getSelectionPath()); if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fso = (FileSystemObject) node.getUserObject(); fso.setIsEditing(false); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void deleteEntityNode(DefaultMutableTreeNode node) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel(); if (parentNode != null) { if (parentNode.getUserObject() instanceof FileSystemObject) { FileSystemObject parent = (FileSystemObject) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { // Can't // be // anything // else parent.getChildren().remove((FileSystemObject) node.getUserObject()); }//w w w.j a va 2 s.c o m } else if (parentNode.getUserObject() instanceof FileGroup) { FileGroup parent = (FileGroup) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { // Can't // be // anything // else parent.getChildren().remove((FileSystemObject) node.getUserObject()); } } else if (parentNode.getUserObject() instanceof FileGroupCollection) { FileGroupCollection parent = (FileGroupCollection) parentNode.getUserObject(); if (node.getUserObject() instanceof FileGroup) { // Can't be // anything // else parent.getFileGroupList().remove((FileGroup) node.getUserObject()); } } model.removeNodeFromParent(node); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void deleteStructMapNode(DefaultMutableTreeNode node) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode != null) { if (parentNode.getUserObject() instanceof StructMap) { // Can't be // anything // else StructMap parent = (StructMap) parentNode.getUserObject(); if (node.getUserObject() instanceof FileSystemObject) { parent.getFiles().remove((FileSystemObject) node.getUserObject()); } else if (node.getUserObject() instanceof StructMap) { parent.getChildren().remove((StructMap) node.getUserObject()); }// w ww .java 2s . co m } } DepositTreeModel model = (DepositTreeModel) theStructMapTree.getModel(); model.removeNodeFromParent(node); }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public StructMapCollection getStructures() { StructMapCollection retVal = new StructMapCollection(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theStructMapTree.getModel().getRoot(); for (int i = 0; rootNode != null && i < rootNode.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) rootNode.getChildAt(i); if (node.getUserObject() instanceof StructMap) { StructMap entity = (StructMap) node.getUserObject(); retVal.add(entity);// w w w . j av a2 s . c o m } } return retVal; }