KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > categorized > DummySchemaNode


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 /*
21  * DummySchemaNode.java
22  *
23  * Created on April 12, 2006, 2:41 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.ui.nodes.categorized;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.Collections JavaDoc;
34 import org.openide.nodes.FilterNode;
35 import org.openide.nodes.Node;
36
37 /**
38  *
39  * @author Ajit Bhate
40  */

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