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

The following examples show how to use org.openide.nodes.Node#equals() . 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: TableView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Synchronize the selected nodes from the manager of this Explorer.
 */
final void synchronizeSelectedNodes() {
    Node[] arr = manager.getSelectedNodes ();
    table.getSelectionModel().clearSelection();
    NodeTableModel ntm = (NodeTableModel)table.getModel();
    int size = ntm.getRowCount();
    int firstSelection = -1;
    for (int i = 0; i < size; i++) {
        Node n = getNodeFromRow(i);
        for (int j = 0; j < arr.length; j++) {
            if (n.equals(arr[j])) {
                table.getSelectionModel().addSelectionInterval(i, i);
                if (firstSelection == -1) {
                    firstSelection = i;
                }
            }
        }
    }
    if (firstSelection >= 0) {
        Rectangle rect = table.getCellRect(firstSelection, 0, true);
        if (!getViewport().getViewRect().contains(rect.getLocation())) {
            rect.height = Math.max(rect.height, getHeight() - 30);
            table.scrollRectToVisible(rect);
        }
    }
}
 
Example 2
Source File: PropertiesDataNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void createPasteTypes(Transferable transferable,
                             List<PasteType> types) {
    super.createPasteTypes(transferable, types);

    Element.ItemElem item;
    Node node = NodeTransfer.node(transferable, NodeTransfer.MOVE);
    if (node != null && node.canDestroy()) {
        item = node.getCookie(Element.ItemElem.class);
        if (item == null) {
            return;
        }
        Node itemNode = getChildren().findChild(item.getKey());
        if (node.equals(itemNode)) {
            return;
        }
        types.add(new EntryPasteType(item, node));
    } else {
        item = NodeTransfer.cookie(transferable, 
                                   NodeTransfer.COPY,
                                   Element.ItemElem.class);
        if (item != null) {
            types.add(new EntryPasteType(item, null));
        }
    }
}
 
Example 3
Source File: TableViewDropSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Can node recieve given drop action? */

    // XXX canditate for more general support
    private boolean canDrop(Node n, int dropAction) {
        if (n == null) {
            return false;
        }

        if (ExplorerDnDManager.getDefault().getNodeAllowedActions() == DnDConstants.ACTION_NONE) {
            return false;
        }

        // test if a parent of the dragged nodes isn't the node over
        // only for MOVE action
        if ((DnDConstants.ACTION_MOVE & dropAction) != 0) {
            Node[] nodes = ExplorerDnDManager.getDefault().getDraggedNodes();
            if (nodes != null) {
                for (int i = 0; i < nodes.length; i++) {
                    if (n.equals(nodes[i].getParentNode())) {
                        return false;
                    }
                }
            }
        }

        Transferable trans = ExplorerDnDManager.getDefault().getDraggedTransferable(
                (DnDConstants.ACTION_MOVE & dropAction) != 0
            );

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

        // get paste types for given transferred transferable
        PasteType pt = null; //TODO DragDropUtilities.getDropType(n, trans, dropAction);

        return (pt != null);
    }
 
Example 4
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int rowForNode(Node node) {
    for (int i = 0; i < nodeRows.length; i++) {
        if (node.equals(nodeRows[i])) {
            return i;
        }
    }

    return -1;
}
 
Example 5
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 6
Source File: NodeTableModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private int rowForNode(Node node) {
    for (int i = 0; i < nodeRows.length; i++) {
        if (node.equals(nodeRows[i])) {
            return i;
        }
    }

    return -1;
}
 
Example 7
Source File: ResultPanelTree.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isSelected(TestMethodNode testMethod, Node selected) {
   if (testMethod.equals(selected)) {
       return true;
   }
   for (Node node : testMethod.getChildren().getNodes()) {
       if (node.equals(selected)) {
           return true;
       }
   }
   return false;
}
 
Example 8
Source File: FileObjectSearchGroup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Tests if the node has parent. Helper method. */
private static boolean hasParent(Node node, Node[] nodes) {
    for (Node parent = node.getParentNode(); parent != null; parent = parent.getParentNode()) {
        for (Node n : nodes) {
            if (n.equals(parent)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: TreeViewDropSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Can node recieve given drop action? */

    // XXX canditate for more general support
    private boolean canDrop(Node n, int dropAction, Transferable dndEventTransferable) {
        if (n == null) {
            return false;
        }

        // Test to see if the target node supports the drop action
        if ((view.getAllowedDropActions() & dropAction) == 0) {
            return false;
        }

        // test if a parent of the dragged nodes isn't the node over
        // only for MOVE action
        if ((DnDConstants.ACTION_MOVE & dropAction) != 0) {
            Node[] nodes = ExplorerDnDManager.getDefault().getDraggedNodes();

            if (nodes != null) {
                for (int i = 0; i < nodes.length; i++) {
                    if (n.equals(nodes[i].getParentNode())) {
                        return false;
                    }
                }
            }
        }

        Transferable trans = ExplorerDnDManager.getDefault().getDraggedTransferable(
                (DnDConstants.ACTION_MOVE & dropAction) != 0
            );

        if (trans == null) {
            trans = dndEventTransferable;
            if( null == trans ) {
                return false;
            }
        }

        // get paste types for given transferred transferable
        PasteType pt = DragDropUtilities.getDropType(n, trans, dropAction, dropIndex);

        return (pt != null);
    }
 
Example 10
Source File: OutlineViewDropSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Can node recieve given drop action? */

    // XXX canditate for more general support
    private boolean canDrop(Node n, int dropAction, Transferable dndEventTransferable) {
        if (LOGABLE) {
            log("canDrop " + n); // NOI18N
        }
        if (n == null) {
            return false;
        }

        // Test to see if the target node supports the drop action
        if ((view.getAllowedDropActions(dndEventTransferable) & dropAction) == 0) {
            return false;
        }

        // test if a parent of the dragged nodes isn't the node over
        // only for MOVE action
        if ((DnDConstants.ACTION_MOVE & dropAction) != 0) {
            Node[] nodes = ExplorerDnDManager.getDefault().getDraggedNodes();

            if (nodes != null) {
                for (int i = 0; i < nodes.length; i++) {
                    if (n.equals(nodes[i].getParentNode())) {
                        return false;
                    }
                }
            }
        }

        Transferable trans = ExplorerDnDManager.getDefault().getDraggedTransferable(
                (DnDConstants.ACTION_MOVE & dropAction) != 0
            );
        if (LOGABLE) {
            log("transferable == " + trans); // NOI18N
        }
        if (trans == null) {
            trans = dndEventTransferable;
            if( null == trans ) {
                return false;
            }
        }

        // get paste types for given transferred transferable
        PasteType pt =  DragDropUtilities.getDropType(n, trans, dropAction, dropIndex);

        return (pt != null);
    }
 
Example 11
Source File: ListViewDropSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Can node recieve given drop action? */

    // XXX canditate for more general support
    private boolean canDrop(Node n, int dropAction, Transferable dndEventTransferable, int dropIndex) {
        if (n == null) {
            return false;
        }

        if (ExplorerDnDManager.getDefault().getNodeAllowedActions() == DnDConstants.ACTION_NONE) {
            return false;
        }

        // test if a parent of the dragged nodes isn't the node over
        // only for MOVE action
        if ((DnDConstants.ACTION_MOVE & dropAction) != 0) {
            Node[] nodes = ExplorerDnDManager.getDefault().getDraggedNodes();

            if( null != nodes ) {
                for (int i = 0; i < nodes.length; i++) {
                    if (n.equals(nodes[i].getParentNode())) {
                        return false;
                    }
                }
            }
        }

        Transferable trans = ExplorerDnDManager.getDefault().getDraggedTransferable(
                (DnDConstants.ACTION_MOVE & dropAction) != 0
            );

        if (trans == null) {
            trans = dndEventTransferable;
            if( trans == null ) {
                return false;
            }
        }

        // get paste types for given transferred transferable
        PasteType pt = DragDropUtilities.getDropType(n, trans, dropAction, dropIndex);

        return (pt != null);
    }
 
Example 12
Source File: ConnectionSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Attaches new node to listen to events produced by this
* event. The type must be one of event types supported by this
* cookie and the listener should have ConnectionCookie.Listener cookie
* attached so it can be notified when event of requested type occurs.
*
* @param type the type of event, must be supported by the cookie
* @param listener the node that should be notified
*
* @exception InvalidObjectException if the type is not supported by the cookie (subclass of IOException)
* @exception IOException if the type is persistent and the listener does not
*    have serializable handle (listener.getHandle () is null or its serialization
*    throws an exception)
*/
public synchronized void register (ConnectionCookie.Type type, Node listener) throws IOException {
    // test if the file is supported, if not throws exception
    testSupported (type);

    boolean persistent = type.isPersistent ();
    LinkedList<Pair> list;

    if (persistent) {
        list = (LinkedList<Pair>)entry.getFile ().getAttribute (EA_LISTENERS);
    } else {
        list = listeners;
    }

    if (list == null) {
        // empty list => create new
        list = new LinkedList<Pair> ();
    }

    //    System.out.println("======================================== ADD:"+entry.getFile().getName()); // NOI18N
    //    System.out.println(this);
    //    System.out.println("size:"+list.size()); // NOI18N

    Iterator<Pair> it = list.iterator ();
    while (it.hasNext ()) {
        Pair pair = it.next ();
        //      System.out.println("test:"+pair.getType()); // NOI18N
        if (type.equals (pair.getType ())) {
            Node n;
            try {
                n = pair.getNode ();
                //          System.out.println("  node:"+n); // NOI18N
            } catch (IOException e) {
                // node that cannot produce handle => remove it
                Logger.getLogger(ConnectionSupport.class.getName()).log(Level.WARNING, null, e);
                it.remove ();
                // go on
                continue;
            }
            //        System.out.println("  compare with:"+listener); // NOI18N
            if (n.equals (listener)) {
                // we found our node - it is already in the list.
                //          System.out.println("the listener found - remove it."); // NOI18N
                it.remove();
                continue;
            }
            else {
                //          System.out.println("  nene"); // NOI18N
            }
        }
    }
    list.add (persistent ? new Pair (type, listener.getHandle ()) : new Pair (type, listener));

    //    System.out.println("after add:"+list.size()); // NOI18N

    if (persistent) {
        // save can throw IOException
        entry.getFile ().setAttribute (EA_LISTENERS, list);
    }

}
 
Example 13
Source File: ConnectionSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Unregisters an listener.
* @param type type of event to unregister the listener from listening to
* @param listener to unregister
* @exception IOException if there is I/O operation error when the removing
*   the listener from persistent storage
*/
public synchronized void unregister (ConnectionCookie.Type type, Node listener) throws IOException {
    // test if the file is supported, if not throws exception
    testSupported (type);

    boolean persistent = type.isPersistent ();
    LinkedList list;

    if (persistent) {
        list = (LinkedList)entry.getFile ().getAttribute (EA_LISTENERS);
    } else {
        list = listeners;
    }

    if (list == null) {
        // empty list => no work
        return;
    }

    //    System.out.println("======================================== REMOVE:"+entry.getFile().getName()); // NOI18N
    //    System.out.println(this);
    //  System.out.println("size:"+list.size()); // NOI18N

    Iterator it = list.iterator ();
    while (it.hasNext ()) {
        Pair pair = (Pair)it.next ();

        if (type.equals (pair.getType ())) {
            Node n;
            try {
                n = pair.getNode ();
            } catch (IOException e) {
                // node that cannot produce handle => remove it
                it.remove ();
                // go on
                continue;
            }
            if (n.equals (listener)) {
                // we found our node
                it.remove ();
                // break the cycle but save if necessary

                continue;
            }
        }
    }

    //System.out.println("after remove:"+list.size()); // NOI18N

    if (persistent) {
        // save can throw IOException
        entry.getFile ().setAttribute (EA_LISTENERS, list);
    }
}
 
Example 14
Source File: LookupNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Overridden, returns LookupNode filters of original nodes.
*
* @param node node to create copy of
* @return LookupNode filter of the original node
*/
@Override
protected Node[] createNodes(Node node) {
    DataObject obj = (DataObject)node.getCookie(DataObject.class);
    //System.err.println("obj="+obj+" node="+node+" hidden="+(obj==null?null:obj.getPrimaryFile ().getAttribute (EA_HIDDEN)));
    
    if (
        obj != null && Boolean.TRUE.equals (obj.getPrimaryFile ().getAttribute (EA_HIDDEN))
    ) {
        return new Node[0];
    }
    
    LookupNode parent = (LookupNode)getNode ();
    
    if (obj != null) {
        if (obj instanceof DataFolder && node.equals (obj.getNodeDelegate ())) {
            node = parent.createChild ((DataFolder)obj);
            return new Node[] { node };
        } else if (obj instanceof DataShadow) {
            DataObject orig = ((DataShadow) obj).getOriginal();
            FileObject fo = orig.getPrimaryFile();
            
            // if folder referenced by shadow is empty do not show it
            if (fo.isFolder() && !fo.getChildren(false).hasMoreElements()) return null;
            
            if (orig instanceof DataFolder) {
                return new Node[] { 
                    parent.createChild ((DataFolder) orig)
                };
            } else {
                obj = orig;
                node = orig.getNodeDelegate();
            }
        }
        node = new Leaf(node, obj, parent);
    }
    
    node = parent.createChild (node);

    return new Node[] { node };
}
 
Example 15
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);
    }
}
 
Example 16
Source File: DragAndDropHandler.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Perform the drop operation and add the dragged item into the given category.
 *
 * @param targetCategory Lookup of the category that accepts the drop.
 * @param item Transferable holding the item being dragged.
 * @param dndAction Drag'n'drop action type.
 * @param dropIndex Zero-based position where the dragged item should be dropped.
 *
 * @return True if the drop has been successful, false otherwise.
 */
public boolean doDrop( Lookup targetCategory, Transferable item, int dndAction, int dropIndex ) {
    Node categoryNode = (Node)targetCategory.lookup( Node.class );
    try {
        //first check if we're reordering items within the same category
        if( item.isDataFlavorSupported( PaletteController.ITEM_DATA_FLAVOR ) ) {
            Lookup itemLookup = (Lookup)item.getTransferData( PaletteController.ITEM_DATA_FLAVOR );
            if( null != itemLookup ) {
                Node itemNode = (Node)itemLookup.lookup( Node.class );
                if( null != itemNode ) {
                    Index order = (Index)categoryNode.getCookie( Index.class );
                    if( null != order && order.indexOf( itemNode ) >= 0 ) {
                        //the drop item comes from the targetCategory so let's 
                        //just change the order of items
                        return moveItem( targetCategory, itemLookup, dropIndex );
                    }
                }
            }
        }
        PasteType paste = categoryNode.getDropType( item, dndAction, dropIndex );
        if( null != paste ) {
            Node[] itemsBefore = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
            paste.paste();
            Node[] itemsAfter = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
            
            if( itemsAfter.length == itemsBefore.length+1 ) {
                int currentIndex = -1;
                Node newItem = null;
                for( int i=itemsAfter.length-1; i>=0; i-- ) {
                    newItem = itemsAfter[i];
                    currentIndex = i;
                    for( int j=0; j<itemsBefore.length; j++ ) {
                        if( newItem.equals( itemsBefore[j] ) ) {
                            newItem = null;
                            break;
                        }
                    }
                    if( null != newItem ) {
                        break;
                    }
                }
                if( null != newItem && dropIndex >= 0 ) {
                    if( currentIndex < dropIndex )
                        dropIndex++;
                    moveItem( targetCategory, newItem.getLookup(), dropIndex );
                }
            }
            return true;
        }
        if( isTextDnDEnabled && null != DataFlavor.selectBestTextFlavor(item.getTransferDataFlavors()) ) {
            importTextIntoPalette( targetCategory, item, dropIndex );
            return false; //return false to retain the original dragged text in its source
        }
    } catch( IOException ioE ) {
        Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, ioE );
    } catch( UnsupportedFlavorException e ) {
        Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, e );
    }
    return false;
}