1 19 24 25 package org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes; 26 27 import java.util.Collection ; 28 import javax.enterprise.deploy.spi.DeploymentManager ; 29 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager; 30 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface; 31 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties; 32 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.ShowAdminToolAction; 33 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.ViewLogAction; 34 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Customizer; 35 import org.openide.cookies.InstanceCookie; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.Repository; 38 import org.openide.loaders.DataObject; 39 import org.openide.nodes.AbstractNode; 40 import org.openide.nodes.Children; 41 import org.openide.nodes.Node; 42 import org.openide.util.HelpCtx; 43 import org.openide.util.Lookup; 44 import org.openide.util.NbBundle; 45 import org.openide.util.actions.SystemAction; 46 47 48 49 53 public class ManagerNode extends AbstractNode implements Node.Cookie{ 54 static java.util.Collection bogusNodes = java.util.Arrays.asList(new Node[] { Node.EMPTY, Node.EMPTY }); 55 private SunDeploymentManagerInterface sdm; 56 private DeploymentManager manager; 57 public static final String DIR_ACTION_EXTENSION = "/J2EE/SunAppServer/Actions"; 59 public ManagerNode(DeploymentManager manager) { 60 super(new MyChildren(bogusNodes)); 61 sdm = (SunDeploymentManagerInterface)manager; 62 this.manager = manager; 63 setDisplayName(sdm.getHost()+":"+sdm.getPort()); 64 65 setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/ide/resources/ServerInstanceIcon.png"); setShortDescription(NbBundle.getMessage(ManagerNode.class, "HINT_node")+" "+sdm.getHost()+":"+sdm.getPort() + " "+sdm.getPlatformRoot().getAbsolutePath()); getCookieSet().add(this); 68 getCookieSet().add(sdm); 69 } 70 71 public Node.Cookie getCookie (Class type) { 72 if (ManagerNode.class.isAssignableFrom(type)) { 73 return this; 74 } 75 if (SunDeploymentManagerInterface.class.isAssignableFrom(type)) { 76 return this; 77 } 78 return super.getCookie (type); 79 } 80 81 public boolean hasCustomizer() { 82 return true; 83 } 84 85 public java.awt.Component getCustomizer() { 86 return new Customizer(manager); 87 } 88 89 public javax.swing.Action [] getActions(boolean context) { 90 Repository rep = (Repository) Lookup.getDefault().lookup(Repository.class); 91 FileObject dir = rep.getDefaultFileSystem().findResource(DIR_ACTION_EXTENSION); 92 int nbextraoptions=0; 93 FileObject[] ch =null; 94 if(dir!=null){ 95 ch = dir.getChildren(); 96 nbextraoptions = ch.length; 97 } 98 javax.swing.Action [] newActions = new javax.swing.Action [4 + nbextraoptions] ; int a=0; 100 newActions[a++]=(null); 101 newActions[a++]= (SystemAction.get(ShowAdminToolAction.class)); 102 newActions[a++]=(SystemAction.get(ViewLogAction.class)); 103 boolean isGlassFish = ServerLocationManager.isGlassFish(sdm.getPlatformRoot()); 104 for(int i = 0; i < nbextraoptions; i++) { 105 try{ 106 DataObject dobj = DataObject.find(ch[i]); 107 InstanceCookie cookie = (InstanceCookie) dobj.getCookie(InstanceCookie.class); 108 newActions[a+i]=null; 109 110 if(cookie != null){ 111 Class theActionClass = cookie.instanceClass(); 112 String attr = (String ) ch[i].getAttribute("8.x"); if (attr==null ){ newActions[a+i]=(SystemAction.get(theActionClass)); 115 116 } else if (!isGlassFish){ newActions[a+i]=(SystemAction.get(theActionClass)); 118 119 } 120 121 } 122 123 } catch (Exception e){ 124 e.printStackTrace(); 125 } 126 } 127 128 return newActions; 129 } 130 131 132 public String getAdminURL() { 133 if(sdm.isSecure()){ 134 return "https://"+sdm.getHost()+":"+sdm.getPort(); } else{ 136 return "http://"+sdm.getHost()+":"+sdm.getPort(); 138 } 139 } 140 public SunDeploymentManagerInterface getDeploymentManager(){ 141 sdm.refreshDeploymentManager(); 142 return sdm; 143 } 144 145 public HelpCtx getHelpCtx() { 146 return null; } 148 149 150 public static class MyChildren extends Children.Array { 151 public MyChildren(Collection nodes) { 152 super(nodes); 153 } 154 } 155 156 157 } 158 | Popular Tags |