1 19 20 package org.netbeans.modules.j2ee.deployment.plugins.api; 21 22 import java.awt.Image ; 23 import java.beans.BeanInfo ; 24 import java.util.WeakHashMap ; 25 import javax.swing.Action ; 26 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 27 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 28 import org.netbeans.modules.j2ee.deployment.impl.ui.ServerRegistryNode; 29 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*; 30 import org.openide.filesystems.Repository; 31 import org.openide.loaders.DataFolder; 32 import org.openide.nodes.Node; 33 import org.openide.util.Utilities; 34 import org.openide.windows.IOProvider; 35 import org.openide.windows.InputOutput; 36 37 43 public final class UISupport { 44 45 private static final WeakHashMap ioWeakMap = new WeakHashMap (); 46 47 52 public enum ServerIcon { 53 EJB_ARCHIVE, WAR_ARCHIVE, EAR_ARCHIVE, 54 EJB_FOLDER, EAR_FOLDER, WAR_FOLDER, 55 EJB_OPENED_FOLDER, EAR_OPENED_FOLDER, WAR_OPENED_FOLDER 56 }; 57 58 59 private UISupport() { 60 } 61 62 69 public static Image getIcon(ServerIcon serverIcon) { 70 switch (serverIcon) { 71 case EJB_ARCHIVE : 72 return Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/ejb.png"); case WAR_ARCHIVE : 74 return Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/war.png"); case EAR_ARCHIVE : 76 return Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/ear.png"); default : 78 return computeIcon(serverIcon); 79 } 80 } 81 82 private static Image computeIcon(ServerIcon serverIcon) { 83 Node folderNode = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 85 Image folder; 86 if (serverIcon == ServerIcon.EJB_OPENED_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER 87 || serverIcon == ServerIcon.EAR_OPENED_FOLDER) { 88 folder = folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16); 89 } else { 90 folder = folderNode.getIcon(BeanInfo.ICON_COLOR_16x16); 91 } 92 Image badge; 93 if (serverIcon == ServerIcon.EJB_FOLDER || serverIcon == ServerIcon.EJB_OPENED_FOLDER) { 94 badge = Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/ejbBadge.png"); } else if (serverIcon == ServerIcon.WAR_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER) { 96 badge = Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/warBadge.png"); } else if (serverIcon == ServerIcon.EAR_FOLDER || serverIcon == ServerIcon.EAR_OPENED_FOLDER) { 98 badge = Utilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/earBadge.png" ); } else { 100 return null; 101 } 102 return Utilities.mergeImages(folder, badge, 7, 7); 103 } 104 105 120 public static InputOutput getServerIO(String url) { 121 122 ServerInstance si = ServerRegistry.getInstance().getServerInstance(url); 123 124 if (si == null) { 125 return null; 126 } 127 128 InputOutput io = (InputOutput)ioWeakMap.get(si); 130 if (io != null) { 131 return io; 132 } 133 134 Node node = ServerRegistryNode.getServerRegistryNode().getChildren().findChild(si.getUrl()); 136 137 if (node == null) { 139 return null; 140 } 141 142 Action [] actions = new Action [] { 143 new StartAction.OutputAction(node), 144 new DebugAction.OutputAction(node), 145 new RestartAction.OutputAction(node), 146 new StopAction.OutputAction(node), 147 new RefreshAction.OutputAction(node) 148 }; 149 InputOutput newIO = IOProvider.getDefault().getIO(si.getDisplayName(), actions); 150 151 ioWeakMap.put(si, newIO); 153 return newIO; 154 } 155 } 156 | Popular Tags |