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

The following are Jave code examples for showing how to use removeNodeListener() 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: PropertySheet.java   Source Code and License Vote up 6 votes
public Node detach() {
    Node n = currNode;

    if (n != null) {
        if (PropUtils.isLoggable(PropertySheet.class)) {
            PropUtils.log(PropertySheet.class, "Detaching listeners from " + n);
        }

        n.removePropertyChangeListener(inner);
        n.removeNodeListener(this);

        //clear the reference
        currNode = null;
    }

    return n;
}
 
Example 2
Project: incubator-netbeans   File: NodeOperationImpl.java   Source Code and License Vote up 6 votes
/** Fired when the node is deleted.
 * @param ev event describing the node
 */
@Override
public void nodeDestroyed(NodeEvent ev) {
    Node destroyedNode = ev.getNode();
    // stop to listen to destroyed node
    destroyedNode.removeNodeListener(this);
    listenerSet.remove(destroyedNode);
    // close top component (our outer class) if last node was destroyed
    if (listenerSet.isEmpty()) {
        // #68943 - stop to listen, as we are waving goodbye :-)
        tc.removePropertyChangeListener(this);
        Mutex.EVENT.readAccess(new Runnable() {
            @Override
            public void run() {
                if (dialog != null) {
                    dialog.setVisible(false);
                    dialog.dispose();
                    dialog = null;
                }
            }
        });
    }
}
 
Example 3
Project: incubator-netbeans   File: CookieAction.java   Source Code and License Vote up 5 votes
/** Removes itself as a listener from given nodes */
void detachListeners(List<Reference<Node>> nodes) {
    if (nodes == null) {
        return;
    }
    Iterator<Reference<Node>> it = nodes.iterator();

    while (it.hasNext()) {
        Node node = it.next().get();

        if (node != null) {
            node.removeNodeListener(listener);
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: CookieAction.java   Source Code and License Vote up 5 votes
/** Removes itself as a listener from given nodes */
private void detachListeners(List<Reference<Node>> nodes) {
    if (nodes != null) {
        Iterator<Reference<Node>> it = nodes.iterator();

        while (it.hasNext()) {
            Node node = it.next().get();

            if (node != null) {
                node.removeNodeListener(listener);
            }
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: NbMainExplorer.java   Source Code and License Vote up 5 votes
/** Sets new root context to view. Name, icon, tooltip
* of this top component will be updated properly */
public void setRootContext (Node rc) {
    Node oldRC = getExplorerManager().getRootContext();
    // remove old listener, if possible
    if (weakRcL != null) {
        oldRC.removePropertyChangeListener(weakRcL);
    }
    if (weakNRcL != null) {
        oldRC.removeNodeListener(weakNRcL);
    }
    getExplorerManager().setRootContext(rc);
}
 
Example 6
Project: incubator-netbeans   File: Tab.java   Source Code and License Vote up 5 votes
/** Sets new root context to view. Name,  tooltip
* of this top component will be updated properly */
public void setRootContext (Node rc) {
    Node oldRC = getExplorerManager().getRootContext();
    // remove old listener, if possible
    if (weakRcL != null) {
        oldRC.removePropertyChangeListener(weakRcL);
    }
    if (weakNRcL != null) {
        oldRC.removeNodeListener(weakNRcL);
    }
    getExplorerManager().setRootContext(rc);
    initializeWithRootContext(rc);
}
 
Example 7
Project: incubator-netbeans   File: BasicAbstractResultsPanel.java   Source Code and License Vote up 4 votes
private void removeChildAdditionListener(Node removedNode) {
    for (Node n : removedNode.getChildren().getNodes(true)) {
        removeChildAdditionListener(n);
    }
    removedNode.removeNodeListener(resultsNodeAdditionListener);
}
 
Example 8
Project: incubator-netbeans   File: DataFolderTimeOrderTest.java   Source Code and License Vote up 4 votes
public void testLastModifiedOrderUpdatedAfterFileIsTouched() throws Exception {
    aa.setSortMode(DataFolder.SortMode.LAST_MODIFIED);

    Node n = aa.getNodeDelegate().cloneNode();
    Node[] nodes = n.getChildren().getNodes(true);
    assertEquals ("Two nodes", 2, nodes.length);

    waitEvents();
    assertEquals("Sort mode not changed and children not refreshed: " + events, 2, events.size());
    assertTrue(DataFolder.PROP_SORT_MODE + " change not fired", events.contains(DataFolder.PROP_SORT_MODE));
    assertTrue(DataFolder.PROP_CHILDREN + " change not fired", events.contains(DataFolder.PROP_CHILDREN));
    assertEquals("Y.txt", nodes[0].getName()); // Y is newer
    assertEquals("X.txt", nodes[1].getName()); // X is older
    events.clear();

    final FileObject orig = lfs.findResource("AA/Y.txt");
    final FileObject touch = lfs.findResource("AA/X.txt");

    // After touching, X.txt will be newer than Y.txt.
    TestFileUtils.touch(FileUtil.toFile(touch), FileUtil.toFile(orig));
    // It's not enough to wait only for DataFolder event
    // because of number of RP tasks run before node children are updated
    // must wait for reorder fired by node itself.
    final CountDownLatch barrier = new CountDownLatch(1);
    NodeListener nodeList = new NodeAdapter() {

        @Override
        public void childrenReordered (NodeReorderEvent ev) {
            barrier.countDown();
        }
      
    };
    n.addNodeListener(nodeList);
    try {
        touch.refresh();
        waitEvents();
        // wait for node reorder event
        barrier.await(10, TimeUnit.SECONDS);
    } finally {
        n.removeNodeListener(nodeList);
    }
    assertEquals(0, barrier.getCount());
    assertTrue(DataFolder.PROP_CHILDREN + " change not fired", events.contains(DataFolder.PROP_CHILDREN));

    Node[] newNodes = n.getChildren().getNodes(true);
    assertEquals("Node " + nodes[1].getName() + " expected first.", newNodes[0], nodes[1]);
    assertEquals("Node " + nodes[0].getName() + " expected second.", newNodes[1], nodes[0]);
}