org.openide.nodes.NodeAdapter Java Examples

The following examples show how to use org.openide.nodes.NodeAdapter. 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: FormEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void registerNodeListener() {
    if (formDataObject.isValid()) {
        Node node = formDataObject.getNodeDelegate();
        multiviewTC.setIcon(node.getIcon(BeanInfo.ICON_COLOR_16x16));
        if (nodeListener == null) {
            NodeListener listener = new NodeAdapter() {
                @Override
                public void propertyChange(final PropertyChangeEvent ev) {
                    Mutex.EVENT.writeAccess(new Runnable() {
                        @Override
                        public void run() {
                            if (Node.PROP_ICON.equals(ev.getPropertyName())) {
                                if (formDataObject.isValid() && (multiviewTC != null)) {
                                    multiviewTC.setIcon(formDataObject.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16));
                                }
                            }
                        }
                    });
                }
            };
            node.addNodeListener(org.openide.nodes.NodeOp.weakNodeListener(listener, node));
            nodeListener = listener;
        }
    }
}
 
Example #2
Source File: GraphNode.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private GraphNode(InputGraph graph, InstanceContent content) {
    super(Children.LEAF, new AbstractLookup(content));
    this.graph = graph;
    this.setDisplayName(graph.getName());
    content.add(graph);

    final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);

    if (viewer != null) {
        // Action for opening the graph
        content.add(new GraphOpenCookie(viewer, graph));
    }

    // Action for removing a graph
    content.add(new GraphRemoveCookie(graph));

    // Action for diffing to the current graph
    content.add(new DiffGraphCookie(graph));

    // Action for cloning to the current graph
    content.add(new GraphCloneCookie(viewer, graph));

    this.addNodeListener(new NodeAdapter() {
        @Override
        public void childrenRemoved(NodeMemberEvent ev) {
            GraphNode.this.graph = null;
        }
    });
}
 
Example #3
Source File: FolderChildrenTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** #175220 - Tests that children keys are not changed when node and underlying
 * data object are garbage collected. It caused collapsing of tree.
 */
public void testNodeKeysNotChanged() throws Exception {
    LOG.info("testNodeKeysNotChanged starting");
    FileObject rootFolder = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo1 = rootFolder.createData("file1.java");
    assertNotNull(fo1);
    FileObject fo2 = rootFolder.createData("file2.java");
    DataObject do2 = DataObject.find(fo2);
    assertNotNull(fo2);
    Node folderNode = DataFolder.findFolder(rootFolder).getNodeDelegate();
    LOG.log(Level.INFO, "testNodeKeysNotChanged folderNode: {0}", folderNode);
    final AtomicInteger removedEventCount = new AtomicInteger(0);
    folderNode.addNodeListener(new NodeAdapter() {

        @Override
        public void childrenRemoved(NodeMemberEvent ev) {
            removedEventCount.incrementAndGet();
            LOG.log(Level.INFO, "testNodeKeysNotChanged childrenRemoved: {0}", ev);
        }
    });
    LOG.info("testNodeKeysNotChanged addNodeListener");

    // refresh children
    LOG.info("testNodeKeysNotChanged about to getNodes");
    folderNode.getChildren().getNodes(true);
    Node childNode1 = folderNode.getChildren().getNodeAt(0);
    LOG.log(Level.INFO, "testNodeKeysNotChanged child0{0}", childNode1);
    assertNotNull(childNode1);
    Node childNode2 = folderNode.getChildren().getNodeAt(1);
    LOG.log(Level.INFO, "testNodeKeysNotChanged child1{0}", childNode2);
    assertNotNull(childNode2);

    // GC node 2
    WeakReference<Node> ref = new WeakReference<Node>(childNode2);
    childNode2 = null;
    assertGC("Cannot GC childNode2", ref);
    // GC data object 2
    WeakReference<DataObject> refDO = new WeakReference<DataObject>(do2);
    do2 = null;
    assertGC("Cannot GC do2", refDO);

    // add new data object
    FileObject fo3 = rootFolder.createData("file3.java");
    assertNotNull(fo3);
    LOG.log(Level.INFO, "testNodeKeysNotChanged fo3: {0}", fo3);
    // refresh children
    folderNode.getChildren().getNodes(true);
    LOG.info("after get children");
    Node childNodeX = folderNode.getChildren().getNodeAt(1);
    LOG.log(Level.INFO, "childeNodeX: {0}", childNodeX);
    assertNotSame("Node 2 should not be the same when GC'd before.", childNode2, childNodeX);
    assertEquals("No node should be removed.", 0, removedEventCount.intValue());
    LOG.info("done");
}
 
Example #4
Source File: DataFolderTimeOrderTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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]);
}