org.openide.nodes.Children Java Examples

The following examples show how to use org.openide.nodes.Children. 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: MatchingObjectNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private MatchingObjectNode(Node original,
        org.openide.nodes.Children children,
        final MatchingObject matchingObject,
        ReplaceCheckableNode checkableNode) {
    super(children, createLookup(matchingObject, checkableNode));
    replacing = checkableNode.isCheckable();
    Parameters.notNull("original", original);                       //NOI18N
    this.matchingObject = matchingObject;
    if (matchingObject.isObjectValid()) {
        this.original = original;
        setValidOriginal();
        origNodeListener = new OrigNodeListener();
        original.addNodeListener(origNodeListener);
    } else {
        setInvalidOriginal();
    }
    validityListener = new ValidityListener(matchingObject);
    matchingObject.addPropertyChangeListener(
            MatchingObject.PROP_INVALIDITY_STATUS,
            validityListener);
    selectionListener = new SelectionListener();
    matchingObject.addPropertyChangeListener(selectionListener);
}
 
Example #2
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void expandFirstLevel(BeanTreeView btv) {
    
    Node root = manager.getRootContext();
    Children ch = root.getChildren();
    if ( ch == Children.LEAF ) {
        return;
    }
    Node nodes[] = ch.getNodes(true);

    btv.expandNode(root);
    for ( int i = 0; i < nodes.length; i++ ) {            
        btv.expandNode( nodes[i] );
        if ( i == 0 ) {
            try {
                manager.setSelectedNodes( new Node[] { nodes[i] } );
            }
            catch ( java.beans.PropertyVetoException e ) {
                // No selection for some reason
            }
        }
    }
}
 
Example #3
Source File: TemplateWizard1.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Updates the root of templates.
 * @param root the root folder
 */
private void updateRootNode (DataFolder root) {
    if (root == null) {
        FileObject fo = FileUtil.getConfigFile("Templates"); // NOI18N
        if (fo != null && fo.isFolder ())
            root = DataFolder.findFolder (fo);
    }

    if (root == null || root.equals(templatesRoot))
        return;

    templatesRoot = root;

    Children ch = new DataShadowFilterChildren(root.getNodeDelegate());
    getExplorerManager().setRootContext(new DataShadowFilterNode (root.getNodeDelegate(), ch, root.getNodeDelegate().getDisplayName ()));
}
 
Example #4
Source File: Tab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Exchanges deserialized root context to projects root context
* to keep the uniquennes. */
protected void validateRootContext () {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run () {
            Node n = new AbstractNode(Children.LEAF);
            n.setName(NbBundle.getMessage(Tab.class, "MSG_Tab.rootNode.loading")); //NOI18N
            setRootContext(n);
        }
    });
    final Node projectsRc = FavoritesNode.getNode ();
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run () {
            setRootContext(projectsRc);
        }
    });
}
 
Example #5
Source File: TreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override final void propertyChange(PropertyChangeEvent evt) {
    if (manager == null) {
        return; // the tree view has been removed before the event got delivered
    }
    final String prop = evt.getPropertyName();
    if (!prop.equals(ExplorerManager.PROP_ROOT_CONTEXT) &&
            !prop.equals(ExplorerManager.PROP_EXPLORED_CONTEXT) &&
            !prop.equals(ExplorerManager.PROP_SELECTED_NODES)) {
        return;
    }
    Children.MUTEX.readAccess(new Runnable() {
        public @Override void run() {
            if (prop.equals(ExplorerManager.PROP_ROOT_CONTEXT)) {
                synchronizeRootContext();
            }

            if (prop.equals(ExplorerManager.PROP_EXPLORED_CONTEXT)) {
                synchronizeExploredContext();
            }

            if (prop.equals(ExplorerManager.PROP_SELECTED_NODES)) {
                synchronizeSelectedNodes();
            }
        }
    });
}
 
Example #6
Source File: TreeTableView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void sortingChanged() {
    // PENDING: remember the last sorting to avoid multiple sorting
    // remenber expanded folders
    TreeNode tn = (TreeNode) (this.getRoot());
    java.util.List<TreePath> list = new ArrayList<TreePath>();
    Enumeration<TreePath> en = TreeTableView.this.tree.getExpandedDescendants(new TreePath(tn));

    while ((en != null) && en.hasMoreElements()) {
        TreePath path = en.nextElement();

        // bugfix #32328, don't sort whole subtree but only expanded folders
        Node n = ((VisualizerNode) path.getLastPathComponent ()).node;
        Children children = n.getChildren();
        if (children instanceof SortedChildren) {
            ((SortedChildren) children).sortNodes ();
            list.add(path);
        } // else Children.LEAF
    }

    // expand again folders
    for (int i = 0; i < list.size(); i++) {
        TreeTableView.this.tree.expandPath(list.get(i));
    }
}
 
Example #7
Source File: Nodes.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ErrorDescriptionNode(AnalyzerFactory provider, final ErrorDescription ed) {
    super(Children.LEAF, Lookups.fixed(ed, new OpenErrorDescription(provider, ed), new DescriptionReader() {
        @Override public CharSequence getDescription() {
            return ed.getDetails();
        }
    }));
    int line = -1;
    try {
        final PositionBounds range = ed.getRange();
        if (range != null) {
            line = range.getBegin().getLine();
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    setDisplayName((line != (-1) ? (line + 1 + ":") : "") + ed.getDescription());
    icon = SPIAccessor.ACCESSOR.getAnalyzerIcon(provider);
}
 
Example #8
Source File: MatchingObjectNodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Test that bug 213441 is fixed.
 */
@RandomlyFails
public void testBug213441() throws IOException, InterruptedException,
        InvocationTargetException {

    Node n = new AbstractNode(Children.LEAF);
    Semaphore s = new Semaphore(0);
    ResultModel rm = SearchTestUtils.createResultModelWithOneMatch();
    MatchingObject mo = rm.getMatchingObjects().get(0);
    MatchingObjectNode mon = new MatchingObjectNode(n, Children.LEAF, mo,
            false);
    mon.addNodeListener(new DisplayNameChangeListener(s));
    mon.getDisplayName();
    mo.getFileObject().delete();
    rm.close();
    assertTrue("Display name change event has not been fired!", //NOI18N
            s.tryAcquire(10, TimeUnit.SECONDS));
}
 
Example #9
Source File: TreeModelNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Lookup createLookup(Object object, Models.CompoundModel model,
                                   Children ch, Index[] indexPtr) {
    CheckNodeCookieImpl cnc = new CheckNodeCookieImpl(model, object);
    boolean canReorder;
    try {
        canReorder = model.canReorder(object);
    } catch (UnknownTypeException ex) {
        if (!(object instanceof String)) {
            Logger.getLogger(TreeModelNode.class.getName()).log(Level.CONFIG, "Model: "+model, ex);
        }
        canReorder = false;
    }
    if (canReorder) {
        Index i = new IndexImpl(model, object);
        indexPtr[0] = i;
        return Lookups.fixed(object, cnc, i);
    } else {
        return Lookups.fixed(object, cnc);
    }
}
 
Example #10
Source File: SectionNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public final void dataModelPropertyChange(Object source, String propertyName, Object oldValue, Object newValue) {
    if (sectionPanel != null) {
        SectionInnerPanel innerPanel = sectionPanel.getInnerPanel();
        if (innerPanel != null) {
            innerPanel.dataModelPropertyChange(source, propertyName, oldValue, newValue);
        }
    }
    Children children = getChildren();
    if (children != null) {
        Node[] nodes = children.getNodes();
        for (int i = 0; i < nodes.length; i++) {
            Node node = nodes[i];
            if (node instanceof SectionNode) {
                ((SectionNode) node).dataModelPropertyChange(source, propertyName, oldValue, newValue);
            }
        }
    }
}
 
Example #11
Source File: BytecodeNode.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public BytecodeNode(InputBytecode bytecode, InputGraph graph, String bciValue) {

        super(Children.LEAF);
        this.setDisplayName(bytecode.getBci() + " " + bytecode.getName());

        bciValue = bytecode.getBci() + " " + bciValue;
        bciValue = bciValue.trim();

        Properties.PropertySelector<InputNode> selector = new Properties.PropertySelector<InputNode>(graph.getNodes());
        StringPropertyMatcher matcher = new StringPropertyMatcher("bci", bciValue);
        List<InputNode> nodeList = selector.selectMultiple(matcher);
        if (nodeList.size() > 0) {
            nodes = new HashSet<InputNode>();
            for (InputNode n : nodeList) {
                nodes.add(n);
            }
            this.setDisplayName(this.getDisplayName() + " (" + nodes.size() + " nodes)");
        }
    }
 
Example #12
Source File: RepositoryPathNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private RepositoryPathNode(BrowserClient client, RepositoryPathEntry entry, boolean repositoryFolder) {
    super(entry.getSvnNodeKind() == SVNNodeKind.DIR ? new RepositoryPathChildren(client) : Children.LEAF);
    this.entry = entry;
    this.client = client;
    this.repositoryFolder = repositoryFolder;
    initProperties();
}
 
Example #13
Source File: AddDependencyPanel.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public FilterNodeWithDefAction(Node nd, boolean leaf) {
    super(nd, leaf ? Children.LEAF : new FilterNode.Children(nd) {
        @Override
        protected Node[] createNodes(Node key) {
            return new Node[]{createFilterWithDefaultAction(key, true)};
        }
    });
}
 
Example #14
Source File: UICommonUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getFileObjectFromNode(Node node) {
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if(fo == null) {
        Children children = node.getChildren();
        for(Node child : children.getNodes()) {
            fo = child.getLookup().lookup(FileObject.class);
            if(fo != null) {
                return child.getDisplayName().equals("<default package>") ? fo : fo.getParent();
            }
        }
    }
    return fo;
}
 
Example #15
Source File: RootNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private RootNode(ChildFactory factory, String displayName, String shortDesc, String iconBase, ServerRegistry registry) {
    super(Children.create(factory, true));
    this.registry = registry;

    setName(""); // NOI18N
    setDisplayName(displayName);
    setShortDescription(shortDesc);
    setIconBaseWithExtension(iconBase);
}
 
Example #16
Source File: Hk2ResourceNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Hk2ResourceNode(final Lookup lookup, final ResourceDesc resource, 
        final ResourceDecorator decorator, final Class customizer) {
    super(Children.LEAF, lookup, resource.getName(), decorator);
    setDisplayName(resource.getName());
    setShortDescription("<html>name: " + resource.getName() + "</html>");

    if(decorator.canUnregister()) {
        getCookieSet().add(new Hk2Cookie.Unregister(lookup,
                resource.getName(), resource.getCommandType(),
                decorator.getCmdPropertyName(),
                decorator.isCascadeDelete()));
    }

    if (decorator.canEditDetails()) {
        GlassfishModule m = lookup.lookup(GlassfishModule.class);
        if (null != m) {
            String rootDir = m.getInstanceProperties().get(GlassfishModule.GLASSFISH_FOLDER_ATTR);
            if (ServerUtilities.isTP2(rootDir)) {
                // don't add the edit details cookie
            } else {
                // add the editor cookie
                getCookieSet().add(new Hk2Cookie.EditDetails(
                        lookup, getDisplayName(),
                        resource.getCommandType(), customizer));
            }

        }

    }
}
 
Example #17
Source File: ShowExecutionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MojoNode(Children children, Lookup lookup) {
    super(children, lookup);
    this.tree = lookup.lookup(ExecutionEventObject.Tree.class);
    this.start = (ExecMojo) tree.getStartEvent();
    this.end = (ExecMojo) tree.getEndEvent();
    config = lookup.lookup(RunConfig.class);
    assert start != null && end != null;
    
    setIconBaseWithExtension(IconResources.MOJO_ICON);
    setDisplayName(start.goal);
}
 
Example #18
Source File: SuiteCustomizerLibraries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean getValue() throws IllegalAccessException, InvocationTargetException {
    Children ch = node.getChildren();
    Logger logger = Logger.getLogger(EnabledProp.class.getName());
    if (ch == Children.LEAF) {
        logger.log(Level.FINE, "Node '" + node.getName() + "' is LEAF, enabled=" + node.isEnabled());
        return node.isEnabled();
    } else if (node.getState() == EnabledState.PART_ENABLED) {
        logger.log(Level.FINE, "Node '" + node.getName() + "', enabled=null");
        return null;
    } else {
        logger.log(Level.FINE, "Node '" + node.getName() + "', enabled=" + node.isEnabled());
        return node.isEnabled();
    }
}
 
Example #19
Source File: WildflyItemNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public WildflyItemNode(Children children, String name) {
    super(children);
    setDisplayName(name);
    if (getChildren() instanceof Refreshable) {
        getCookieSet().add(new RefreshModulesCookieImpl((Refreshable) getChildren()));
    }
}
 
Example #20
Source File: AddDependencyPanel.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of VersionNode
 */
public VersionNode(MavenDependencyInfo.Version version) {
    super(Children.LEAF, Lookups.fixed(version));

    this.nbvi = version;

    setName(version.getVersion());
    setDisplayName(version.getVersion());
}
 
Example #21
Source File: NodeListModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final void setNode(final Node root, final boolean showRoot) {
    Mutex.EVENT.readAccess(new Runnable() {
        @Override
        public void run() {
            if (!Children.MUTEX.isReadAccess() && !Children.MUTEX.isWriteAccess()) {
                Children.MUTEX.readAccess(this);
                return;
            }
            VisualizerNode v = VisualizerNode.getVisualizer(null, root);

            if (v == parent && showParent == showRoot) {
                // no change
                return;
            }

            removeAll();
            parent.removeNodeModel(listener());

            showParent = showRoot;
            parent = v;
            selectedObject = v;
            clearChildrenCount();

            addAll();
            parent.addNodeModel(listener());
        }
    });
}
 
Example #22
Source File: TreeViewTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Create nodes for a given key.
 * @param key the key
 * @return child nodes for this key or null if there should be no
 *   nodes for this key
 */
protected Node[] createNodes(Object key) {
    if (key.toString().startsWith("-")) {
        return null;
    }
    AbstractNode an = new AbstractNode (Children.LEAF);
    an.setName (key.toString ());

    return new Node[] { an };
}
 
Example #23
Source File: HgVersioningTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    setContentTitle((String) in.readObject());
    files = (File[]) in.readObject();
    final List<Node> nodes = new ArrayList<>(files.length);
    for (File file : files) {
        nodes.add(new AbstractNode(Children.LEAF, Lookups.singleton(file)) {
            @Override
            public String getDisplayName() {
                return getLookup().lookup(File.class).getName();
            }
        });
    }
    setContext(null);
    Utils.post(new Runnable() {

        @Override
        public void run () {
            try {
                OpenProjects.getDefault().openProjects().get();
            } catch (InterruptedException | ExecutionException ex) {
            }
            final VCSContext ctx = VCSContext.forNodes(nodes.toArray(new Node[nodes.size()]));
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run () {
                    if (context == null) {
                        setContext(ctx);
                        performRefreshAction();
                    }
                }
                
            });
        }
    });
}
 
Example #24
Source File: AddPropertyDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addPluginNode(String groupId, String artifactId, String version, String mojo, Children.Array rootChilds) {
    if (version == null || groupId == null || artifactId == null) {
        return;
    }
    assert rootChilds != null;
    Children.Array pluginChilds = new Children.Array();
    try {
        Set<PluginIndexManager.ParameterDetail> exprs = PluginIndexManager.getPluginParameters(groupId, artifactId, version, mojo);
        if (exprs != null) {
            for (PluginIndexManager.ParameterDetail el : exprs) {
                if (el.getExpression() == null) {
                    continue;
                }
                AbstractNode param = new AbstractNode(Children.LEAF, Lookups.singleton(el));
                param.setIconBaseWithExtension("org/netbeans/modules/maven/customizer/param.png");
                param.setDisplayName(el.getExpression() + " (" + el.getName() + ")"); //NOI18N
                pluginChilds.add(new Node[]{param});
            }
        }
    } catch (Exception exception) {
        Logger.getLogger(AddPropertyDialog.class.getName()).log(Level.INFO, "Error while retrieving list of expressions", exception); //NOI18N
    }
    AbstractNode plugin = new AbstractNode(pluginChilds);
    plugin.setIconBaseWithExtension("org/netbeans/modules/maven/customizer/mojo.png");
    plugin.setDisplayName(groupId + ":" + artifactId + (mojo != null ? (" [" + mojo + "]") : "")); //NOI18N
    rootChilds.add(new Node[]{plugin});
}
 
Example #25
Source File: AreVisualizersSynchronizedTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node[] createNodes(String key) {
    if (key.contains("Empty")) {
        return null;
    } else {
        AbstractNode n = new AbstractNode(Children.LEAF);
        n.setName(key);
        return new Node[]{n};
    }
}
 
Example #26
Source File: EmbeddedIndexerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node createNodeDelegate() {
    final Node n = new AbstractNode(
            Children.LEAF,
            Lookup.EMPTY);
    return n;
}
 
Example #27
Source File: ClassPathFileChooser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Node getRootNode(FileObject fileInProject, Filter filter) {
    Children children = new Children.Array();
    children.add(createPackageRootNodes(fileInProject, choosingFolder, filter));
    AbstractNode root = new AbstractNode(children);
    root.setIconBaseWithExtension("org/netbeans/modules/form/editors2/iconResourceRoot.gif"); // NOI18N
    root.setDisplayName(NbBundle.getMessage(ClassPathFileChooser.class, "CTL_ClassPathName")); // NOI18N
    // ProjectUtils.getInformation(prj).getDisplayName()
    return root;
}
 
Example #28
Source File: DockerNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private DockerNode(DockerChildFactory factory, String displayName, String shortDesc, String iconBase) {
    super(Children.create(factory, true));

    setName(""); // NOI18N
    setDisplayName(displayName);
    setShortDescription(shortDesc);
    setIconBaseWithExtension(iconBase);
}
 
Example #29
Source File: VCSStatusNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected VCSStatusNode (T node, Lookup lkp) {
    super(Children.LEAF, lkp);
    this.node = node;
    nameProperty = new NameProperty(this);
    pathProperty = new PathProperty(this);
    statusProperty = new StatusProperty(this);
}
 
Example #30
Source File: ComponentNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
ComponentNode findNodeFor(ComponentInfo ci) {
    if (ci.equals(this.ci)) {
        return this;
    }
    Children ch = getChildren();
    Node[] subNodes = ch.getNodes();
    for (Node n : subNodes) {
        ComponentNode cn = (ComponentNode) n;
        ComponentNode node = cn.findNodeFor(ci);
        if (node != null) {
            return node;
        }
    }
    return null;
}