List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor.java
/** * Appends given {@link TreeNode} and its children to the {@link StringBuffer}. *//*from www . j a va 2 s .c om*/ private static void getTooltip_appendNodes(StringBuffer buffer, TreeNode node, String prefix) { // append separator if (buffer.length() != 0) { buffer.append("\n"); } // append current node buffer.append(prefix); if (node instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode mutableTreeNode = (DefaultMutableTreeNode) node; buffer.append(mutableTreeNode.getUserObject()); } // append children String newPrefix = prefix + " "; for (int i = 0; i < node.getChildCount(); i++) { getTooltip_appendNodes(buffer, node.getChildAt(i), newPrefix); } }
From source file:org.eclipse.wb.tests.designer.swing.model.component.JTreeTest.java
public void test_JTree_parsing() throws Exception { ContainerInfo panel = parseContainer("import javax.swing.tree.*;", "public class Test extends JPanel {", " public Test() {", " JTree tree = new JTree();", " add(tree);", " tree.setModel(new DefaultTreeModel(", " new DefaultMutableTreeNode('(root)') {", " {", " DefaultMutableTreeNode node1 = new DefaultMutableTreeNode('1');", " DefaultMutableTreeNode node2 = new DefaultMutableTreeNode('11');", " node1.add(node2);", " add(node1);", " node1 = new DefaultMutableTreeNode('2');", " node1.add(new DefaultMutableTreeNode('21'));", " add(node1);", " }", " }", " ));", " }", "}"); panel.refresh();//from w w w. ja v a2 s . co m // ComponentInfo treeInfo = panel.getChildrenComponents().get(0); JTree treeObject = (JTree) treeInfo.getObject(); // validate model { TreeModel model = treeObject.getModel(); assertNotNull(model); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); { assertEquals("(root)", rootNode.getUserObject()); assertEquals(2, rootNode.getChildCount()); } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(0); assertEquals("1", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("11", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } { DefaultMutableTreeNode node_1 = (DefaultMutableTreeNode) rootNode.getChildAt(1); assertEquals("2", node_1.getUserObject()); assertEquals(1, node_1.getChildCount()); { DefaultMutableTreeNode node_2 = (DefaultMutableTreeNode) node_1.getChildAt(0); assertEquals("21", node_2.getUserObject()); assertEquals(0, node_2.getChildCount()); } } } // check "model" property { Property modelProperty = treeInfo.getPropertyByTitle("model"); PropertyEditor modelEditor = modelProperty.getEditor(); // text { String text = (String) ReflectionUtils.invokeMethod2(modelEditor, "getText", Property.class, modelProperty); assertEquals("(root), +1, ++11, +2, ++21", text); } // tooltip { String tooltip = getPropertyTooltipText(modelEditor, modelProperty); assertEquals(StringUtils.join( new String[] { "(root)", " 1", " 11", " 2", " 21" }, "\n"), tooltip); // position PropertyTooltipProvider provider = modelEditor.getAdapter(PropertyTooltipProvider.class); assertSame(PropertyTooltipProvider.BELOW, provider.getTooltipPosition()); } } }
From source file:org.fseek.simon.swing.util.TreeUtil.java
public static DefaultMutableTreeNode clear(LinkTreeNode node) { for (int i = 0; i < node.getChildCount(); i++) { TreeNode childAt = node.getChildAt(i); if (childAt instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode child = (DefaultMutableTreeNode) childAt; if (child.getUserObject() == null || child.getUserObject().toString().length() <= 0) { return child; }//from w w w . j a va 2 s. c o m } } return null; }
From source file:org.icefaces.application.showcase.view.bean.ApplicationController.java
/** * Utility method to assign the selected state of a tree node. * * @param nodeId nodeId of the node to set the selected state on. * @param value desired selection state of node. *///from w w w . j ava 2s.co m private void setTreeNodeSelectedState(String nodeId, boolean value) { DefaultMutableTreeNode defaultNode = findTreeNode(nodeId); if (defaultNode != null) { NavigationTreeNode node = (NavigationTreeNode) defaultNode.getUserObject(); node.setSelected(value); } }
From source file:org.icefaces.application.showcase.view.bean.ApplicationController.java
/** * Utility method to toggle the selected state of the specified node. * * @param nodeId nodeId of the the node to toggle the expanded state of. */// ww w . ja v a 2 s . c o m private void toggleTreeNodeExpandedState(String nodeId) { DefaultMutableTreeNode defaultNode = findTreeNode(nodeId); if (defaultNode != null) { NavigationTreeNode node = (NavigationTreeNode) defaultNode.getUserObject(); node.setExpanded(!node.isExpanded()); } }
From source file:org.icefaces.application.showcase.view.bean.ApplicationController.java
/** * Utility method to find a tree node by its ID. * * @param nodeId node Id of node to to find in tree. * @return node specified by ID or null of no node of that ID is found. *//*from ww w.j a va 2s . c om*/ private DefaultMutableTreeNode findTreeNode(String nodeId) { ApplicationSessionModel applicationModel = (ApplicationSessionModel) FacesUtils .getManagedBean(BeanNames.APPLICATION_MODEL); Collection<DefaultTreeModel> trees = applicationModel.getNavigationTrees().values(); DefaultMutableTreeNode node; DefaultMutableTreeNode rootNode; // search all trees defined by meta data using a depthFirst search. for (DefaultTreeModel treeModel : trees) { rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); Enumeration nodes = rootNode.depthFirstEnumeration(); while (nodes.hasMoreElements()) { node = (DefaultMutableTreeNode) nodes.nextElement(); NavigationTreeNode tmp = (NavigationTreeNode) node.getUserObject(); if (tmp.getNodeId() != null && tmp.getNodeId().equals(nodeId)) { return node; } } } return null; }
From source file:org.jbpcc.admin.beans.navigation.TreeBean.java
/** * Initialises tree root and calls method to build tree of configuration schema changes *///from w w w .j a v a2 s.c o m public TreeBean() { DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode(); UrlNodeUserObject rootObject = new UrlNodeUserObject(rootTreeNode, this); rootObject.setText("Empty root"); rootObject.setExpanded(true); Document dom = readDOM(); Element docElement = dom.getDocumentElement(); // get root element if (!docElement.getNodeName().equals(ELEM_APP)) { throw new IllegalArgumentException("Illegal tree menu configuration"); } rootObject.setUrl(APP_CONTEXT_PATH + docElement.getAttribute(ATTR_URL)); rootObject.setIconUrl(docElement.getAttribute(ATTR_ICON)); rootObject.setSelectedNode(true); rootTreeNode.setUserObject(rootObject); rootNodeObject = (UrlNodeUserObject) rootTreeNode.getUserObject(); rootNodeObject.setSelectedNode(true); model = new DefaultTreeModel(rootTreeNode); buildTree(rootTreeNode, docElement); }
From source file:org.jbpcc.admin.beans.navigation.TreeBean.java
private void buildTree(DefaultMutableTreeNode rootTreeNode, Element docElement) { ((UrlNodeUserObject) rootTreeNode.getUserObject()).setText(getLabelResource(docElement)); // get nodelist of elements & loop through items NodeList nodeList = docElement.getElementsByTagName(ELEM_MODULE); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Element itemElement = (Element) nodeList.item(i); DefaultMutableTreeNode itemNode = createParentMenuItem(itemElement); if (itemElement.hasChildNodes()) { NodeList childNodeList = itemElement.getChildNodes(); for (int j = 0; j < childNodeList.getLength(); j++) { if (childNodeList.item(j).getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) childNodeList.item(j); if (ELEM_PAGE.equals(childElement.getNodeName())) { createChildMenuItem(itemNode, childElement); }//w w w.j a va2 s. co m } } } rootTreeNode.add(itemNode); } } }
From source file:org.kepler.objectmanager.cache.LocalRepositoryManager.java
/** * //from w w w.ja va 2 s.c o m * @param dmtn * @param dir * @return the TreeNode that corresponds to the given directory name */ private DefaultMutableTreeNode checkChildren(DefaultMutableTreeNode dmtn, File folder) { Enumeration<?> children = dmtn.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); if (child.getUserObject().equals(folder)) { return child; } } return null; }
From source file:org.kuali.test.creator.TestCreator.java
/** * * @param platform//from w ww. j av a 2s. c o m */ public void handleCreateTest(Platform platform) { if (platform == null) { if (testRepositoryTree.getSelectionPath() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) testRepositoryTree.getSelectionPath() .getLastPathComponent(); if (node != null) { Object o = node.getUserObject(); if (o instanceof Platform) { platform = (Platform) o; } } } } CreateTestDlg dlg = new CreateTestDlg(this, platform); if (dlg.isSaved()) { enableCreateTestActions(false); if (LOG.isDebugEnabled()) { LOG.debug("init new " + dlg.getTestHeader().getTestType() + " test for platform " + dlg.getTestHeader().getPlatformName()); } TestHeader testHeader = dlg.getTestHeader(); String testDescription = dlg.getDescription(); Platform testPlatform = Utils.findPlatform(getConfiguration(), testHeader.getPlatformName()); switch (testHeader.getTestType().intValue()) { case TestType.INT_WEB: createTestPanel .replaceCenterComponent(new WebTestPanel(this, testPlatform, testHeader, testDescription)); break; case TestType.INT_WEB_SERVICE: createTestPanel.replaceCenterComponent( new WebServicePanel(this, testPlatform, testHeader, testDescription)); break; case TestType.INT_DATABASE: createTestPanel .replaceCenterComponent(new DatabasePanel(this, testPlatform, testHeader, testDescription)); break; case TestType.INT_FILE: createTestPanel .replaceCenterComponent(new FileTestPanel(this, testPlatform, testHeader, testDescription)); break; } } }