1 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.lookup.Lookups; 28 import org.netbeans.lib.cvsclient.CVSRoot; 29 import org.netbeans.lib.cvsclient.Client; 30 import org.netbeans.lib.cvsclient.connection.AuthenticationException; 31 import org.netbeans.lib.cvsclient.command.CommandException; 32 33 import javax.swing.*; 34 import java.util.Collections ; 35 import java.util.List ; 36 import java.awt.*; 37 import java.beans.BeanInfo ; 38 39 47 public class RepositoryPathNode extends AbstractNode { 48 49 public static RepositoryPathNode create(Client.Factory clientFactory, CVSRoot root, String path) { 50 51 assert path.startsWith("/") == false : path; 53 RepositoryPathChildren kids = new RepositoryPathChildren(clientFactory, root, path); 54 Lookup lookup = Lookups.singleton(path); 55 RepositoryPathNode node = new RepositoryPathNode(kids, lookup); 56 57 String name = root.getRepository(); 58 if (path.equals("") == false) { String [] atoms = path.split("/"); if (atoms.length > 0) { 61 name = atoms[atoms.length -1]; 62 } 63 } 64 node.setDisplayName(name); 65 return node; 66 } 67 68 private RepositoryPathNode(Children children, Lookup lookup) { 69 super(children, lookup); 70 setIconBaseWithExtension("org/netbeans/modules/versioning/system/cvss/ui/selectors/defaultFolder.gif"); } 72 73 public Image getIcon(int type) { 74 Image img = null; 75 if (type == BeanInfo.ICON_COLOR_16x16) { 76 img = (Image)UIManager.get("Nb.Explorer.Folder.icon"); } 78 if (img == null) { 79 img = super.getIcon(type); 80 } 81 return img; 82 } 83 84 public Image getOpenedIcon(int type) { 85 Image img = null; 86 if (type == BeanInfo.ICON_COLOR_16x16) { 87 img = (Image)UIManager.get("Nb.Explorer.Folder.openedIcon"); } 89 if (img == null) { 90 img = super.getIcon(type); 91 } 92 return img; 93 } 94 95 static class RepositoryPathChildren extends Children.Keys implements Runnable { 96 97 private final Client.Factory clientFactory; 98 private final CVSRoot root; 99 private final String path; 100 private RequestProcessor.Task task; 101 102 public RepositoryPathChildren(Client.Factory client, CVSRoot root, String path) { 103 this.clientFactory = client; 104 this.root = root; 105 this.path = path; 106 } 107 108 protected void addNotify() { 109 super.addNotify(); 110 AbstractNode waitNode = new WaitNode(org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "BK2024")); 111 setKeys(Collections.singleton(waitNode)); 112 RequestProcessor rp = RequestProcessor.getDefault(); 113 task = rp.post(this); 114 } 115 116 protected void removeNotify() { 117 task.cancel(); 118 setKeys(Collections.EMPTY_SET); 119 super.removeNotify(); 120 } 121 122 protected Node[] createNodes(Object key) { 123 if (key instanceof Node) { 124 return new Node[] {(Node)key}; 125 } 126 127 String relPath = path.equals("") ? (String ) key : path + "/" + key; Node pathNode = RepositoryPathNode.create(clientFactory, root, relPath); 129 return new Node[] {pathNode}; 130 } 131 132 public void run() { 133 try { 134 List keys = ModuleSelector.listRepositoryPath(clientFactory.createClient(), root, path); 135 setKeys(keys); 136 } catch (CommandException e) { 137 setKeys(Collections.singleton(errorNode(e))); 138 } catch (AuthenticationException e) { 139 setKeys(Collections.singleton(errorNode(e))); 140 } 141 } 142 143 private Node errorNode(Exception ex) { 144 AbstractNode errorNode = new AbstractNode(Children.LEAF); 145 errorNode.setDisplayName(org.openide.util.NbBundle.getMessage(RepositoryPathNode.class, "BK2025")); 146 errorNode.setShortDescription(ex.getLocalizedMessage()); 147 return errorNode; 148 } 149 } 150 151 } 152 | Popular Tags |