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

The following are Jave code examples for showing how to use equals() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: TableView.java   Source Code and License Vote up 6 votes
/** 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
Project: incubator-netbeans   File: PropertiesDataNode.java   Source Code and License Vote up 6 votes
@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
Project: incubator-netbeans   File: TableViewDropSupport.java   Source Code and License Vote up 5 votes
/** 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
Project: incubator-netbeans   File: NodeTableModel.java   Source Code and License Vote up 5 votes
private int rowForNode(Node node) {
    for (int i = 0; i < nodeRows.length; i++) {
        if (node.equals(nodeRows[i])) {
            return i;
        }
    }

    return -1;
}
 
Example 5
Project: incubator-netbeans   File: TreeView.java   Source Code and License Vote up 5 votes
/** 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
Project: incubator-netbeans   File: NodeTableModel.java   Source Code and License Vote up 5 votes
private int rowForNode(Node node) {
    for (int i = 0; i < nodeRows.length; i++) {
        if (node.equals(nodeRows[i])) {
            return i;
        }
    }

    return -1;
}
 
Example 7
Project: incubator-netbeans   File: ResultPanelTree.java   Source Code and License Vote up 5 votes
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
Project: incubator-netbeans   File: FileObjectSearchGroup.java   Source Code and License Vote up 5 votes
/** 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
Project: incubator-netbeans   File: TreeViewDropSupport.java   Source Code and License Vote up 4 votes
/** 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
Project: incubator-netbeans   File: OutlineViewDropSupport.java   Source Code and License Vote up 4 votes
/** 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
Project: incubator-netbeans   File: ListViewDropSupport.java   Source Code and License Vote up 4 votes
/** 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
Project: incubator-netbeans   File: ProjectTab.java   Source Code and License Vote up 4 votes
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 13
Project: incubator-netbeans   File: DragAndDropHandler.java   Source Code and License Vote up 4 votes
/**
 * 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;
}
 
Example 14
Project: incubator-netbeans   File: ConnectionSupport.java   Source Code and License Vote up 4 votes
/** 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 15
Project: incubator-netbeans   File: ConnectionSupport.java   Source Code and License Vote up 4 votes
/** 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 16
Project: incubator-netbeans   File: LookupNode.java   Source Code and License Vote up 4 votes
/** 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 };
}