KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbstractNode;
23 import org.openide.nodes.Children;
24 import org.openide.nodes.Node;
25 import org.openide.util.Lookup;
26 import org.openide.util.RequestProcessor;
27 import org.openide.util.Utilities;
28 import org.openide.util.lookup.Lookups;
29 import org.netbeans.lib.cvsclient.Client;
30 import org.netbeans.lib.cvsclient.CVSRoot;
31 import org.netbeans.lib.cvsclient.connection.AuthenticationException;
32 import org.netbeans.lib.cvsclient.command.CommandException;
33 import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation;
34
35 import javax.swing.*;
36 import java.util.Collections JavaDoc;
37 import java.util.List JavaDoc;
38 import java.awt.*;
39 import java.beans.BeanInfo JavaDoc;
40
41 /**
42  * Represents module aliases subtree.
43  *
44  * @author Petr Kuzel
45  */

46 final class AliasesNode extends AbstractNode {
47
48     public static AliasesNode create(Client.Factory client, CVSRoot root) {
49         AliasesNode node = new AliasesNode(new AliasesChildren(client, root));
50         node.setDisplayName(org.openide.util.NbBundle.getMessage(AliasesNode.class, "BK2005"));
51         return node;
52     }
53
54     private AliasesNode(Children children) {
55         super(children);
56         setIconBaseWithExtension("org/netbeans/modules/versioning/system/cvss/ui/selectors/defaultFolder.gif"); // NOI18N
57
}
58
59     public Image getIcon(int type) {
60         Image img = null;
61         if (type == BeanInfo.ICON_COLOR_16x16) {
62             img = (Image)UIManager.get("Nb.Explorer.Folder.icon"); // NOI18N
63
}
64         if (img == null) {
65             img = super.getIcon(type);
66         }
67         return img;
68     }
69
70     public Image getOpenedIcon(int type) {
71         Image img = null;
72         if (type == BeanInfo.ICON_COLOR_16x16) {
73             img = (Image)UIManager.get("Nb.Explorer.Folder.openedIcon"); // NOI18N
74
}
75         if (img == null) {
76             img = super.getIcon(type);
77         }
78         return img;
79     }
80
81     static class AliasesChildren extends Children.Keys implements Runnable JavaDoc {
82
83         private final Client.Factory clientFactory;
84         private final CVSRoot root;
85         private RequestProcessor.Task task;
86
87         public AliasesChildren(Client.Factory client, CVSRoot root) {
88             this.clientFactory = client;
89             this.root = root;
90         }
91
92         protected void addNotify() {
93             super.addNotify();
94             AbstractNode waitNode = new WaitNode(org.openide.util.NbBundle.getMessage(AliasesNode.class, "BK2006"));
95             setKeys(Collections.singleton(waitNode));
96             RequestProcessor rp = RequestProcessor.getDefault();
97             task = rp.post(this);
98         }
99
100         protected void removeNotify() {
101             task.cancel();
102             setKeys(Collections.EMPTY_SET);
103             super.removeNotify();
104         }
105
106         protected Node[] createNodes(Object JavaDoc key) {
107             if (key instanceof Node) {
108                 return new Node[] {(Node)key};
109             }
110
111             Node alias = AliasNode.create((ModuleListInformation)key); // NOI18N
112
return new Node[] {alias};
113         }
114
115         public void run() {
116             try {
117                 List JavaDoc aliases = ModuleSelector.listAliases(clientFactory.createClient(), root);
118                 setKeys(aliases);
119             } catch (CommandException e) {
120                 setKeys(Collections.singleton(errorNode(e)));
121             } catch (AuthenticationException e) {
122                 setKeys(Collections.singleton(errorNode(e)));
123             }
124         }
125
126         private Node errorNode(Exception JavaDoc ex) {
127             AbstractNode errorNode = new AbstractNode(Children.LEAF);
128             errorNode.setDisplayName(org.openide.util.NbBundle.getMessage(AliasesNode.class, "BK2007"));
129             errorNode.setShortDescription(ex.getLocalizedMessage());
130             return errorNode;
131         }
132     }
133
134     static class AliasNode extends AbstractNode {
135
136         public static AliasNode create(ModuleListInformation alias) {
137             String JavaDoc name = alias.getModuleName();
138             Lookup lookup = Lookups.singleton(name);
139             AliasNode node = new AliasNode(Children.LEAF, lookup);
140             node.setName(name);
141             String JavaDoc paths = alias.getPaths();
142             node.setShortDescription(paths);
143             return node;
144         }
145
146         private AliasNode(Children children, Lookup lookup) {
147             super(children, lookup);
148             setIconBaseWithExtension("org/netbeans/modules/versioning/system/cvss/ui/selectors/defaultFolder.gif"); // NOI18N
149
}
150
151         public Image getIcon(int type) {
152             Image img = null;
153             if (type == BeanInfo.ICON_COLOR_16x16) {
154                 img = (Image)UIManager.get("Nb.Explorer.Folder.icon"); // NOI18N
155
}
156             if (img == null) {
157                 img = super.getIcon(type);
158             }
159             return badge(img);
160         }
161
162         public Image getOpenedIcon(int type) {
163             Image img = null;
164             if (type == BeanInfo.ICON_COLOR_16x16) {
165                 img = (Image)UIManager.get("Nb.Explorer.Folder.openedIcon"); // NOI18N
166
}
167             if (img == null) {
168                 img = super.getIcon(type);
169             }
170             return badge(img);
171         }
172
173         private Image badge(Image image) {
174             Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/ui/selectors/link.png", true); // NOI18N
175
return Utilities.mergeImages(image, badge, 0, 8);
176         }
177     }
178 }
179
Popular Tags