Java Code Examples for org.openide.nodes.Node

The following examples show how to use org.openide.nodes.Node. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   Source File: SectionNodePanel.java    License: Apache License 2.0 6 votes vote down vote up
public SectionNodePanel(final SectionNode node, boolean openFirstChild) {
    super(node.getSectionNodeView(), node, node.getDisplayName(), node);
    this.openFirstChild = openFirstChild;
    
    if (node.getKey() instanceof SectionView) {
        // the section corresponding to the top level node is always expanded
        setInnerViewMode();
    } else if (node.isExpanded()) {
        setExpandedViewMode();
    }
    node.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (Node.PROP_DISPLAY_NAME.equals(evt.getPropertyName())) {
                setTitle(node.getDisplayName());
            }
        }
    });
}
 
Example 2
Source Project: netbeans   Source File: BrowseFolders.java    License: Apache License 2.0 6 votes vote down vote up
public void actionPerformed( ActionEvent e ) {
    String command = e.getActionCommand();

    if ( COMMAND_SELECT.equals( command ) ) {
        Node selection[] = browsePanel.getExplorerManager().getSelectedNodes();
        
        if ( selection != null && selection.length > 0 ) {
            DataObject dobj = (DataObject)selection[0].getLookup().lookup( DataObject.class );
            //if (dobj!=null && dobj.getClass().isAssignableFrom(target)) {
                result = dobj.getPrimaryFile();
            //}
            /*
            if ( dobj != null ) {
                FileObject fo = dobj.getPrimaryFile();
                if ( fo.isFolder() ) {
                    result = fo;
                }
            }
            */
        }
        
        
    }
}
 
Example 3
@Override
    protected Sheet createSheet() {
        Sheet sheet = super.createSheet();
        Sheet.Set set = Sheet.createPropertiesSet();
        set.setDisplayName("Bloom");
        set.setName(Node.class.getName());
        BloomFilter obj = (BloomFilter) filter;
        if (obj == null) {
            return sheet;
        }
//        set.put(makeProperty(obj, float.class, "getBloomIntensity", "setBloomIntensity", "Intensity"));
//        set.put(makeProperty(obj, float.class, "getBlurScale", "setBlurScale", "Blur Scale"));
//        set.put(makeProperty(obj, float.class, "getDownSamplingFactor", "setDownSamplingFactor", "Downsampling Factor"));
//        set.put(makeProperty(obj, float.class, "getExposureCutOff", "setExposureCutOff", "Exposure Cutoff"));
//        set.put(makeProperty(obj, float.class, "getExposurePower", "setExposurePower", "Exposure Power"));
         createFields(BloomFilter.class, set, obj);
        sheet.put(set);
        return sheet;

    }
 
Example 4
Source Project: netbeans   Source File: NewAction.java    License: Apache License 2.0 6 votes vote down vote up
private NewType[] newTypes() {
    if (lookup != null) {
        java.util.Collection c = lookup.lookupResult(Node.class).allItems();

        if (c.size() == 1) {
            Iterator<Lookup.Item> it = c.iterator();

            while (it.hasNext()) {
                Lookup.Item item = it.next();
                Node n = (Node) item.getInstance();

                if (n != null) {
                    if (n == prevNode && prevTypes != null) {
                        return prevTypes;
                    }
                    prevNode = n;
                    prevTypes = n.getNewTypes();
                    return prevTypes;
                }
            }
        }
    }

    return getNewTypes();
}
 
Example 5
Source Project: netbeans   Source File: PrintAction.java    License: Apache License 2.0 6 votes vote down vote up
private PrintProvider[] getCookieProviders(Node[] nodes) {
//out();
//out("get cookie provider");
        if (nodes == null) {
//out("NODES NULL");
            return null;
        }
        List<PrintProvider> providers = new ArrayList<PrintProvider>();

        for (Node node : nodes) {
//out("  see: " + node);
            PrintProvider provider = getCookieProvider(node);

            if (provider != null) {
                providers.add(provider);
            }
        }
        if (providers.size() == 0) {
//out("result null");
            return null;
        }
//out("result: " + providers);
        return providers.toArray(new PrintProvider[providers.size()]);
    }
 
Example 6
Source Project: netbeans   Source File: TreeView.java    License: Apache License 2.0 6 votes vote down vote up
/** Collapses the tree under given node.
*
* @param n node to collapse
*/
public void collapseNode(final Node n) {
    if (n == null) {
        throw new IllegalArgumentException();
    }

    // run safely to be sure all preceding events are processed (especially VisualizerEvent.Added)
    // otherwise VisualizerNodes may not be in hierarchy yet (see #140629)
    VisualizerNode.runSafe(new Runnable() {
        @Override
        public void run() {
            final TreePath path = getTreePath(n);
            LOG.log(Level.FINE, "collapseNode: {0} {1}", new Object[] { n, path });
            tree.collapsePath(path);
            LOG.fine("collapsePath done");
        }
    });
}
 
Example 7
Source Project: netbeans   Source File: FavoritesTest.java    License: Apache License 2.0 6 votes vote down vote up
@RandomlyFails // got empty list of nodes in NB-Core-Build #3603
public void testSelectWithAdditionExisting() throws Exception {
    RootsTest.clearBareFavoritesTabInstance();
    TopComponent win = RootsTest.getBareFavoritesTabInstance();
    assertNull(win);
    fav.add(file);
    assertTrue(fav.isInFavorites(file));
    fav.selectWithAddition(file);
    win = RootsTest.getBareFavoritesTabInstance();
    assertNotNull(win);
    assertTrue(win.isOpened());
    assertTrue(fav.isInFavorites(file));
    EventQueue.invokeAndWait(new Runnable() {   // Favorites tab EM refreshed in invokeLater, we have to wait too

        public void run() {
            ExplorerManager man = ((ExplorerManager.Provider) RootsTest.getBareFavoritesTabInstance()).getExplorerManager();
            assertNotNull(man);
            Node[] nodes = man.getSelectedNodes();
            assertEquals(Arrays.toString(nodes), 1, nodes.length);
            assertEquals(TEST_TXT, nodes[0].getName());
        }

    });
}
 
Example 8
Source Project: netbeans   Source File: EventsAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (!(source instanceof EventMenuItem))
            return;

    EventMenuItem mi = (EventMenuItem) source;
    Event event = ((EventMenuItem)source).getEvent();
    Node.Property prop = event.getComponent()
                                   .getPropertyByName(event.getId());
    if (prop != null) {
        String handlerName = mi.getHandlerName();
        event.getComponent().getFormModel().getFormEvents()
            .attachEvent(event, handlerName, null);

        try { // hack to update the property sheet
            if (handlerName == null)
                handlerName = (String) prop.getValue();
            prop.setValue(handlerName);
        }
        catch (Exception ex) {}
    }
}
 
Example 9
Source Project: netbeans   Source File: SelectLayoutAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt) {
    Node[] nodes = getNodes();
    for (int i = 0; i < nodes.length; i++) {
        RADVisualContainer container = getContainer(nodes[i]);
        if (container == null) {
            continue;
        }

        if (paletteItem != null) {
            // set the selected layout on the container
            container.getFormModel().getComponentCreator().createComponent(
                paletteItem, container, null);
        } else if (defaultLayout) {
            container.getFormModel().getComponentCreator().restoreDefaultLayout(container);
        } else if (container.getLayoutSupport() != null) {
            convertToNewLayout(container);
        }
    }
}
 
Example 10
Source Project: opensim-gui   Source File: OneFrameNode.java    License: Apache License 2.0 6 votes vote down vote up
protected final void createGeometryNodes() {
    // attached_geometry doesn't reach geometry mounted on 
    // offset frames, use iterator instead
    // Caveat if nested bodies or components have geometry 
    // it may appear multiple times
    ComponentsList compList = frame.getComponentsList();
    ComponentIterator compIter = compList.begin();
    Children children = getChildren();
    while (!compIter.equals(compList.end())) {
        Component comp = compIter.__deref__();
        Geometry oneG = Geometry.safeDownCast(comp);
        if (oneG != null && FrameGeometry.safeDownCast(oneG) == null) {
            Frame gFrame = oneG.getFrame();
            if (gFrame.equals(frame)){
                OneGeometryNode node = new OneGeometryNode(oneG);
                Node[] arrNodes = new Node[1];
                arrNodes[0] = node;
                children.add(arrNodes);
            }
        }
        compIter.next();
    }
}
 
Example 11
Source Project: netbeans   Source File: ViewDataAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void performAction (final Node[] activatedNodes) {
    final DatabaseConnection connection = activatedNodes[0].getLookup().lookup(DatabaseConnection.class);
    if (connection != null) {
        RP.post(
            new Runnable() {
                @Override
                public void run() {
                    String expression = null;
                    try {
                        expression = getDefaultQuery(activatedNodes);
                        SQLEditorSupport.openSQLEditor(connection.getDatabaseConnection(), expression + ";\n", true); //NOI18N
                    } catch(Exception exc) {
                        Logger.getLogger(ViewDataAction.class.getName()).log(Level.INFO, exc.getLocalizedMessage() + " while executing expression " + expression, exc); // NOI18N
                        String message = NbBundle.getMessage (ViewDataAction.class, "ShowDataError", exc.getMessage()); // NOI18N
                        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
                    }
                }
            }
        );
    }
}
 
Example 12
Source Project: netbeans   Source File: EditServletAction.java    License: Apache License 2.0 6 votes vote down vote up
protected void performAction (final Node[] activatedNodes) {
    for (int i = 0; i < activatedNodes.length; i++) {
        JspDataObject jspdo = (JspDataObject)activatedNodes[i].getCookie(JspDataObject.class);
        if (jspdo != null) {
            jspdo.refreshPlugin(true);
            EditorCookie cook = jspdo.getServletEditor();
            if (cook != null)
                cook.open ();
            else {
                //show error dialog
                String msg = NbBundle.getMessage(EditServletAction.class, "ERR_CantEditServlet");
                String title = NbBundle.getMessage(EditServletAction.class, "EditServlet");
                NotifyDescriptor descriptor = new NotifyDescriptor(msg, title,
                        NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE,
                        new Object[]{NotifyDescriptor.OK_OPTION}, null);
                DialogDisplayer.getDefault().notify(descriptor);
            }
        }
    }
}
 
Example 13
Source Project: netbeans   Source File: SelectPathAction.java    License: Apache License 2.0 6 votes vote down vote up
private Node[] getSelectionNodes() {
    if(selectionNodes == null) {
        String[] segments = selectionUrl.getPathSegments();
        Node node = (RepositoryPathNode) browser.getExplorerManager().getRootContext();            
        
        for (int i = 0; i < segments.length; i++) {
            Children children = node.getChildren();    
            node = children.findChild(segments[i]);
            if(node==null) {
                break;
            }                    
        }            
        if(node == null) {
            selectionNodes = EMPTY_NODES;
        } else {
            selectionNodes = new Node[] {node};    
        }            
    }
    return selectionNodes;
}
 
Example 14
Source Project: netbeans   Source File: CustomizeActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testEnable() { 
    CustomizeAction action = new CustomizeAction();
    Node customizable = new AbstractNode(Children.LEAF) {
        public @Override boolean hasCustomizer() {
            return true;
        }
    };
    Node not = new AbstractNode(Children.LEAF);
    assertFalse(action.enable(null));
    assertFalse(action.enable(new Node[0]));
    assertTrue(action.enable(new Node[] {customizable}));
    assertFalse(action.enable(new Node[] {not}));
    assertFalse(action.enable(new Node[] {customizable, customizable}));
}
 
Example 15
Source Project: netbeans   Source File: WildflyEarApplicationNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isRunning() {
    boolean running = getChildren().getNodes().length > 0;
    for (Node node : getChildren().getNodes()) {
        if (node instanceof WildflyWebModuleNode) {
            running = running && ((WildflyWebModuleNode) node).isRunning();
        }
    }
    return running;
}
 
Example 16
Source Project: netbeans   Source File: DummyWindowManager.java    License: Apache License 2.0 5 votes vote down vote up
synchronized void setActivatedNodes(TopComponent tc, Node[] _nodes) {
    if (tc == getActive()) {
        if (_nodes != null) {
            nodes = _nodes;

            if (pcs != null) {
                pcs.firePropertyChange(PROP_ACTIVATED_NODES, null, null);
            }
        }

        if (pcs != null) {
            pcs.firePropertyChange(PROP_CURRENT_NODES, null, null);
        }
    }
}
 
Example 17
Source Project: netbeans   Source File: FixActionProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the project that the active node's fileobject belongs to. 
 * If this cannot be determined for some reason, returns the main project.
 *  
 * @return the project that the active node's fileobject belongs to
 */ 
private Project getCurrentProject() {
    Node[] nodes = TopComponent.getRegistry ().getActivatedNodes ();
    if (nodes == null || nodes.length == 0) {
        return MainProjectManager.getDefault().getMainProject();
    }
    DataObject dao = (DataObject) nodes[0].getLookup().lookup(DataObject.class);
    if (dao == null || !dao.isValid()) {
        return MainProjectManager.getDefault().getMainProject();
    }
    return FileOwnerQuery.getOwner(dao.getPrimaryFile());        
}
 
Example 18
Source Project: netbeans   Source File: ContextLogAction.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean enable(Node[] nodes) {
    for (int i = 0; i < nodes.length; i++) {
        TomcatWebModuleCookie cookie = (TomcatWebModuleCookie)nodes[i].getCookie(TomcatWebModuleCookie.class);
        if (cookie == null || !cookie.hasLogger()) {
            return false;
        }
    }         
    return true;
}
 
Example 19
Source Project: netbeans   Source File: ExplorerManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    em = new ExplorerManager();
    keys = new Keys();
    root = new AbstractNode(keys);
    Node[] justAsk = root.getChildren().getNodes(true);
    em.setRootContext(root);
    events = new LinkedList<PropertyChangeEvent>();
}
 
Example 20
Source Project: netbeans   Source File: CookieActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public NodeWithDefaultLookup() {
    super(Children.LEAF);
    getCookieSet().add(OpenCookie.class, new CookieSet.Factory() {
        public Node.Cookie createCookie(Class clazz) {
            if(clazz.isAssignableFrom(OpenCookie.class)) {
                synchronized(NodeWithDefaultLookup.this) {
                    NodeWithDefaultLookup.this.cookieCreated = true;
                }
                return new Open();
            }
            return null;
        }
    });
}
 
Example 21
Source Project: netbeans   Source File: FormDesigner.java    License: Apache License 2.0 5 votes vote down vote up
void setSelectedNodes(Node... nodes) {
        try {
//            if (formEditor == null) {
//                // Lazy synchronization of already closed form - issue 129877
//                return;
//            }
//            FormDataObject fdo = formEditor.getFormDataObject();
//            if (!fdo.isValid()) {
//                return; // Issue 130637
//            }
            explorerManager.setSelectedNodes(nodes);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(getClass().getName()).log(Level.INFO, ex.getMessage(), ex);
        }
    }
 
Example 22
Source Project: netbeans   Source File: SwitchToBranchAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void performContextAction(Node[] nodes) {
    final VCSContext ctx = HgUtils.getCurrentContext(nodes);
    final File roots[] = HgUtils.getActionRoots(ctx);
    if (roots == null || roots.length == 0) return;
    final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);

    final BranchSelector switchBranch = new BranchSelector(root);
    JCheckBox forcedUpdateChxBox = new JCheckBox();
    org.openide.awt.Mnemonics.setLocalizedText(forcedUpdateChxBox, org.openide.util.NbBundle.getMessage(SwitchToBranchAction.class, "SwitchTo.forcedUpdateChxBox.text")); // NOI18N
    JPanel optionsPanel = new JPanel(new BorderLayout());
    optionsPanel.add(forcedUpdateChxBox, BorderLayout.NORTH);
    optionsPanel.setBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0));
    switchBranch.setOptionsPanel(optionsPanel, null);
    
    JButton okButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(BranchSelector.class, "CTL_SwitchToForm_Action_SwitchTo")); // NOI18N
    okButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSD_SwitchToForm_Action_SwitchTo")); // NOI18N
    okButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSN_SwitchToForm_Action_SwitchTo")); // NOI18N
    okButton.setEnabled(false);
    
    if (!switchBranch.showDialog(okButton, org.openide.util.NbBundle.getMessage(BranchSelector.class, "CTL_SwitchToDialog", root.getName()), //NOI18N
            org.openide.util.NbBundle.getMessage(SwitchToBranchAction.class, "SwitchToPanel.infoLabel.text"))) { //NOI18N
        return;
    }
    final String revStr = switchBranch.getBranchName();
    if (revStr == null) {
        return;
    }
    final boolean doForcedUpdate = forcedUpdateChxBox.isSelected();
    doSwitch(root, revStr, doForcedUpdate, ctx); //NOI18N
}
 
Example 23
Source Project: netbeans   Source File: JavaDataSupport.java    License: 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 24
Source Project: netbeans   Source File: AbstractSearchResultsPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void shift(int direction) {

        Node next = findShiftNode(direction, getOutlineView(), true);
        if (next != null) {
            try {
                getExplorerManager().setSelectedNodes(new Node[]{next});
                onDetailShift(next);
            } catch (PropertyVetoException pve) {
                Exceptions.printStackTrace(pve);
            }
        }
    }
 
Example 25
Source Project: netbeans   Source File: YardaTest.java    License: Apache License 2.0 5 votes vote down vote up
private void doColeasingSimulation (int type) throws Exception {
    ArrayList l = new ArrayList ();
    CompoundModel1 cm1 = new CompoundModel1 ();
    l.add (cm1);
    OutlineTable tt = BasicTest.createView(Models.createCompoundModel (l));
    Node n = tt.getExplorerManager ().
        getRootContext ();
    synchronized (cm1) {
        n.getChildren ().getNodes ();
        cm1.wait (1000);
        if (cm1.count > 1) {
            cm1.stackTraces.toString();
        }
        assertEquals ("Model caled", 1, cm1.count);
        cm1.fire (new ModelEvent.TreeChanged(cm1.getRoot()));
        n.getChildren ().getNodes ();
        
        if (type == 1) {
            cm1.fire (new ModelEvent.TreeChanged(cm1.getRoot()));
            n.getChildren ().getNodes ();
        }
        
        cm1.notifyAll ();
    }
    Thread.yield();
    Thread.sleep(1000);
    tt.currentTreeModelRoot.getRootNode().getRequestProcessor().post (new Runnable () {
        public void run () {}
    }).waitFinished ();
    //System.err.println("Child = "+n.getChildren().getNodes()[0]);
    // TODO: Broken, there's a Please wait... node!
    assertEquals ("Computation has finished in RP", 3, n.getChildren ().getNodes ().length);
    if (cm1.count > 2) {
        cm1.stackTraces.toString();
    }
    assertEquals ("Model caled", 2, cm1.count);
}
 
Example 26
Source Project: netbeans   Source File: Hk2ResourceContainers.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected org.openide.nodes.Node[] createNodes(Object key) {
    if (key instanceof Hk2ItemNode){
        return new Node [] { (Hk2ItemNode) key };
    }

    if (key instanceof String && key.equals(WAIT_NODE)){
        return new Node [] { WAIT_NODE };
    }

    return null;
}
 
Example 27
Source Project: NBANDROID-V2   Source File: AdbConnectionNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable(Node[] activatedNodes) {
    if (activatedNodes.length != 1) {
        return false;
    }
    return true;
}
 
Example 28
Source Project: netbeans   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void revert(final Node[] nodes) {
    for(Node node : nodes) {
        StoreEntry se =  node.getLookup().lookup(StoreEntry.class);
        if(se != null) {
            Utils.revert(se);
        }
    }
}
 
Example 29
Source Project: netbeans   Source File: Nodes.java    License: Apache License 2.0 5 votes vote down vote up
private static Node locateChild(Node parent, LogicalViewProvider lvp, FileObject file) {
    if (lvp != null) {
        return lvp.findPath(parent, file);
    }
    
    throw new UnsupportedOperationException("Not done yet");
}
 
Example 30
Source Project: netbeans   Source File: AnnotateAction.java    License: Apache License 2.0 5 votes vote down vote up
private File activatedFile(Node[] nodes) {
    if (nodes.length == 1) {
        Node node = nodes[0];
        DataObject dobj = (DataObject) node.getCookie(DataObject.class);
        if (dobj != null) {
            FileObject fo = dobj.getPrimaryFile();
            return FileUtil.toFile(fo);
        }
    }
    return null;
}