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.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 ; 37 import java.util.List ; 38 import java.awt.*; 39 import java.beans.BeanInfo ; 40 41 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"); } 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"); } 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"); } 75 if (img == null) { 76 img = super.getIcon(type); 77 } 78 return img; 79 } 80 81 static class AliasesChildren extends Children.Keys implements Runnable { 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 key) { 107 if (key instanceof Node) { 108 return new Node[] {(Node)key}; 109 } 110 111 Node alias = AliasNode.create((ModuleListInformation)key); return new Node[] {alias}; 113 } 114 115 public void run() { 116 try { 117 List 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 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 name = alias.getModuleName(); 138 Lookup lookup = Lookups.singleton(name); 139 AliasNode node = new AliasNode(Children.LEAF, lookup); 140 node.setName(name); 141 String 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"); } 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"); } 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"); } 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); return Utilities.mergeImages(image, badge, 0, 8); 176 } 177 } 178 } 179 | Popular Tags |