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

The following examples show how to use org.openide.nodes.Node#getParentNode() . 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: AbstractJUnitTestCreatorProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean hasParentAmongNodes(final Node[] nodes,
                                           final int idx) {
    Node node;

    node = nodes[idx].getParentNode();
    while (null != node) {
        for (int i = 0; i < nodes.length; i++) {
            if (i == idx) {
                continue;
            }
            if (node == nodes[i]) {
                return true;
            }
        }
        node = node.getParentNode();
    }
    return false;
}
 
Example 2
Source File: BreadCrumbComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<Node> computeNodePath() {
    ExplorerManager manager = findManager();
    List<Node> path = new ArrayList<Node>();
    Node sel = manager.getExploredContext();

    // see #223480; root context need not be the root of the node structure.
    Node stopAt = manager.getRootContext().getParentNode();
    while (sel != null && sel != stopAt) {
        path.add(sel);
        sel = sel.getParentNode();
    }

    path.remove(path.size() - 1); //XXX

    Collections.reverse(path);
    
    return path;
}
 
Example 3
Source File: ExplorerActionsImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Adds all parent nodes into the set.
 * @param set set of all nodes
 * @param node the node to check
 * @return false if one of the nodes is parent of another
 */
private boolean checkParents(Node node, HashMap<Node, Object> set) {
    if (set.get(node) != null) {
        return false;
    }

    // this signals that this node is the original one
    set.put(node, this);

    for (;;) {
        node = node.getParentNode();

        if (node == null) {
            return true;
        }

        if (set.put(node, node) == this) {
            // our parent is a node that is also in the set
            return false;
        }
    }
}
 
Example 4
Source File: Nodes.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isParent(Node parent, Node child) {
    if (NodeOp.isSon(parent, child)) {
        return true;
    }

    Node p = child.getParentNode();

    if (p == null) {
        return false;
    }

    return isParent(parent, p);
}
 
Example 5
Source File: JaxWsCodeGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void addProjectReference(Node serviceNode, DataObject dObj) {
    Node clientNode = serviceNode.getParentNode();
    FileObject srcRoot = clientNode.getLookup().lookup(FileObject.class);
    Project clientProject = FileOwnerQuery.getOwner(srcRoot);
    if (dObj != null) {
        FileObject targetFo = dObj.getPrimaryFile();
        JaxWsUtils.addProjectReference(clientProject, targetFo);
    }
}
 
Example 6
Source File: RESTResourcesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String getSaasResourceName(Node node) {
    WadlSaasResource saasResource = node.getLookup().lookup(WadlSaasResource.class);

    String resourceName = saasResource.getResource().getPath();
    if (resourceName.startsWith("/")) { //NOI18N
        resourceName = resourceName.substring(1);
    }

    Node saasNode = node.getParentNode();
    while (saasNode != null && saasNode.getLookup().lookup(WadlSaas.class) == null) {
        saasResource = saasNode.getLookup().lookup(WadlSaasResource.class);
        if (saasResource != null) {
            String path = saasResource.getResource().getPath();
            if (path.startsWith("/")) {
                path = path.substring(1);
            }
            if (path.endsWith("/")) {
                path = path.substring(0, path.length()-1);
            }
            if (path.length() > 0) {
                resourceName = path+"/"+resourceName;
            }
        } else {
            resourceName = saasNode.getDisplayName()+"/"+resourceName;
        }
        saasNode = saasNode.getParentNode();
    }
    if (saasNode != null) {
        resourceName = saasNode.getDisplayName()+" ["+resourceName+"]"; //NOI18N
    }
    return resourceName;
}
 
Example 7
Source File: RefreshAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    for (Node node : activatedNodes) {
        Node parentNode = node.getParentNode();
        if (parentNode instanceof KnockoutNode) {
            // We have to refresh the parent to refresh the value stored in some node
            ((KnockoutNode)parentNode).refresh();
        } else {
            ((KnockoutNode)node).refresh();
        }
    }
}
 
Example 8
Source File: Nodes.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isParent(Node parent, Node child) {
    if (NodeOp.isSon(parent, child)) {
        return true;
    }

    Node p = child.getParentNode();

    if (p == null) {
        return false;
    }

    return isParent(parent, p);
}
 
Example 9
Source File: ResultPanelTree.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TestsuiteNode getSelectedSuite(Node selected) {
    if (selected instanceof TestMethodNode) {
        return (TestsuiteNode) selected.getParentNode();
    } else if (selected instanceof TestsuiteNode) {
        return (TestsuiteNode) selected;
    } else if (selected instanceof CallstackFrameNode) {
        return (TestsuiteNode) selected.getParentNode().getParentNode();
    }
    return getFirstFailedSuite();
}
 
Example 10
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static DataObject createDuplicateFromNode (Node n) {
    DataObject source = getDOFromNode (n);
    try {
        Node parent = n.getParentNode ();
        DataObject target = source.copy(source.getFolder());
        FileObject srcFo = source.getPrimaryFile();
        FileObject targetFo = target.getPrimaryFile();
        setTemplateAttributes(targetFo, srcFo);
        if (parent != null) {
            Node duplicateNode = null;
            for (Node k : parent.getChildren ().getNodes (true)) {
                if (k.getName ().startsWith (targetFo.getName ())) {
                    duplicateNode = k;
                    break;
                }
            }
            if (duplicateNode != null) {
                final Node finalNode = duplicateNode;
                SwingUtilities.invokeLater (new Runnable () {
                    @Override public void run() {
                        try {
                            manager.setSelectedNodes (new Node [] { finalNode });
                            view.invokeInplaceEditing ();
                        } catch (PropertyVetoException ex) {
                            Logger.getLogger (TemplatesPanel.class.getName ()).log (Level.INFO, ex.getLocalizedMessage (), ex);
                        }
                    }
                });
            }
        }
        return target;
    } catch (IOException ioe) {
        Logger.getLogger(TemplatesPanel.class.getName()).log(Level.WARNING, null, ioe);
    }
    return null;
}
 
Example 11
Source File: MotionsDB.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void closeMotion(Model model, Storage simmMotionData, boolean confirmCloseIfModified, boolean allowCancel) {
   // Prompt user to confirm the close and possibly save the motion if it has been modified.
   if (confirmCloseIfModified && getMotionModified(simmMotionData)) {
      if (!confirmCloseMotion(model, simmMotionData, allowCancel))
         return;
   }

   ArrayList<Storage> motions = mapModels2Motions.get(model);
   if(motions!=null) { // Shouldn't be null, but just in case...
      motions.remove(simmMotionData);
   }

   // Remove from mapMotion2BitSet
   mapMotion2BitSet.remove(simmMotionData);

   boolean removed = removeFromCurrentMotions(new ModelMotionPair(model, simmMotionData));
   Node motionNode = getMotionNode(model, simmMotionData);
   Node parentOrTopMotionsNode = null;
   if(motionNode!=null) {
        parentOrTopMotionsNode = motionNode.getParentNode();
        // get displayer for parnet motion and remove evnt.getMotion() from associated motions
        if (motionNode instanceof OneAssociatedMotionNode){
            Storage parentMotion = ((OneMotionNode) parentOrTopMotionsNode).getMotion();
            MotionDisplayer currentDisplayer = getDisplayerForMotion(simmMotionData);
            currentDisplayer.cleanupDisplay();
            getDisplayerForMotion(parentMotion).getAssociatedMotions().remove(currentDisplayer);
        }
   }
   MotionEvent evt = new MotionEvent(this, model, simmMotionData, MotionEvent.Operation.Close);
   setChanged();
   notifyObservers(evt);
   removeMotionDisplayer(simmMotionData);

   if(removed) {
      evt = new MotionEvent(this, MotionEvent.Operation.CurrentMotionsChanged);
      setChanged();
      notifyObservers(evt);
   }
}
 
Example 12
Source File: TreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Checks whether given Node is a subnode of rootContext.
* @return true if specified Node is under current rootContext
*/
private boolean isUnderRoot(Node rootContext, Node node) {
    while (node != null) {
        if (node.equals(rootContext)) {
            return true;
        }

        node = node.getParentNode();
    }

    return false;
}
 
Example 13
Source File: ListView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void valueChanged(ListSelectionEvent e) {
    int curSize = model.getSize();
    int[] indices = list.getSelectedIndices();

    // bugfix #24193, check if the nodes in selection are in the view's root context
    List<Node> ll = new ArrayList<Node>(indices.length);

    for (int i = 0; i < indices.length; i++) {
        if (indices[i] < curSize) {
            Node n = Visualizer.findNode(model.getElementAt(indices[i]));

            if ((n == manager.getRootContext()) || (n.getParentNode() != null)) {
                ll.add(n);
            }
        } else {
            // something went wrong?
            updateSelection();

            return;
        }
    }

    Node[] nodes = ll.toArray(new Node[ll.size()]);

    // forwarding TO E.M., so we won't listen to its cries for a while
    manager.removePropertyChangeListener(wlpc);
    manager.removeVetoableChangeListener(wlvc);

    try {
        selectionChanged(nodes, manager);
    } catch (PropertyVetoException ex) {
        // selection vetoed - restore previous selection
        updateSelection();
    } finally {
        manager.addPropertyChangeListener(wlpc);
        manager.addVetoableChangeListener(wlvc);
    }
}
 
Example 14
Source File: Browser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int getNodeLevel(Node node) {
    int level = 0;
    while(node!=null) {
        node = node.getParentNode();
        level++;
    }
    return level;
}
 
Example 15
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 16
Source File: NamedBeanGroupNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected NamedBeanGroupNode getParentGroupNode() {
    NamedBeanGroupNode parentGroupNode = null;
    Node parentNode = getParentNode();
    // Hack to bypass the references group node, but then this entire method is a hack.
    if(parentNode instanceof ReferencesNode) {
        parentNode = parentNode.getParentNode();
    }
    if(parentNode instanceof NamedBeanNode) {
        parentNode = parentNode.getParentNode();
        if(parentNode instanceof NamedBeanGroupNode) {
            parentGroupNode = (NamedBeanGroupNode) parentNode;
        }
    }
    return parentGroupNode;
}
 
Example 17
Source File: JaxWsCodeGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void doInsertMethod(final Document document, final int pos, 
        OperationNode operationNode) 
{
    Node portNode = operationNode.getParentNode();
    Node serviceNode = portNode.getParentNode();
    Node wsdlNode = serviceNode.getParentNode();
    WsdlOperation operation = operationNode.getLookup().lookup(WsdlOperation.class);
    WsdlPort port = portNode.getLookup().lookup(WsdlPort.class);
    WsdlService service = serviceNode.getLookup().lookup(WsdlService.class);
    Client client = wsdlNode.getLookup().lookup(Client.class);
    JaxWsClientNode wsClientNode = wsdlNode.getLookup().lookup( JaxWsClientNode.class );
    FileObject srcRoot = wsdlNode.getLookup().lookup(FileObject.class);
    
    JAXWSClientSupport clientSupport = JAXWSClientSupport.getJaxWsClientSupport(srcRoot);
    FileObject wsdlFileObject = null;
    
    FileObject localWsdlocalFolder = clientSupport.getLocalWsdlFolderForClient(
            client.getName(),false);
    if (localWsdlocalFolder!=null) {
        String relativePath = client.getLocalWsdlFile();
        if (relativePath != null) {
            wsdlFileObject=localWsdlocalFolder.getFileObject(relativePath);
        }
    }
    
    FileObject documentFileObject = NbEditorUtilities.getFileObject(document);
    String wsdlUrl = findWsdlLocation(client, documentFileObject);
    
    Project targetProject = FileOwnerQuery.getOwner(documentFileObject);

    Map<String,Object> context = (Map<String,Object>)wsClientNode.getValue(
            JaxWsClientNode.CONTEXT);
    if ( context == null ){
        context = new HashMap<String, Object>();
        wsClientNode.setValue(JaxWsClientNode.CONTEXT, context);
    }

    insertMethod(client , document, pos, service, port, operation, 
            wsdlFileObject, wsdlUrl, context, targetProject );
}
 
Example 18
Source File: TreeModelNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
Integer getTreeDepth() {
    Node p = getNode();
    if (p == null) {
        return 0;
    } else if (depth != null) {
        return depth;
    } else {
        int d = 1;
        while ((p = p.getParentNode()) != null) d++;
        depth = new Integer(d);
        return depth;
    }
}
 
Example 19
Source File: TreeView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Check if selection of the nodes could break the selection mode set in TreeSelectionModel.
 * @param nodes the nodes for selection
 * @return true if the selection mode is broken */
private boolean isSelectionModeBroken(Node[] nodes) {
    // if nodes are empty or single the everthing is ok
    // or if discontiguous selection then everthing ok
    if ((nodes.length <= 1) || (getSelectionMode() == TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION)) {
        return false;
    }

    // if many nodes
    // brakes single selection mode
    if (getSelectionMode() == TreeSelectionModel.SINGLE_TREE_SELECTION) {
        return true;
    }

    // check the contiguous selection mode
    TreePath[] paths = new TreePath[nodes.length];
    RowMapper rowMapper = tree.getSelectionModel().getRowMapper();

    // if rowMapper is null then tree bahaves as discontiguous selection mode is set
    if (rowMapper == null) {
        return false;
    }

    ArrayList<Node> toBeExpaned = new ArrayList<Node>(3);

    for (int i = 0; i < nodes.length; i++) {
        toBeExpaned.clear();

        Node n = nodes[i];

        while (n.getParentNode() != null) {
            if (!isExpanded(n)) {
                toBeExpaned.add(n);
            }

            n = n.getParentNode();
        }

        for (int j = toBeExpaned.size() - 1; j >= 0; j--) {
            expandNode(toBeExpaned.get(j));
        }
        paths[i] = getTreePath(nodes[i]);
    }

    int[] rows = rowMapper.getRowsForPaths(paths);

    // check selection's rows
    Arrays.sort(rows);

    for (int i = 1; i < rows.length; i++) {
        if (rows[i] != (rows[i - 1] + 1)) {
            return true;
        }
    }

    // all is ok
    return false;
}
 
Example 20
Source File: ProjectTab.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void performChange(Node [] selectedNodes) {
    String text = "";
    Node projectNode = null;
    if( selectedNodes != null && selectedNodes.length > 0 ) {
        Node selectedNode = selectedNodes[0];
        Node originallySelectedNode = selectedNodes[0];
        Node rootNode = ProjectTab.this.manager.getRootContext();
        while ( selectedNode.getParentNode() != null && !selectedNode.getParentNode().equals(rootNode)) {
            selectedNode = selectedNode.getParentNode();
        }
        projectNode = selectedNode;
        //Tests whether other selected items have same project owner
        if( selectedNodes.length > 1 ) {
            for ( int i = 1; i < selectedNodes.length; i ++) {
                selectedNode = selectedNodes[i];                        
                while ( !selectedNode.getParentNode().equals(rootNode) ) {
                    selectedNode = selectedNode.getParentNode();
                }
                if ( !projectNode.equals(selectedNode) ) {
                    projectNode = null;
                    text = Bundle.MSG_nodes_from_more_projects();
                    break;
                }
            }
        }
        if ( projectNode != null ) {
            ProjectTab.this.btv.showOrHideNodeSelectionProjectPanel(projectNode, originallySelectedNode);
            text = projectNode.getDisplayName();
        }
    } else {
        text = Bundle.MSG_none_node_selected();
    }
    if ( this.actualProjectLabel != null ) {
        this.actualProjectLabel.setText(text);
        setSelectionLabelProperties(projectNode);
    } else {
        this.actualProjectLabel = new JLabel(text);
        setSelectionLabelProperties(projectNode);
        this.selectionsProjectPanel.add(actualProjectLabel);
    }
}