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

The following examples show how to use org.openide.nodes.Node#isLeaf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplateChooserPanelGUITest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 2
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 3
Source File: SettingChildren.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 4
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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
Source File: ContextTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 6
Source File: ExplorerTopComponent.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private Node findObjectNode(Node topNode, OpenSimObject openSimObject) {
    if (topNode instanceof OpenSimObjectNode){
        if (((OpenSimObjectNode)topNode).getOpenSimObject().equals(openSimObject))
            return topNode;
    }
    if (topNode instanceof ExperimentalDataNode){
        ExperimentalDataNode edn = (ExperimentalDataNode) topNode;
        if (openSimObject.equals(edn.getDataObject()))
            return topNode;
    }
    if (topNode.isLeaf()) return null;
    boolean found = false;
    Children chden= topNode.getChildren();
    Node fndNode=null;
    for(int ch=0; ch < chden.getNodesCount() && !found; ch++){
        fndNode = findObjectNode(chden.getNodeAt(ch), openSimObject);
        found = (fndNode != null);
    }
    return fndNode;
}
 
Example 7
Source File: VersionNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 8
Source File: CreateSiteTemplate.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void writeChildren(ZipOutputStream str, FileObject projectDirectory, FileObject siteRoot, Children children) throws IOException {
    for (Node node : children.getNodes(true)) {
        FileObject fo = node.getLookup().lookup(FileObject.class);
        InputStream is = null;
        if (!fo.isFolder()) {
            is = fo.getInputStream();
        }
        try {
            Checkable ch = node.getLookup().lookup(Checkable.class);
            if (!Boolean.TRUE.equals(ch.isSelected())) {
                continue;
            }
            String relPath = getRelativePath(projectDirectory, siteRoot, fo);
            if (fo.isFolder()) {
                relPath += "/"; //NOI18N
            }
            ZipEntry ze = new ZipEntry(relPath);
            str.putNextEntry(ze);
            if (is != null) {
                FileUtil.copy(fo.getInputStream(), str);
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
        if (!node.isLeaf()) {
            writeChildren(str, projectDirectory, siteRoot, node.getChildren());
        }
    }
}
 
Example 9
Source File: ContextTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 10
Source File: DefaultSearchResultsDisplayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ClassPathFileChooser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 12
Source File: PackageViewTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 13
Source File: ListView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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 14
Source File: PhysicalView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 15
Source File: LookupNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
Leaf (Node node, DataObject data, Node parent) {
    super(node, ((data instanceof XMLDataObject) || node.isLeaf()) ? Children.LEAF : new FilterNode.Children(node));
    this.data = data;
    this.parent = parent;
}
 
Example 16
Source File: PhadhailViews.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public EQReplannedNode(Node n) {
    super(n, n.isLeaf() ? Children.LEAF : new EQReplannedChildren(n));
}
 
Example 17
Source File: CSSStylesDocumentPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the tree view.
 */
private void initTreeView() {
    treeView = new BeanTreeView() {
        {
            MouseAdapter listener = createTreeMouseListener();
            tree.addMouseListener(listener);
            tree.addMouseMotionListener(listener);
            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 18
Source File: ClientSideProjectLogicalView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public FolderFilterNode(ClientSideProject project, BasicNodes nodeType, Node folderNode, List<File> ignoreList) {
    super(folderNode, folderNode.isLeaf() ? Children.LEAF :
            new FolderFilterChildren(project, folderNode, ignoreList));
    this.nodeType = nodeType;
    delegate = folderNode;
}
 
Example 19
Source File: ActionFilterNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private ActionFilterNode(Node original, int mode) {
    super(original, original.isLeaf() ? Children.LEAF : new ActionFilterChildren(original, mode, null));
    this.mode = mode;
}
 
Example 20
Source File: DocumentViewPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}