List of usage examples for javax.swing.tree TreePath TreePath
public TreePath(Object lastPathComponent)
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);/*w w w. j a va 2s. 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 DefaultMutableTreeNode addIntellectualEntity(DefaultMutableTreeNode rootNode, FileGroup entity, boolean editEntry) { DepositTreeModel model = (DepositTreeModel) theEntityTree.getModel(); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(); newNode.setUserObject(entity);//from w ww .j a v a2s .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 w w . j a v a 2 s .c om*/ 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 . c om*/ 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// ww w . j a v a 2 s .c o m 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;/* w w w.j a v a 2 s.c o m*/ } 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 ww . j a v a 2s . co m*/ Rectangle bounds = getPathBounds(path); if (bounds != null) { bounds.height = getVisibleRect().height; scrollRectToVisible(bounds); } } setSelectionPath(path); }
From source file:org.apache.jmeter.gui.action.ChangeParent.java
private void changeParent(TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) { // keep the old name if it was not the default one Controller currentController = (Controller) currentNode.getUserObject(); JMeterGUIComponent currentGui = guiPackage.getCurrentGui(); String defaultName = JMeterUtils.getResString(currentGui.getLabelResource()); if (StringUtils.isNotBlank(currentController.getName()) && !currentController.getName().equals(defaultName)) { newParent.setName(currentController.getName()); }/*from w w w .j a v a2 s .c o m*/ JMeterTreeModel treeModel = guiPackage.getTreeModel(); JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel); JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent(); int index = parentNode.getIndex(currentNode); treeModel.insertNodeInto(newNode, parentNode, index); treeModel.removeNodeFromParent(currentNode); int childCount = currentNode.getChildCount(); for (int i = 0; i < childCount; i++) { // Using index 0 is voluntary as child is removed in next step and added to new parent JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0); treeModel.removeNodeFromParent(node); treeModel.insertNodeInto(node, newNode, newNode.getChildCount()); } // select the node TreeNode[] nodes = treeModel.getPathToRoot(newNode); JTree tree = guiPackage.getTreeListener().getJTree(); tree.setSelectionPath(new TreePath(nodes)); }
From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java
/** * @param e {@link ActionEvent}/* w w w . j ava 2 s .c o m*/ */ private void doSearch(ActionEvent e) { boolean expand = e.getSource() == searchAndExpandButton; String wordToSearch = searchTF.getText(); if (StringUtils.isEmpty(wordToSearch)) { return; } else { this.lastSearch = wordToSearch; } // reset previous result ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SEARCH_RESET)); // do search Searcher searcher = null; if (isRegexpCB.isSelected()) { searcher = new RegexpSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText()); } else { searcher = new RawTextSearcher(isCaseSensitiveCB.isSelected(), searchTF.getText()); } GuiPackage guiPackage = GuiPackage.getInstance(); JMeterTreeModel jMeterTreeModel = guiPackage.getTreeModel(); Set<JMeterTreeNode> nodes = new HashSet<>(); for (JMeterTreeNode jMeterTreeNode : jMeterTreeModel.getNodesOfType(Searchable.class)) { try { if (jMeterTreeNode.getUserObject() instanceof Searchable) { Searchable searchable = (Searchable) jMeterTreeNode.getUserObject(); List<JMeterTreeNode> matchingNodes = jMeterTreeNode.getPathToThreadGroup(); List<String> searchableTokens = searchable.getSearchableTokens(); boolean result = searcher.search(searchableTokens); if (result) { nodes.addAll(matchingNodes); } } } catch (Exception ex) { logger.error("Error occured searching for word:" + wordToSearch, ex); } } GuiPackage guiInstance = GuiPackage.getInstance(); JTree jTree = guiInstance.getMainFrame().getTree(); for (JMeterTreeNode jMeterTreeNode : nodes) { jMeterTreeNode.setMarkedBySearch(true); if (expand) { jTree.expandPath(new TreePath(jMeterTreeNode.getPath())); } } GuiPackage.getInstance().getMainFrame().repaint(); searchTF.requestFocusInWindow(); this.setVisible(false); }
From source file:org.apache.jmeter.gui.MainFrame.java
private void addQuickComponentHotkeys(JTree treevar) { Action quickComponent = new AbstractAction("Quick Component") { private static final long serialVersionUID = 1L; @Override/*from w ww.j a v a 2 s. co m*/ public void actionPerformed(ActionEvent actionEvent) { String propname = "gui.quick_" + actionEvent.getActionCommand(); String comp = JMeterUtils.getProperty(propname); log.debug("Event " + propname + ": " + comp); if (comp == null) { log.warn("No component set through property: " + propname); return; } GuiPackage guiPackage = GuiPackage.getInstance(); try { guiPackage.updateCurrentNode(); TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp)); JMeterTreeNode parentNode = guiPackage.getCurrentNode(); while (!MenuFactory.canAddTo(parentNode, testElement)) { parentNode = (JMeterTreeNode) parentNode.getParent(); } if (parentNode.getParent() == null) { log.debug("Cannot add element on very top level"); } else { JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode); guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath())); } } catch (Exception err) { log.warn("Failed to perform quick component add: " + comp, err); // $NON-NLS-1$ } } }; InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9, }; for (int n = 0; n < keyStrokes.length; n++) { treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent); inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n)); } }