List of usage examples for javax.swing.tree TreeNode isLeaf
boolean isLeaf();
From source file:EditLeafSample.java
public boolean isCellEditable(EventObject event) { boolean returnValue = super.isCellEditable(event); if (returnValue) { Object node = tree.getLastSelectedPathComponent(); if ((node != null) && (node instanceof TreeNode)) { TreeNode treeNode = (TreeNode) node; returnValue = treeNode.isLeaf(); }// ww w . ja v a2 s . c om } return returnValue; }
From source file:TreeDragTest.java
public void dragEnter(DropTargetDragEvent dtde) { TreeNode node = getNodeForEvent(dtde); if (node.isLeaf()) { dtde.rejectDrag();//w w w.ja v a2 s .c o m } else { // start by supporting move operations //dtde.acceptDrag(DnDConstants.ACTION_MOVE); dtde.acceptDrag(dtde.getDropAction()); } }
From source file:TreeDragTest.java
public void dragOver(DropTargetDragEvent dtde) { TreeNode node = getNodeForEvent(dtde); if (node.isLeaf()) { dtde.rejectDrag();/*from w w w.ja v a 2s .c om*/ } else { // start by supporting move operations //dtde.acceptDrag(DnDConstants.ACTION_MOVE); dtde.acceptDrag(dtde.getDropAction()); } }
From source file:TreeUtil.java
public void addNode(String name, Object obj) { itsMap.put(name, obj);/*from ww w.j av a 2 s. c o m*/ DefaultMutableTreeNode tempNode = itsRootNode; StringTokenizer tok = new StringTokenizer(name, "."); String currentName = null; while (tok.hasMoreTokens()) { String myTok = tok.nextToken(); currentName = (currentName == null) ? myTok : currentName + "." + myTok; boolean createNew = true; for (int j = 0; j < tempNode.getChildCount(); j++) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j); if (childNode.toString().equals(myTok)) { tempNode = childNode; createNew = false; break; } } if (createNew) { DefaultMutableTreeNode aNode = new DefaultMutableTreeNode(myTok); itsTreeMap.put(currentName, aNode); // Let's give some consideration to where in the tree we place // the new node. // We want any nodes with children to be listed first, in // alphabetical order. // Then come nodes with no children, in alphabetical order. if (tok.hasMoreTokens()) { // This node is not a leaf node int targeti; for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) { TreeNode bNode = tempNode.getChildAt(targeti); if (bNode.isLeaf() || bNode.toString().compareToIgnoreCase(myTok) > 0) { break; } } tempNode.insert(aNode, targeti); } else { // This node is a leaf node int targeti; for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) { TreeNode bNode = tempNode.getChildAt(targeti); if (bNode.isLeaf() && bNode.toString().compareToIgnoreCase(myTok) > 0) { break; } } tempNode.insert(aNode, targeti); } tempNode = aNode; } } }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
@Action public void addServiceToUser() { // ? ? ? . ? ?? ? ?? ??. .. listUsers.getSelectedIndex() == -1 listUserService.setModel(((QUser) listUsers.getSelectedValue()).getPlanServiceList()); final QUser user = (QUser) listUsers.getSelectedValue(); final QService service = (QService) treeServices.getLastSelectedPathComponent(); if (service != null && service.isLeaf() && listUsers.getSelectedIndex() != -1 && !(user.hasService(service))) { user.addPlanService(service); if (listUserService.getLastVisibleIndex() != -1) { listUserService.setSelectedIndex(listUserService.getLastVisibleIndex()); QLog.l().logger().debug(" \"" + user.getName() + "\" ? \"" + service.getName() + "\"."); }//from w w w. j a v a2s. com } if (service != null && !service.isLeaf() && listUsers.getSelectedIndex() != -1 && !(user.hasService(service))) { QServiceTree.sailToStorm(service, (TreeNode service1) -> { if (service1.isLeaf() && !user.hasService((QService) service1)) { user.addPlanService((QService) service1); QLog.l().logger() .debug(" \"" + ((QUser) listUsers.getSelectedValue()).getName() + "\" ? \"" + ((QService) service1).getName() + "\"."); } }); if (listUserService.getLastVisibleIndex() != -1) { listUserService.setSelectedIndex(listUserService.getLastVisibleIndex()); } } }
From source file:ru.apertum.qsystem.client.forms.FAdmin.java
@Action public void addService() throws DocumentException { // ? ? ? ?, String serviceName = ""; boolean flag = true; while (flag) { serviceName = (String) JOptionPane.showInputDialog(this, getLocaleMessage("admin.add_service_dialog.title"), getLocaleMessage("admin.add_service_dialog.caption"), 3, null, null, serviceName); if (serviceName == null) { return; }//from www.j a v a2s .c om if ("".equals(serviceName)) { JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err1.title"), getLocaleMessage("admin.add_service_dialog.err1.caption"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } else if (QServiceTree.getInstance().hasByName(serviceName)) { JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err2.title"), getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } else if (serviceName.indexOf('\"') != -1) { JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err3.title"), getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } else if (serviceName.length() > 2001) { JOptionPane.showConfirmDialog(this, getLocaleMessage("admin.add_service_dialog.err4.title"), getLocaleMessage("admin.add_service_dialog.err2.caption"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } else { flag = false; } } // ? final QService newService = new QService(); newService.setName(serviceName); newService.setDescription(serviceName); newService.setStatus(1); newService.setSoundTemplate("021111"); newService.setAdvanceTimePeriod(60); newService.setCalendar(QCalendarList.getInstance().getById(1)); if (QScheduleList.getInstance().getSize() != 0) { newService.setSchedule(QScheduleList.getInstance().getElementAt(0)); } newService.setButtonText( "<html><b><p align=center><span style='font-size:20.0pt;color:red'>" + serviceName + "</span></b>"); //? newService.setPrefix("A"); QServiceTree.sailToStorm(QServiceTree.getInstance().getRoot(), (TreeNode service) -> { if (service.isLeaf()) { String pr = ((QService) service).getPrefix(); if (!pr.isEmpty()) { if (pr.substring(pr.length() - 1).compareToIgnoreCase( newService.getPrefix().substring(newService.getPrefix().length() - 1)) >= 0) { newService.setPrefix( String.valueOf((char) (pr.substring(pr.length() - 1).charAt(0) + 1)).toUpperCase()); } } } }); final QService parentService = (QService) treeServices.getLastSelectedPathComponent(); QServiceTree.getInstance().insertNodeInto(newService, parentService, parentService.getChildCount()); final TreeNode[] nodes = QServiceTree.getInstance().getPathToRoot(newService); final TreePath path = new TreePath(nodes); treeServices.scrollPathToVisible(path); treeServices.setSelectionPath(path); // ? ? ? ? ?? ? , .. ? deleteServiceFromUsers(parentService); QLog.l().logger().debug(" ? \"" + serviceName + "\" \"" + parentService.getName() + "\""); }
From source file:org.apache.accumulo.examples.wikisearch.parser.FieldIndexQueryReWriter.java
private RewriterTreeNode transformTreeNode(TreeNode node) throws ParseException { if (node.getType().equals(ASTEQNode.class) || node.getType().equals(ASTNENode.class)) { if (log.isDebugEnabled()) { log.debug("transformTreeNode, Equals Node"); }//from w w w .j a v a2s. co m Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", ""); boolean negated = t.getOperator().equals("!="); RewriterTreeNode child = new RewriterTreeNode(ParserTreeConstants.JJTEQNODE, fName, fValue, negated); return child; } } } if (node.getType().equals(ASTERNode.class) || node.getType().equals(ASTNRNode.class)) { if (log.isDebugEnabled()) { log.debug("transformTreeNode, Regex Node"); } Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", ""); boolean negated = node.getType().equals(ASTNRNode.class); RewriterTreeNode child = new RewriterTreeNode(ParserTreeConstants.JJTERNODE, fName, fValue, negated); return child; } } } if (node.getType().equals(ASTLTNode.class) || node.getType().equals(ASTLENode.class) || node.getType().equals(ASTGTNode.class) || node.getType().equals(ASTGENode.class)) { if (log.isDebugEnabled()) { log.debug("transformTreeNode, LT/LE/GT/GE node"); } Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", "").toLowerCase(); boolean negated = false; // to be negated, must be child of Not, which is handled elsewhere. int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator()); RewriterTreeNode child = new RewriterTreeNode(mytype, fName, fValue, negated); return child; } } } RewriterTreeNode returnNode = null; if (node.getType().equals(ASTAndNode.class) || node.getType().equals(ASTOrNode.class)) { int parentType = node.getType().equals(ASTAndNode.class) ? ParserTreeConstants.JJTANDNODE : ParserTreeConstants.JJTORNODE; if (log.isDebugEnabled()) { log.debug("transformTreeNode, AND/OR node: " + parentType); } if (node.isLeaf() || !node.getTerms().isEmpty()) { returnNode = new RewriterTreeNode(parentType); Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", ""); boolean negated = t.getOperator().equals("!="); int childType = JexlOperatorConstants.getJJTNodeType(t.getOperator()); RewriterTreeNode child = new RewriterTreeNode(childType, fName, fValue, negated); if (log.isDebugEnabled()) { log.debug("adding child node: " + child.getContents()); } returnNode.add(child); } } } else { returnNode = new RewriterTreeNode(parentType); } } else if (node.getType().equals(ASTNotNode.class)) { if (log.isDebugEnabled()) { log.debug("transformTreeNode, NOT node"); } if (node.isLeaf()) { // NOTE: this should be cleaned up a bit. Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", "").toLowerCase(); boolean negated = !t.getOperator().equals("!="); int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator()); return new RewriterTreeNode(mytype, fName, fValue, negated); } } } else { returnNode = new RewriterTreeNode(ParserTreeConstants.JJTNOTNODE); } } else if (node.getType().equals(ASTJexlScript.class) || node.getType().getSimpleName().equals("RootNode")) { if (log.isDebugEnabled()) { log.debug("transformTreeNode, ROOT/JexlScript node"); } if (node.isLeaf()) { returnNode = new RewriterTreeNode(ParserTreeConstants.JJTJEXLSCRIPT); // NOTE: this should be cleaned up a bit. Multimap<String, QueryTerm> terms = node.getTerms(); for (String fName : terms.keySet()) { Collection<QueryTerm> values = terms.get(fName); for (QueryTerm t : values) { if (null == t || null == t.getValue()) { continue; } String fValue = t.getValue().toString(); fValue = fValue.replaceAll("'", ""); boolean negated = t.getOperator().equals("!="); int mytype = JexlOperatorConstants.getJJTNodeType(t.getOperator()); RewriterTreeNode child = new RewriterTreeNode(mytype, fName, fValue, negated); returnNode.add(child); return returnNode; } } } else { returnNode = new RewriterTreeNode(ParserTreeConstants.JJTJEXLSCRIPT); } } else { log.error("transformTreeNode, Currently Unsupported Node type: " + node.getClass().getName() + " \t" + node.getType()); } for (TreeNode child : node.getChildren()) { returnNode.add(transformTreeNode(child)); } return returnNode; }
From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java
public TreeNode getNextTreeNode(TreeNode node) { ITreeState state = getTreeState();/*www . java 2s . co m*/ DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null) { return null; } if (!node.isLeaf() && node.getAllowsChildren() && state.isNodeExpanded(node)) { return node.getChildAt(0); } TreeNode nextNode = parent.getChildAfter(node); if (nextNode == null) { return getNextParent(parent); } return nextNode; }
From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java
public TreeNode getPrevTreeNode(TreeNode node) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); if (parent == null) { return null; }//from www .j av a2s . co m TreeNode prevNode = parent.getChildBefore(node); if (prevNode != null) { ITreeState state = getTreeState(); node = prevNode; while (!node.isLeaf() && node.getAllowsChildren() && state.isNodeExpanded(node)) { node = node.getChildAt(node.getChildCount() - 1); } return node; } DefaultTreeModel treeModel = getTreeModel(); if (parent == treeModel.getRoot()) { return null; } return parent; }
From source file:org.robotframework.swing.tree.TreeOperator.java
public boolean isLeaf(TreePath nodeIdentifier) { TreeNode lastPathComponent = (TreeNode) nodeIdentifier.getLastPathComponent(); return lastPathComponent.isLeaf(); }