KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > DummyDefinitionsNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import org.openide.nodes.FilterNode;
26 import org.openide.nodes.Node;
27
28 /**
29  * A proxy, of sorts, which appears in the columns view to make the root
30  * node visible in the first column of the view.
31  *
32  * @author Ajit Bhate
33  * @author Nathan Fiedler
34  */

35 public class DummyDefinitionsNode extends FilterNode implements Node.Cookie {
36
37     public DummyDefinitionsNode(Node original) {
38         this(original, new Children(original));
39     }
40
41     private DummyDefinitionsNode(Node original,
42             org.openide.nodes.Children children) {
43         super(original, children);
44     }
45
46     private static class Children extends FilterNode.Children {
47
48         public Children(Node original) {
49             super(original);
50         }
51
52         @Override JavaDoc
53         protected void removeNotify() {
54             setKeys((Collection JavaDoc)Collections.emptyList());
55         }
56
57         @Override JavaDoc
58         protected void addNotify() {
59             setKeys(createKeys());
60         }
61
62         private ArrayList JavaDoc<Node> createKeys() {
63             ArrayList JavaDoc<Node> keys = new ArrayList JavaDoc<Node>();
64             keys.add(new DummyInnerSchemaNode(original));
65             Node[] children = original.getChildren().getNodes();
66             for (Node child : children) {
67                 if (child.getCookie(FolderNode.class) != null) {
68                     keys.add(child);
69                 }
70             }
71             return keys;
72         }
73     }
74
75     public static class DummyInnerSchemaNode extends DummyDefinitionsNode {
76
77         public DummyInnerSchemaNode(final Node original) {
78             super(original, new FilterNode.Children(original) {
79                 @Override JavaDoc
80                 protected Node[] createNodes(Node n) {
81                     if (n.getCookie(FolderNode.class) != null) {
82                         return new Node[] {};
83                     }
84                     return super.createNodes(n);
85                 }
86             });
87         }
88     }
89 }
90
Popular Tags