org.openide.nodes.Node Java Examples

The following examples show how to use org.openide.nodes.Node. 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: FavoritesTest.java    From netbeans with 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 #2
Source File: EditServletAction.java    From netbeans with 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 #3
Source File: ViewDataAction.java    From netbeans with 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 #4
Source File: JmeBloomFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #5
Source File: OneFrameNode.java    From opensim-gui with 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 #6
Source File: SelectLayoutAction.java    From netbeans with 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 #7
Source File: BrowseFolders.java    From netbeans with 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 #8
Source File: EventsAction.java    From netbeans with 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 File: SelectPathAction.java    From netbeans with 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 #10
Source File: NewAction.java    From netbeans with 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 #11
Source File: SectionNodePanel.java    From netbeans with 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 #12
Source File: TreeView.java    From netbeans with 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 #13
Source File: PrintAction.java    From netbeans with 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 #14
Source File: CancelIncomingCallAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    EmulatorControlSupport emulatorControl = activatedNodes[0].getLookup().lookup(EmulatorControlSupport.class);
    if (emulatorControl != null) {
        String no = calledNumbers.remove(emulatorControl.getDevice().getSerialNumber());
        if (no != null) {
            emulatorControl.getConsole().cancelCall(no);
        }
    }
}
 
Example #15
Source File: DefaultSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Object getNodeDefaultValue( Node node, String attrName ) {
    Object res = node.getValue( attrName );
    if( null == res ) {
        DataObject dobj = (DataObject)node.getCookie( DataObject.class );
        if( null != dobj ) {
            res = dobj.getPrimaryFile().getAttribute( attrName );
        }
    }
    return res;
}
 
Example #16
Source File: ContextLogAction.java    From netbeans with 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 #17
Source File: CustomizeDriverAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void performAction(Node[] activatedNodes) {
    Lookup lookup = activatedNodes[0].getLookup();
    final DriverNode node = lookup.lookup(DriverNode.class);
    if (node != null) {
        AddDriverDialog.showDialog(node);
    }
}
 
Example #18
Source File: ViewApiDocAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    for (Node node : activatedNodes) {
        try {
            String apiUrl = getApiDocUrl(node);
            URL href = new URL(apiUrl);
            HtmlBrowser.URLDisplayer.getDefault().showURL(href);
        } catch (MalformedURLException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example #19
Source File: AdbConnectionNode.java    From NBANDROID-V2 with 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 #20
Source File: JmeTerrainLodControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Node[] createNodes(Object key) {
    if (key instanceof DistanceLodCalculator) {
        DistanceLodCalculator assetKey = (DistanceLodCalculator) key;
        return new Node[]{new JmeDistanceLodCalculator(control, assetKey, getDataObject())};
    } else if (key instanceof PerspectiveLodCalculator) {
        //PerspectiveLodCalculator assetKey = (PerspectiveLodCalculator) key;
        //return new Node[]{new JmePerspectiveLodCalculator(control, assetKey)};
    }
    return null;
}
 
Example #21
Source File: DisableModulesAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable(Node[] nodes) {
    for(Node node : nodes) {
        DisableModulesCookie cookie = node.getCookie(DisableModulesCookie.class);
        if(cookie == null || cookie.isRunning()) {
            return false;
        }
    }

    return true;
}
 
Example #22
Source File: Nodes.java    From netbeans with 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 #23
Source File: AnnotateAction.java    From netbeans with 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;
}
 
Example #24
Source File: MatchedPropertyNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a sub-node to this node. This method is called on nodes that
 * represent a short-hand property only.
 *
 * @param subNode sub-node that represents a property that belongs under
 * a short-hand property represented by this node.
 */
void addSubNode(MatchedPropertyNode subNode) {
    if (isLeaf()) {
        setChildren(new Children.Array());
    }
    Children.Array children = (Children.Array)getChildren();
    children.add(new Node[] { subNode });
}
 
Example #25
Source File: RootNodeFactory.java    From BART with MIT License 5 votes vote down vote up
@Override
protected Node[] createNodesForKey(String key) {
    if(key.equals(NodeResource.FACTORY_KEY_RootNodeFactory))   {
        Node[] n = {new DatabaseConfigurationNode(dto.getEgtask(),dto),
                    new ConfigurationNode(dto.getEgtask(),dto),
                    new DependenciesNode(dto.getEgtask(),dto),
                    new DirtyStrategiesNode(dto.getEgtask(), dto),
                    new RandomErrorsNode(dto.getEgtask(),dto)
                    };
        return n;
    }else{
        return null;
    }
}
 
Example #26
Source File: MergeDialogComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public synchronized void addMergePanel(MergePanel panel) {
    mergeTabbedPane.addTab(panel.getName(), panel);
    MergeNode node = new MergeNode(panel);
    nodesForPanels.put(panel, node);
    mergeTabbedPane.setSelectedComponent(panel);
    setActivatedNodes(new Node[] { node });
}
 
Example #27
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    Node[] activatedNodes = manager.getSelectedNodes();
    // exactly one node should be selected
    if ((activatedNodes == null) || (activatedNodes.length != 1)) {
        return false;
    }

    return true;
}
 
Example #28
Source File: SetExecutionUriAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable (Node[] activatedNodes) {
    if ((activatedNodes != null) && (activatedNodes.length == 1)) {
        if (activatedNodes[0] != null) {
            DataObject data = (DataObject)activatedNodes[0].getLookup().lookup(DataObject.class);
            if (data != null) {
                FileObject javaClass = data.getPrimaryFile();
                WebModule webModule = WebModule.getWebModule(javaClass);
                if ( servletFilesScanning( webModule, javaClass ) ){
                    return false;
                }
                String mimetype = javaClass.getMIMEType();
                if ( !"text/x-java".equals(mimetype) ){     // NOI18N
                    return false;
                }
                Boolean servletAttr = (Boolean)javaClass.getAttribute(IS_SERVLET_FILE);
                if (!Boolean.TRUE.equals(servletAttr)) {
                    boolean isServletFile = isServletFile(webModule, 
                            javaClass, false );
                    if (isServletFile) {
                        try {
                            javaClass.setAttribute(IS_SERVLET_FILE, Boolean.TRUE); 
                        } catch (java.io.IOException ex) {
                            //we tried
                        }
                    }
                    servletAttr = Boolean.valueOf(isServletFile);
                }
                return Boolean.TRUE.equals(servletAttr);
            }
        }
    }
    return false;
}
 
Example #29
Source File: ElementNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void refreshRecursively() {
    Children ch = getChildren();
    if ( ch instanceof ElementChilren ) {
       ((ElementChilren)ch).resetKeys(description.subs, filters);
       for( Node sub : ch.getNodes() ) {
           ((ElementNode)sub).refreshRecursively();
        }
    }
}
 
Example #30
Source File: ServicesTab.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override Handle getHandle() {
    return new Handle() {
        public @Override Node getNode() throws IOException {
            TopComponent tc = WindowManager.getDefault().findTopComponent(ID);
            if (tc instanceof ServicesTab) {
                return ((ServicesTab) tc).manager.getRootContext();
            } else {
                throw new IOException("no ServicesTab");
            }
        }
    };
}