KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > selectors > BranchNodeChildren


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.selectors;
21
22 import org.openide.nodes.Children;
23 import org.openide.nodes.Node;
24 import org.openide.nodes.AbstractNode;
25 import org.openide.util.lookup.Lookups;
26
27 import java.util.Collection JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 /**
33  * Defines Tags and Branches node structure. Nodes representing
34  * tag or branch have <code>String</code> it their lookups.
35  *
36  * @author Petr Kuzel
37  */

38 final class BranchNodeChildren extends Children.Keys {
39
40     private final Node headNode = new AbstractNode(Children.LEAF, Lookups.singleton("HEAD")); // NOI18N
41
private final SymbolicNamesNode branchesNode = SymbolicNamesNode.create(org.openide.util.NbBundle.getMessage(BranchNodeChildren.class, "BK2008"));
42     private final SymbolicNamesNode tagsNode = SymbolicNamesNode.create(org.openide.util.NbBundle.getMessage(BranchNodeChildren.class, "BK2009"));
43
44     /**
45      * Sets discovered branch names. Until called
46      * a wait node is presented.
47      */

48     public void setBranches(Collection JavaDoc branches) {
49         branchesNode.setNames(branches);
50     }
51
52     /**
53      * Sets discovered tag names. Until called
54      * a wait node is presented.
55      */

56     public void setTags(Collection JavaDoc tags) {
57        tagsNode.setNames(tags);
58     }
59
60     protected void addNotify() {
61         List JavaDoc nodes = new ArrayList JavaDoc(3);
62         headNode.setName("HEAD"); // NOI18N
63
nodes.add(headNode);
64         nodes.add(branchesNode);
65         nodes.add(tagsNode);
66         setKeys(nodes);
67     }
68
69     protected void removeNotify() {
70         setKeys(Collections.EMPTY_SET);
71     }
72
73     protected Node[] createNodes(Object JavaDoc key) {
74         return new Node[]{ (Node) key};
75     }
76
77     private static final class SymbolicNamesNode extends AbstractNode {
78
79         public static SymbolicNamesNode create(String JavaDoc displayName) {
80             Children kids = new SNChildren();
81             SymbolicNamesNode node = new SymbolicNamesNode(kids);
82             node.setName(displayName);
83             return node;
84         }
85
86         public void setNames(Collection JavaDoc names) {
87             SNChildren kids = (SNChildren) getChildren();
88             kids.setNames(names);
89         }
90
91         private SymbolicNamesNode(Children children) {
92             super(children);
93         }
94
95         private static class SNChildren extends Children.Keys {
96
97             private SNChildren() {
98                 AbstractNode waitNode = new AbstractNode(Children.LEAF);
99                 waitNode.setDisplayName(org.openide.util.NbBundle.getMessage(BranchNodeChildren.class, "BK2010"));
100                 setKeys(Collections.singleton(waitNode));
101             }
102
103             public void setNames(Collection JavaDoc names) {
104                 if (names.size() == 0) {
105                     AbstractNode waitNode = new AbstractNode(Children.LEAF);
106                     waitNode.setDisplayName(org.openide.util.NbBundle.getMessage(BranchNodeChildren.class, "BK2011"));
107                     setKeys(Collections.singleton(waitNode));
108                 } else {
109                     setKeys(names);
110                 }
111             }
112
113             protected Node[] createNodes(Object JavaDoc key) {
114                 if (key instanceof Node) {
115                     return new Node[] {(Node) key};
116                 } else {
117                     String JavaDoc name = (String JavaDoc) key;
118                     Node node = new AbstractNode(Children.LEAF, Lookups.singleton(name));
119                     node.setDisplayName(name);
120                     return new Node[] {node};
121                 }
122             }
123         }
124     }
125
126 }
127
Popular Tags