org.openide.nodes.AbstractNode Java Examples

The following examples show how to use org.openide.nodes.AbstractNode. 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: HistoryProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void openHistory(File[] files) {
    if(files == null || files.length == 0) {
        return;
    }
    Set<File> repositories = getRepositoryRoots(files);
    if(repositories == null || repositories.isEmpty()) {
        return;
    }
    List<Node> nodes = new ArrayList<Node>(files.length);
    for (File f : files) {
        nodes.add(new AbstractNode(Children.LEAF, Lookups.fixed(f)) {
            @Override
            public String getDisplayName() {
                return getLookup().lookup(File.class).getName();
            }
        });
    }
    SearchHistoryAction.openSearch(repositories.iterator().next(), files, Utils.getContextDisplayName(VCSContext.forNodes(nodes.toArray(new Node[nodes.size()]))));
}
 
Example #2
Source File: ExplorerActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Setups an explorer manager to be ready to delete something.
 * @param em manager 
 */
private static void setupExplorerManager (ExplorerManager em) throws Exception {
    AbstractNode root = new RootNode ();
    Node[] arr = new Node[] {
        new Del ("1"), new Del ("2")
    };
    root.getChildren().add (arr);
    
    em.setRootContext(root);
    em.setSelectedNodes(root.getChildren().getNodes());
    
    assertEquals (
        "Same nodes selected", 
        Arrays.asList (arr),
        Arrays.asList (root.getChildren ().getNodes ())
    );
}
 
Example #3
Source File: TreeViewTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
TestTreeView() {
    super();
    tree.setAutoscrolls(true);

    setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    vertScrollBar = getVerticalScrollBar();
    
    rootNode = new AbstractNode(new TreeChildren());
    rootNode.setDisplayName("Root node");
    
    tree.setRowHeight(20);
    
    Dimension prefSize = new Dimension(200, 6 * tree.getRowHeight() + 8);
    prefSize.width = (int) (prefSize.width * 1.25f)
                     + vertScrollBar.getWidth();
    setPreferredSize(prefSize);
}
 
Example #4
Source File: UINode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected Node[] createNodes(StackTraceElement key) {
    AbstractNode an = new AbstractNode(Children.LEAF);
    an.setName(key.getClassName() + "." + key.getMethodName());
    an.setDisplayName(NbBundle.getMessage(UINode.class, "MSG_StackTraceElement", 
        new Object[] { 
            key.getFileName(),
            key.getClassName(),
            key.getMethodName(),
            key.getLineNumber(),
            afterLastDot(key.getClassName()),
        }
    ));
    an.setIconBaseWithExtension("org/netbeans/modules/uihandler/stackframe.gif"); // NOI18N
    return new Node[] { an };
}
 
Example #5
Source File: NodeTreeModelTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testAddNodesDoesNotRecreateAllOfThem() {
    Keys keys = new Keys(true);
    AbstractNode an = new AbstractNode(keys);

    NodeTreeModel model = new NodeTreeModel();
    model.setNode(an);

    assertEquals("Node set", Visualizer.findVisualizer(an), model.getRoot());
    assertEquals("No children", 0, model.getChildCount(model.getRoot()));
    keys.keys("1", "2", "3");
    assertEquals("3 children", 3, model.getChildCount(model.getRoot()));
    keys.keys("2", "1", "3");
    assertEquals("still 3 children", 3, model.getChildCount(model.getRoot()));
    keys.keys("2");
    assertEquals("1 children", 1, model.getChildCount(model.getRoot()));

    assertEquals("No nodes created yet", 0, keys.cnt);
}
 
Example #6
Source File: BrowseFolders.java    From netbeans with Apache License 2.0 6 votes vote down vote up
BrowseFolders(SourceGroup[] folders, Class<?> target, String preselectedFileName) {
    initComponents();
    String description = target == DataFolder.class ? "ACSD_BrowseFolders" : "ACSD_BrowseFiles"; // NOI18N
    getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BrowseFolders.class, description));

    this.folders = folders;
    this.target = target;
    manager = new ExplorerManager();
    AbstractNode rootNode = new AbstractNode(new SourceGroupsChildren(folders));
    manager.setRootContext(rootNode);

    // Create the templates view
    btv = new BeanTreeView();
    btv.setRootVisible(false);
    btv.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    btv.setBorder(SAMPLE_SCROLL_PANE.getBorder());
    expandSelection(preselectedFileName);
    folderPanel.add(btv, BorderLayout.CENTER);
}
 
Example #7
Source File: SourcesNodeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({"# {0} - label of source group", "# {1} - project name", "ERR_WrongSG={0} is owned by project {1}, cannot be used here, see issue #138310 for details."})
@Override
public Node node(SourceGroup group) {
    Project owner = FileOwnerQuery.getOwner(group.getRootFolder());
    if (owner != project) {
        if (owner == null) {
            //#152418 if project for folder is not found, just look the other way..
            Logger.getLogger(SourcesNodeFactory.class.getName()).log(Level.INFO, "Cannot find a project owner for folder {0}", group.getRootFolder()); //NOI18N
            return null;
        }
        AbstractNode erroNode = new AbstractNode(Children.LEAF);
        String prjText = ProjectUtils.getInformation(owner).getDisplayName();
        erroNode.setDisplayName(ERR_WrongSG(group.getDisplayName(), prjText));
        return erroNode;
    }
    return PackageView.createPackageView(group);
}
 
Example #8
Source File: GitUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void openInVersioningView (Collection<File> files, File repository, ProgressMonitor pm) {
    List<Node> nodes = new LinkedList<Node>();
    for (File file : files) {
        Node node = new AbstractNode(Children.LEAF, Lookups.fixed(file));
        nodes.add(node);
        // this will refresh seen roots
    }
    Git.getInstance().getFileStatusCache().refreshAllRoots(Collections.<File, Collection<File>>singletonMap(repository, files), pm);
    if (!pm.isCanceled()) {
        final VCSContext context = VCSContext.forNodes(nodes.toArray(new Node[nodes.size()]));
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                SystemAction.get(StatusAction.class).performContextAction(context);
            }
        });
    }
}
 
Example #9
Source File: MoveToDependencyManagementPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
            NbMavenProject nbprj = currentProject.getLookup().lookup(NbMavenProject.class);
    List<MavenEmbedder.ModelDescription> lin = null;
    if (nbprj != null) {
        lin = MavenEmbedder.getModelDescriptors(nbprj.getMavenProject());
    }
    if (lin != null) {
                final Children ch = new PomChildren(lin);
                SwingUtilities.invokeLater(new Runnable() {
            @Override
                    public void run() {
                       treeView.setRootVisible(false);
                       explorerManager.setRootContext(new AbstractNode(ch));
                        try {
                            explorerManager.setSelectedNodes(new Node[]{
                                explorerManager.getRootContext().getChildren().getNodes()[0]
                            });
                        } catch (PropertyVetoException ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    }
                });
    }
}
 
Example #10
Source File: LibraryChooserGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setRootNode() {
    explorer.setRootContext(new AbstractNode(new LibraryManagerChildren()));
    tree.expandAll();
    try {
        if (explorer.getRootContext().getChildren().getNodes(true).length > 0) {
            explorer.setSelectedNodes(new Node[] {explorer.getRootContext().getChildren().getNodes(true)[0]});
        }
    } catch (PropertyVetoException x) {
        Exceptions.printStackTrace(x);
    }
    /* XXX Nothing seems to work to scroll to top; how is it done?
    tree.getViewport().setViewPosition(new Point());
    tree.getViewport().scrollRectToVisible(new Rectangle(0, 0, 1, 1));
     */
    tree.requestFocus();
}
 
Example #11
Source File: RepositoryBrowserPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void addNotify () {
    super.addNotify();
    if (!initialized) {
        initialized = true;
        List<AbstractNode> keys = new LinkedList<AbstractNode>();
        if (options.contains(Option.DISPLAY_BRANCHES_LOCAL) || options.contains(Option.DISPLAY_BRANCHES_REMOTE)) {
            keys.add(new BranchesTopNode(((RepositoryNode) getNode()).getRepository()));
        }
        if (options.contains(Option.DISPLAY_TAGS)) {
            keys.add(new TagsNode(((RepositoryNode) getNode()).getRepository()));
        }
        if (options.contains(Option.DISPLAY_STASH)) {
            keys.add(new StashesNode(((RepositoryNode) getNode()).getRepository()));
        }
        if (options.contains(Option.DISPLAY_REMOTES)) {
            keys.add(new RemotesNode(((RepositoryNode) getNode()).getRepository()));
        }
        setKeys(keys);
    }
}
 
Example #12
Source File: TopComponentActivatedNodesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setUp () {        
    System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); // no lookup
    
    
    p = new ExplorerPanel ();
    em = p.getExplorerManager ();
    
    TreeView tv = new BeanTreeView ();
    p.add (tv);
    Children ch = new Children.Array ();
    nodes = new Node[10];
    for (int i = 0; i < 10; i++) {
        nodes[i] = new AbstractNode (Children.LEAF);
        nodes[i].setName ("Node" + i);
    }
    ch.add (nodes);
    Node root = new AbstractNode (ch);
    em.setRootContext (root);
    
    // check synchronixzation before
    assertArrays ("INIT: getSelectedNodes equals getActivatedNodes.",
        em.getSelectedNodes (), p.getActivatedNodes ());
}
 
Example #13
Source File: TransactionView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Invoked by DisplayAction. Displays monitor data for the selected
    * node. 
    * PENDING - register this as a listener for the display action
    */
   void displayTransaction(Node node) {
if (node == null)
    return;

if(node instanceof TransactionNode || 
   node instanceof NestedNode) {
    try {
	selected = (AbstractNode)node;
    } 
    catch (ClassCastException ex) {
	selected = null;
	selectNode(null);
    }
}
else {
    selected = null;
    selectNode(null);
}

showData(); 
   }
 
Example #14
Source File: Nodes.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages("LBL_Wait=Please Wait...")
public static Node createWaitNode() {
    AbstractNode an = new AbstractNode(Children.LEAF);
    an.setIconBaseWithExtension(WAIT_GIF);
    an.setDisplayName(Bundle.LBL_Wait());
    return an;
}
 
Example #15
Source File: PhysicalViewTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCreateNodeAndChangeDataObject() throws IOException {
    AbstractNode node = new AbstractNode(Children.LEAF) {
        @Override
        public void setExpert(boolean b) {
            setChildren(new Children.Array());
        }
    };
    Node res = new PhysicalView.ProjectIconNode(node, true);
    assertEquals(Boolean.TRUE, res.getValue("VCS_PHYSICAL"));
    assertTrue("No children", res.isLeaf());

    node.setExpert(true);
    
    assertFalse("Now it has children", res.isLeaf());
}
 
Example #16
Source File: ChangeParametersFix.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void doFullChangeMethodParameters(TreePathHandle tph, ParameterInfo[] newParameterInfo) {
    InstanceContent ic = new InstanceContent();
    ic.add(tph);
    ic.add(new AbstractNode(Children.LEAF, Lookups.singleton(tph)));
    for (ParameterInfo parameterInfo : newParameterInfo) {
        ic.add(parameterInfo);
    }
    Lookup actionContext = new AbstractLookup(ic);
    final Action a = JavaRefactoringActionsFactory.changeParametersAction().createContextAwareInstance(actionContext);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
        }
    });
}
 
Example #17
Source File: JavaDataSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a default node for a particular java file object.
 * @param javafile the java file object to represent
 * @return the node
 */
public static Node createJavaNode(FileObject javafile) {
    try {
        DataObject jdo = DataObject.find(javafile);
        return new JavaNode(jdo, true);
    } catch (DataObjectNotFoundException ex) {
        Logger.getLogger(JavaDataSupport.class.getName()).log(Level.INFO, null, ex);
        return new AbstractNode(Children.LEAF);
    }
}
 
Example #18
Source File: ProjectFileExplorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ProjectFileExplorer() {
    projects = OpenProjects.getDefault().getOpenProjects();
    rootChildren = new Children.Array();
    explorerClientRoot = new AbstractNode(rootChildren);
    projectNodeList = new ArrayList<Node>();
    manager = new ExplorerManager();

    initComponents();
    initUserComponents();
}
 
Example #19
Source File: UINode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node[] createNodes(Object key) {
    AbstractNode an = new AbstractNode(Children.LEAF);
    an.setName((String)key);
    an.setIconBaseWithExtension("org/netbeans/lib/uihandler/module.gif"); // NOI18N
    return new Node[] { an };
}
 
Example #20
Source File: ResourceNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
ResourceNode(ChildFactory<? extends AbstractNode> childFactory ,
        ResourceNodeType type , String name ) 
{
    super(childFactory, name);
    setDisplayName( name);
    this.resourceType= type; 
}
 
Example #21
Source File: GoalsPanel.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    final Children ch = Children.create(new PluginChildren(gradleProject, gradleUserTaskProvider), true);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            treeView.setRootVisible(false);
            explorerManager.setRootContext(new AbstractNode(ch));
            treeView.expandAll();
        }
    });
}
 
Example #22
Source File: TopComponentGetLookupOverridenTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ListingYourComponent (Logger l) {
    delegate = new YourComponent();
    LOG = l;
    
    addPropertyChangeListener (this);
    delegate.getExplorerManager ().setRootContext (new AbstractNode (new Children.Array ()));
    java.lang.ref.SoftReference ref = new java.lang.ref.SoftReference (new Object ());
    assertGC ("Trying to simulate issue 40842, to GC TopComponent$SynchronizeNodes", ref);
    
    delegate.getExplorerManager().addPropertyChangeListener(this);
}
 
Example #23
Source File: VisualizerNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIndexOfProvidesResultsEvenIfTheVisualizerIsComputedViaDifferentMeans() throws Exception {
    AbstractNode a = new AbstractNode(new Children.Array());
    AbstractNode m = new AbstractNode(Children.LEAF);
    a.getChildren().add(new Node[] { Node.EMPTY.cloneNode(), m, Node.EMPTY.cloneNode() });
    
    TreeNode ta = Visualizer.findVisualizer(a);
    TreeNode tm = Visualizer.findVisualizer(m);
    
    assertEquals("Index is 1", 1, ta.getIndex(tm));
}
 
Example #24
Source File: CodelessProjectLogicalView.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public org.openide.nodes.Node createLogicalView() {

    try {
        return new ProjectNode(project);
    } catch (DataObjectNotFoundException donfe) {
        Exceptions.printStackTrace(donfe);
        //Fallback—the directory couldn't be created -
        //read-only filesystem or something evil happened
        return new AbstractNode(Children.LEAF);
    }
}
 
Example #25
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 #26
Source File: ClientExplorerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClientExplorerPanel(FileObject targetSource) {
    super(targetSource);
    sourceProjects = OpenProjects.getDefault().getOpenProjects();
    rootChildren = new Children.Array();
    explorerClientRoot = new AbstractNode(rootChildren);
    projectNodeList = new ArrayList<Node>();
}
 
Example #27
Source File: NodeListModelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNodesAreReferenced() {
    
    WeakReference[] tn;
    
    Node c = new AbstractNode(new CNodeChildren());
    NodeListModel model = new NodeListModel(c);
    
    
    
    tn = new WeakReference[model.getSize()];
    for (int i = 0; i < model.getSize(); i++) {
        tn[i] = new WeakReference(model.getElementAt(i));
    }
    
    assertTrue("Need to have more than one child", tn.length > 0);
    
    boolean fail;
    try {
        assertGC("First node should not be gone", tn[0]);
        fail = true;
    } catch (Error err) {
        fail = false;
    }
    if (fail) {
        fail("First node garbage collected!!! " + tn[0].get());
    }
    
    for (int i = 0; i < tn.length; i++) {
        // else fail
        assertNotNull("One of the nodes was gone. Index: " + i, tn[i].get());
    }
}
 
Example #28
Source File: VisualizerNodeEventsOrderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Node[] createNodes(String key) {
    if (key.startsWith("-")) {
        return null;
    }

    AbstractNode node = new AbstractNode(LEAF);
    node.setName(key);
    cnt++;
    return new Node[] {node};
}
 
Example #29
Source File: XMLDataObjectNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Lookup getEnvironment(DataObject obj) {
    if (obj.getPrimaryFile().equals(which)) {
        AbstractNode an = new AbstractNode(Children.LEAF);
        an.setName("ENV");
        return an.getLookup();
    }
    return null;
}
 
Example #30
Source File: VisualizerNodeEventsOrderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    lch = new LazyChildren();
    a = new AbstractNode(lch);
    ta = Visualizer.findVisualizer(a);     
}