2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.versioning.system.cvss.ui.selectors;
44
import org.openide.nodes.AbstractNode;
45
import org.openide.nodes.Children;
46
import org.openide.nodes.Node;
47
import org.openide.util.Lookup;
48
import org.openide.util.RequestProcessor;
49
import org.openide.util.lookup.Lookups;
50
import org.netbeans.lib.cvsclient.CVSRoot;
51
import org.netbeans.lib.cvsclient.Client;
52
import org.netbeans.lib.cvsclient.connection.AuthenticationException;
53
import org.netbeans.lib.cvsclient.command.CommandException;
56
import java.util.Collections;
57
import java.util.List;
59
import java.beans.BeanInfo;
62
* Represents a path in repository, its children
65
* <p>Lookup contains a string identifing rpresented path.
69
public class RepositoryPathNode extends AbstractNode {
71
public static RepositoryPathNode create(Client.Factory clientFactory, CVSRoot root, String path) {
73
assert path.startsWith("/") == false : path; // NOI18N
75
RepositoryPathChildren kids = new RepositoryPathChildren(clientFactory, root, path);
76
Lookup lookup = Lookups.singleton(path);
77
RepositoryPathNode node = new RepositoryPathNode(kids, lookup);
79
String name = root.getRepository();
80
if (path.equals("") == false) { // NOI18N
81
String[] atoms = path.split("/"); // NOI18N
82
if (atoms.length > 0) {
83
name = atoms[atoms.length -1];
86
node.setDisplayName(name);
90
private RepositoryPathNode(Children children, Lookup lookup) {
91
super(children, lookup);
92
setIconBaseWithExtension("org/netbeans/modules/versioning/system/cvss/ui/selectors/defaultFolder.gif"); // NOI18N
95
public Image getIcon(int type) {
97
if (type == BeanInfo.ICON_COLOR_16x16) {
98
img = (Image)UIManager.get("Nb.Explorer.Folder.icon"); // NOI18N
101
img = super.getIcon(type);
106
public Image getOpenedIcon(int type) {
108
if (type == BeanInfo.ICON_COLOR_16x16) {
109
img = (Image)UIManager.get("Nb.Explorer.Folder.openedIcon"); // NOI18N
112
img = super.getIcon(type);
117
static class RepositoryPathChildren extends Children.Keys implements Runnable {
119
private final Client.Factory clientFactory;
120
private final CVSRoot root;
121
private final String path;
122
private RequestProcessor.Task task;
124
public RepositoryPathChildren(Client.Factory client, CVSRoot root, String path) {
125
this.clientFactory = client;
130
protected void addNotify() {
132
AbstractNode waitNode = new WaitNode(org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "BK2024"));
133
setKeys(Collections.singleton(waitNode));
134
RequestProcessor rp = RequestProcessor.getDefault();
135
task = rp.post(this);
138
protected void removeNotify() {
140
setKeys(Collections.EMPTY_SET);
141
super.removeNotify();
144
protected Node[] createNodes(Object key) {
145
if (key instanceof Node) {
146
return new Node[] {(Node)key};
149
String relPath = path.equals("") ? (String) key : path + "/" + key; // NOI18N
150
Node pathNode = RepositoryPathNode.create(clientFactory, root, relPath);
151
return new Node[] {pathNode};
156
List keys = ModuleSelector.listRepositoryPath(clientFactory.createClient(), root, path);
158
} catch (CommandException e) {
159
setKeys(Collections.singleton(errorNode(e)));
160
} catch (AuthenticationException e) {
161
setKeys(Collections.singleton(errorNode(e)));
165
private Node errorNode(Exception ex) {
166
AbstractNode errorNode = new AbstractNode(Children.LEAF);
167
errorNode.setDisplayName(org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "BK2025"));
168
errorNode.setShortDescription(ex.getLocalizedMessage());