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

The following examples show how to use org.openide.nodes.Node#removeNodeListener() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: PropertySheet.java    License: Apache License 2.0 6 votes vote down vote up
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
Source Project: netbeans   File: NodeOperationImpl.java    License: Apache License 2.0 6 votes vote down vote up
/** 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
Source Project: netbeans   File: CookieAction.java    License: Apache License 2.0 5 votes vote down vote up
/** 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
Source Project: netbeans   File: CookieAction.java    License: Apache License 2.0 5 votes vote down vote up
/** 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
Source Project: netbeans   File: NbMainExplorer.java    License: Apache License 2.0 5 votes vote down vote up
/** 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
Source Project: netbeans   File: Tab.java    License: Apache License 2.0 5 votes vote down vote up
/** 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
private void removeChildAdditionListener(Node removedNode) {
    for (Node n : removedNode.getChildren().getNodes(true)) {
        removeChildAdditionListener(n);
    }
    removedNode.removeNodeListener(resultsNodeAdditionListener);
}
 
Example 8
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]);
}