Java Code Examples for org.openide.nodes.Node.isLeaf()

The following are Jave code examples for showing how to use isLeaf() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: ContextTreeView.java   Source Code and License Vote up 6 votes
public java.lang.Object getChild(java.lang.Object parent, int index) {
    int superCnt = super.getChildCount(parent);
    int myCnt = 0;

    for (int i = 0; i < superCnt; i++) {
        Object origChild = super.getChild(parent, i);
        Node n = Visualizer.findNode(origChild);

        if (!n.isLeaf()) {
            if (myCnt++ == index) {
                return origChild;
            }
        }
    }

    return null;
}
 
Example 2
Project: incubator-netbeans   File: ContextTreeView.java   Source Code and License Vote up 6 votes
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child) {
    int superCnt = super.getChildCount(parent);
    int myCnt = 0;

    for (int i = 0; i < superCnt; i++) {
        Object origChild = super.getChild(parent, i);

        if (child.equals(origChild)) {
            return myCnt;
        }

        Node n = Visualizer.findNode(origChild);

        if (!n.isLeaf()) {
            myCnt++;
        }
    }

    return -1;
}
 
Example 3
Project: incubator-netbeans   File: TemplateChooserPanelGUITest.java   Source Code and License Vote up 6 votes
private static void representationOf(Children c, StringBuilder b) {
    boolean first = true;
    for (Node n : c.getNodes(true)) {
        if (first) {
            first = false;
        } else {
            b.append(", ");
        }
        b.append(n.getDisplayName());
        if (!n.isLeaf()) {
            b.append('[');
            representationOf(n.getChildren(), b);
            b.append(']');
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: HistoryFileView.java   Source Code and License Vote up 6 votes
private int getPrevRow(int row) {
    row = row - 1;
    Outline outline = tablePanel.treeView.getOutline();
    if(row < 0 || row >= outline.getRowCount()) {
        return -1;
    }
    TreePath path = outline.getOutlineModel().getLayout().getPathForRow(row);
    Node node = Visualizer.findNode(path.getLastPathComponent());
    if(node.isLeaf()) {
        if(node instanceof RevisionNode || node instanceof RevisionNode.FileNode) {
            return row;
        } else {
            return -1;
        }
    } else {
        TreePathSupport support = outline.getOutlineModel().getTreePathSupport();
        if(support.isExpanded(path)) {
            return getPrevRow(row);
        } else {
            support.expandPath(path);
            return row + node.getChildren().getNodesCount();
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: HistoryFileView.java   Source Code and License Vote up 6 votes
private int getNextRow(int row) {
    row = row + 1;
    Outline outline = tablePanel.treeView.getOutline();
    if(row < 0 || row >= outline.getRowCount()) {
        return -1;
    }
    TreePath path = outline.getOutlineModel().getLayout().getPathForRow(row);
    Node node = Visualizer.findNode(path.getLastPathComponent());
    if(node.isLeaf()) {
        if(node instanceof RevisionNode || node instanceof RevisionNode.FileNode) {
            return row;
        } else {
            return -1;
        }
    } else {
        TreePathSupport support = outline.getOutlineModel().getTreePathSupport();
        if(support.isExpanded(path)) {
            return getPrevRow(row);
        } else {
            support.expandPath(path);
            return row + 1;
        }
    }
}
 
Example 6
Project: incubator-netbeans   File: SettingChildren.java   Source Code and License Vote up 6 votes
protected Node copyNode (Node node) {
    boolean filter = false;
    try {
        DataObject d = (DataObject) node.getCookie (DataObject.class);
        if (d != null) {
            InstanceCookie.Of inst = (InstanceCookie.Of)d.getCookie(InstanceCookie.Of.class);
            if (inst != null && (inst.instanceOf(Node.class) || inst.instanceOf(Node.Handle.class))) {
                // This is just a node, not a real setting. E.g. ModuleNode, LoaderPoolNode. As such,
                // it itself should not display any origin information, it would make no sense. However
                // its children might have a legitimate DataObject cookie from the SFS.
                d = null;
            }
        }
        DataFolder folder = (DataFolder) node.getCookie (DataFolder.class);
        FileSystem fs = d == null || folder != null ? null : d.getPrimaryFile ().getFileSystem ();
        filter = fs == null ? false : fs.isDefault();
    } catch (FileStateInvalidException e) {
        // ignore
    }

    return filter ? new SettingFilterNode (node) : 
        node.isLeaf() ? node.cloneNode() : new TrivialFilterNode(node);
}
 
Example 7
Project: incubator-netbeans   File: DefaultSearchResultsDisplayer.java   Source Code and License Vote up 5 votes
@Override
public boolean isRelevantNode(Node node) {
    if (node == null) {
        return false;
    } else {
        Node parent = node.getParentNode();
        return node.isLeaf() && parent != null
                && parent.getParentNode() != null;
    }
}
 
Example 8
Project: incubator-netbeans   File: PackageViewTest.java   Source Code and License Vote up 5 votes
private static String printTree(Node n) {
    String name = n.getDisplayName();
    if (n.isLeaf()) {
        return name;
    } else {
        List<String> kidNames = new ArrayList<String>();
        for (Node kid : n.getChildren().getNodes(true)) {
            kidNames.add(printTree(kid));
        }
        return name + kidNames;
    }
}
 
Example 9
Project: incubator-netbeans   File: VersionNode.java   Source Code and License Vote up 5 votes
private static Children createChildren(FileObject fo) {
    if (fo != null) {
        try {
            Node n = DataObject.find(fo).getNodeDelegate();
            if (!n.isLeaf()) { // using n.cloneNode().getChildren() does not work; someone caches cloneNode??
                return new FilterNode.Children(n);
            }
        } catch (DataObjectNotFoundException x) {
            Exceptions.printStackTrace(x);
        }
    }
    return Children.LEAF;
}
 
Example 10
Project: incubator-netbeans   File: ClassPathFileChooser.java   Source Code and License Vote up 5 votes
FilteredNode(Node original, String displayName, Filter filter) {
    super(original, original.isLeaf() ? Children.LEAF : new FilteredChildren(original, filter));
    if (displayName != null) {
        disableDelegation(DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME);
        setDisplayName(displayName);
    }
}
 
Example 11
Project: incubator-netbeans   File: ContextTreeView.java   Source Code and License Vote up 5 votes
public int getChildCount(java.lang.Object parent) {
    int superCnt = super.getChildCount(parent);
    int myCnt = 0;

    for (int i = 0; i < superCnt; i++) {
        Node n = Visualizer.findNode(super.getChild(parent, i));

        if (!n.isLeaf()) {
            myCnt++;
        }
    }

    return myCnt;
}
 
Example 12
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 5 votes
private void initChildren() {
    Node node = getOriginal();
    node.addNodeListener(WeakListeners.create(NodeListener.class, this, node));
    final boolean leaf = node.isLeaf();
    if (!leaf) {
        setChildren(children);
    }
}
 
Example 13
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 4 votes
private ActionFilterNode(Node original, int mode) {
    super(original, original.isLeaf() ? Children.LEAF : new ActionFilterChildren(original, mode, null));
    this.mode = mode;
}
 
Example 14
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 4 votes
private ActionFilterNode(Node original, int mode, FileObject root, Lookup lkp) {
    super(original, original.isLeaf() ? Children.LEAF : new ActionFilterChildren(original, mode,root),lkp);
    this.mode = mode;
}
 
Example 15
Project: incubator-netbeans   File: DocumentViewPanel.java   Source Code and License Vote up 4 votes
/**
 * Initializes the tree view.
 */
private void initTreeView() {
    treeView = new BeanTreeView() {
        {
            tree.setCellRenderer(createTreeCellRenderer(tree.getCellRenderer()));
        }

        @Override
        public void expandAll() {
            // The original expandAll() doesn't work for us as it doesn't
            // seem to wait for the calculation of sub-nodes.
            Node root = manager.getRootContext();
            expandAll(root);
            // The view attempts to scroll to the expanded node
            // and it does it with a delay. Hence, simple calls like
            // tree.scrollRowToVisible(0) have no effect (are overriden
            // later) => the dummy collapse and expansion attempts
            // to work around that and keep the root node visible.
            collapseNode(root);
            expandNode(root);
        }

        /**
         * Expands the whole sub-tree under the specified node.
         *
         * @param node root node of the sub-tree that should be expanded.
         */
        private void expandAll(Node node) {
            treeView.expandNode(node);
            for (Node subNode : node.getChildren().getNodes(true)) {
                if (!subNode.isLeaf()) {
                    expandAll(subNode);
                }
            }
        }
    };
    treeView.setAllowedDragActions(DnDConstants.ACTION_NONE);
    treeView.setAllowedDropActions(DnDConstants.ACTION_NONE);
    treeView.setRootVisible(false);
    add(treeView, BorderLayout.CENTER);
}
 
Example 16
Project: incubator-netbeans   File: TreeTableView.java   Source Code and License Vote up 4 votes
public SortedNode (Node original) {
    super(original, original.isLeaf() ? Children.LEAF : new SortedChildren(original));
    original2filter.put (original, this);
}
 
Example 17
Project: incubator-netbeans   File: ListView.java   Source Code and License Vote up 4 votes
/** This method is called when user double-clicks on some object or
* presses Enter key.
* @param index Index of object in current explored context
*/
final void performObjectAt(int index, int modifiers) {
    if ((index < 0) || (index >= model.getSize())) {
        return;
    }

    VisualizerNode v = (VisualizerNode) model.getElementAt(index);
    Node node = v.node;

    // if DefaultProcessor is set, the default action is notified to it overriding the default action on nodes
    if (defaultProcessor != null) {
        defaultProcessor.actionPerformed(new ActionEvent(node, 0, null, modifiers));

        return;
    }

    if (showParentNode && NodeListModel.findVisualizerDepth(model, v) == -1) {
        try {
            manager.setExploredContextAndSelection(node.getParentNode(), new Node[] { node });
        } catch (PropertyVetoException ex) {
            // OK, let it be
        }
        return;
    }

    // on double click - invoke default action, if there is any
    // (unless user holds CTRL key what means that we should always dive into the context)
    Action a = node.getPreferredAction();

    if ((a != null) && ((modifiers & InputEvent.CTRL_MASK) == 0)) {
        a = TreeView.takeAction(a, node);

        if (a.isEnabled()) {
            a.actionPerformed(new ActionEvent(node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N
        } else {
            Utilities.disabledActionBeep();
        }
    }
    // otherwise dive into the context
    else if (traversalAllowed && (!node.isLeaf())) {
        manager.setExploredContext(node, manager.getSelectedNodes());
    }
}
 
Example 18
Project: incubator-netbeans   File: PhysicalView.java   Source Code and License Vote up 4 votes
public ProjectIconNode(Node orig, boolean root) {
    super(orig, orig.isLeaf() ? Children.LEAF : new ProjectBadgingChildren(orig));
    this.root = root;
    setValue("VCS_PHYSICAL", Boolean.TRUE); //#159543 
    addNodeListener(this);
}
 
Example 19
Project: incubator-netbeans   File: PhadhailViews.java   Source Code and License Vote up 4 votes
public EQReplannedNode(Node n) {
    super(n, n.isLeaf() ? Children.LEAF : new EQReplannedChildren(n));
}
 
Example 20
Project: incubator-netbeans   File: PackageRenameHandlerImpl.java   Source Code and License Vote up 4 votes
@Override
public void handleRename(Node node, String newName) {
    DataFolder dob = (DataFolder) node.getCookie(DataObject.class);
    FileObject fo = dob.getPrimaryFile();
    if (node.isLeaf()) {
        //rename empty package and don't try to do any refactoring
        try {
            if (!RefactoringUtils.isValidPackageName(newName)) {
                String msg = new MessageFormat(NbBundle.getMessage(RenameRefactoringPlugin.class,"ERR_InvalidPackage")).format(
                        new Object[] {newName}
                );
                
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    msg, NotifyDescriptor.INFORMATION_MESSAGE));
                return;
            }
            ClassPath sourcepath = ClassPath.getClassPath(fo, ClassPath.SOURCE);
            if (sourcepath == null) {
                throw new IOException("no sourcepath for " + fo);
            }
            FileObject root = sourcepath.findOwnerRoot(fo);
            if (root == null) {
                throw new IOException(fo + " not in its own sourcepath " + sourcepath);
            }
            FileObject newFolder = FileUtil.createFolder(root, newName.replace('.','/'));
            while (dob.getChildren().length == 0 && dob.isDeleteAllowed() && !dob.getPrimaryFile().equals(newFolder)) {
                DataFolder parent = dob.getFolder();
                dob.delete();
                dob = parent;
            }
        } catch (IOException ioe) {
            ErrorManager.getDefault().notify(ioe);
        }
        return;
    }

    InstanceContent ic = new InstanceContent();
    ic.add(node);
    ExplorerContext d = new ExplorerContext();
    d.setNewName(newName);
    ic.add(d);
    final Lookup l = new AbstractLookup(ic);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l);
            if (Boolean.TRUE.equals(a.getValue("applicable"))) { //NOI18N
                a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
            }
        }
    });
}