List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void expandFileSystemTree(TreePath currentPath) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) currentPath.getLastPathComponent(); FileSystemObject fso = (FileSystemObject) node.getUserObject(); if ((fso.getChildren() != null) && (fso.getChildren().size() == 1) && (fso.getChildren().get(0).getIsPlaceholder())) { // LOG.debug("Before load children"); fso.loadChildren(false);/*from w w w . ja v a 2s . c o m*/ // LOG.debug("After load children"); DepositTreeModel model = (DepositTreeModel) theFileSystemTree.getModel(); // LOG.debug("Before remove children"); node.removeAllChildren(); // LOG.debug("Before reload node"); model.reload(node); // LOG.debug("Before add children"); addChildFiles(node, fso.getChildren(), model, null, null); // LOG.debug("Before expand path"); theFileSystemTree.expandPath(currentPath); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public String getRootFileName() { String retVal;/*from ww w .j a v a 2 s. c om*/ DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) this.theFileSystemTree.getModel().getRoot(); if (rootNode.getUserObject() instanceof FileSystemObject) { retVal = rootNode.getUserObject().toString(); } else if (rootNode.getUserObject() instanceof String) { retVal = rootNode.getUserObject().toString(); } else { retVal = null; } return retVal; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public String getRootEntityName() { String retVal;// w w w.j a v a 2s . c om DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theEntityTree.getModel().getRoot(); if (rootNode.getUserObject() instanceof FileGroup) { retVal = rootNode.getUserObject().toString(); } else if (rootNode.getUserObject() instanceof FileGroupCollection) { retVal = rootNode.getUserObject().toString(); } else if (rootNode.getUserObject() instanceof String) { retVal = rootNode.getUserObject().toString(); } else { retVal = "Intellectual Entity"; } return retVal; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private String getEntityName() { String entityName = "Unknown entity type"; DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theEntityTree.getModel().getRoot(); if (rootNode.getUserObject() instanceof FileGroupCollection) { FileGroupCollection collection = (FileGroupCollection) rootNode.getUserObject(); entityName = collection.getEntityName(); } else if (rootNode.getUserObject() instanceof String) { entityName = (String) rootNode.getUserObject(); }//from w ww . j ava 2 s . co m return entityName; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public ArrayList<FileGroupCollection> getEntities() { ArrayList<FileGroupCollection> retVal = new ArrayList<FileGroupCollection>(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) theEntityTree.getModel().getRoot(); if (rootNode.getUserObject() instanceof FileGroupCollection) { FileGroupCollection collection = (FileGroupCollection) rootNode.getUserObject(); retVal.add(collection);//from w w w. ja va 2 s. com } else { for (int i = 0; rootNode != null && i < rootNode.getChildCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) rootNode.getChildAt(i); if (node.getUserObject() instanceof FileGroupCollection) { FileGroupCollection collection = (FileGroupCollection) node.getUserObject(); retVal.add(collection); } } } return retVal; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public boolean canOpenFiles(TreePath[] paths) { boolean retVal = true; if (paths == null) { retVal = false;//from w w w . j ava2 s . c o m } else { for (TreePath path : paths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node.getUserObject() instanceof FileSystemObject) { FileSystemObject fso = (FileSystemObject) node.getUserObject(); if (!fso.getIsFile()) { retVal = false; break; } } else { retVal = false; break; } } } return retVal; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void storeAsFavourite(DefaultMutableTreeNode node) { PersonalSettings personalSettings = applicationProperties.getApplicationData().getPersonalSettings(); // This will fail if you give it a non-FSO node FileSystemObject fso = (FileSystemObject) node.getUserObject(); if (!fso.getIsFile()) { String dir = fso.getFullPath(); personalSettings.addFavourite(dir); setupFavourites();//from w w w .j a v a 2 s . c o m manualDepositFrame.showMessage("Favourite Stored", dir + " has been stored as a favourite directory"); } }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
private DefaultMutableTreeNode addEntity(RepresentationTypes entityType) { DefaultMutableTreeNode retVal = null; DefaultMutableTreeNode node = theNodeInClipboard.get(0); if (node.getUserObject() instanceof FileGroupCollection) { int noOfEntities = noOfEntityTypesAdded(entityType, getEntities()); noOfEntities++;//from w w w . j a va 2 s . c o m FileGroupCollection collection = (FileGroupCollection) node.getUserObject(); FileGroup newEntity = FileGroup.create(this.getEntityName(entityType, noOfEntities), BLANK_ID, entityType, null); try { collection.add(newEntity); } catch (Exception ex) { manualDepositFrame.showError("Couldn't add file group", "An error has occurred in " + newEntity.getEntityName(), ex); reportException(ex); } retVal = addIntellectualEntity(node, newEntity, false); } return retVal; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public boolean canDeleteEntityItem() { boolean canDelete = false; JTree tree = theEntityTree;/*from w w w .ja v a 2s . co m*/ if (tree != null) { if (tree.getSelectionCount() > 0) { TreePath[] paths = tree.getSelectionPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if ((node.getUserObject() instanceof FileGroup) || (node.getUserObject() instanceof FileSystemObject) || ((getEntities().size() > 1) && (node.getUserObject() instanceof FileGroupCollection))) { canDelete = true; break; } } } } return canDelete; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java
public void resequenceEntity() { JTree tree = theEntityTree;//w w w. java 2 s .c o m TreePath[] paths = tree.getSelectionPaths(); for (int i = 0; i < paths.length; i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent(); if ((node.getUserObject() instanceof FileGroup) || (node.getUserObject() instanceof FileSystemObject) || ((getEntities().size() > 1) && (node.getUserObject() instanceof FileGroupCollection))) { FileGroup group = (FileGroup) node.getUserObject(); String sequenceNumber = manualDepositFrame.getInput("Enter Sequence Number", "Enter new sequence number", String.format("%d", group.getRevisionNumber())); if (sequenceNumber != null) { try { int newSequence = Integer.parseInt(sequenceNumber); group.setRevisionNumber(newSequence); } catch (Exception ex) { manualDepositFrame.showError("Invalid Sequence Number", "Sequence number must be a valid number", ex); } } } } }