#96554: Implement undeploy action for datasources ddbean_removal_merge1
authormmocnak@netbeans.org
Mon, 26 Feb 2007 17:13:20 +0000
changeset 8024493a91bc8525
parent 8023 ff3ea0eb40a6
child 8025 d99e241a824e
#96554: Implement undeploy action for datasources
j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JItemNode.java
j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JManagedDataSourcesChildren.java
j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JNativeDataSourcesChildren.java
j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/actions/UndeployModuleAction.java
     1.1 --- a/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JItemNode.java	Mon Feb 26 02:40:55 2007 +0000
     1.2 +++ b/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JItemNode.java	Mon Feb 26 17:13:20 2007 +0000
     1.3 @@ -22,12 +22,14 @@
     1.4  import java.awt.Image;
     1.5  import javax.enterprise.deploy.spi.TargetModuleID;
     1.6  import javax.enterprise.deploy.spi.status.ProgressObject;
     1.7 +import javax.management.MBeanServerConnection;
     1.8  import org.netbeans.api.progress.ProgressHandle;
     1.9  import org.netbeans.api.progress.ProgressHandleFactory;
    1.10  import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
    1.11  import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport;
    1.12  import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport.ServerIcon;
    1.13  import org.netbeans.modules.j2ee.oc4j.OC4JDeploymentManager;
    1.14 +import org.netbeans.modules.j2ee.oc4j.config.OC4JDatasourceManager;
    1.15  import org.netbeans.modules.j2ee.oc4j.nodes.actions.OpenURLAction;
    1.16  import org.netbeans.modules.j2ee.oc4j.nodes.actions.OpenURLActionCookie;
    1.17  import org.netbeans.modules.j2ee.oc4j.nodes.actions.RefreshModulesAction;
    1.18 @@ -62,7 +64,7 @@
    1.19      
    1.20      private static final int TIMEOUT = 30000;
    1.21      
    1.22 -    private OC4JItemNode(Children children, final TargetModuleID module, final Lookup lookup, ItemType type) {
    1.23 +    private OC4JItemNode(Children children, final TargetModuleID module, final Lookup lookup, final ItemType type) {
    1.24          super(children);
    1.25          this.type = type;
    1.26          
    1.27 @@ -148,6 +150,45 @@
    1.28                      return isRunning;
    1.29                  }
    1.30              });
    1.31 +        } else if (type.equals(ItemType.JDBC_NATIVE_DATASOURCES) ||
    1.32 +                type.equals(ItemType.JDBC_MANAGED_DATASOURCES) ||
    1.33 +                type.equals(ItemType.CONNECTION_POOLS)) {
    1.34 +            getCookieSet().add(new UndeployModuleCookie() {
    1.35 +                private boolean isRunning = false;
    1.36 +                
    1.37 +                public Task undeploy() {
    1.38 +                    final OC4JDeploymentManager dm = lookup.lookup(OC4JDeploymentManager.class);
    1.39 +                    final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(OC4JItemNode.class,
    1.40 +                            "LBL_UndeployProgress", getDisplayName()));
    1.41 +                    
    1.42 +                    Runnable r = new Runnable() {
    1.43 +                        public void run() {
    1.44 +                            isRunning = true;
    1.45 +                            
    1.46 +                            OC4JDatasourceManager dsManager = new OC4JDatasourceManager(dm);
    1.47 +                            
    1.48 +                            // Undeploying
    1.49 +                            if(type.equals(ItemType.JDBC_NATIVE_DATASOURCES)) {
    1.50 +                                dsManager.undeployNativeDataSource(getDisplayName());
    1.51 +                            } else if (type.equals(ItemType.JDBC_MANAGED_DATASOURCES)) {
    1.52 +                                dsManager.undeployManagedDataSource(getDisplayName());
    1.53 +                            } else if (type.equals(ItemType.CONNECTION_POOLS)) {
    1.54 +                                dsManager.undeployConnectionPool(getDisplayName());
    1.55 +                            }
    1.56 +                            
    1.57 +                            handle.finish();
    1.58 +                            isRunning = false;
    1.59 +                        }
    1.60 +                    };
    1.61 +                    
    1.62 +                    handle.start();
    1.63 +                    return RequestProcessor.getDefault().post(r);
    1.64 +                }
    1.65 +                
    1.66 +                public synchronized boolean isRunning() {
    1.67 +                    return isRunning;
    1.68 +                }
    1.69 +            });
    1.70          }
    1.71      }
    1.72      
    1.73 @@ -167,7 +208,8 @@
    1.74          } else if(this.type.equals(ItemType.J2EE_APPLICATION) ||
    1.75                  this.type.equals(ItemType.J2EE_APPLICATION_SYSTEM)) {
    1.76              return UISupport.getIcon(ServerIcon.EAR_ARCHIVE);
    1.77 -        } else if(this.type.equals(ItemType.JDBC_RESOURCES)) {
    1.78 +        } else if(this.type.equals(ItemType.JDBC_MANAGED_DATASOURCES) ||
    1.79 +                this.type.equals(ItemType.JDBC_NATIVE_DATASOURCES)) {
    1.80              return Utilities.loadImage(JDBC_RESOURCE_ICON);
    1.81          } else if(this.type.equals(ItemType.CONNECTION_POOLS)) {
    1.82              return Utilities.loadImage(CONNECTION_POOL_ICON);
    1.83 @@ -181,7 +223,8 @@
    1.84              return UISupport.getIcon(ServerIcon.EAR_OPENED_FOLDER);
    1.85          } else if(this.type.equals(ItemType.J2EE_APPLICATION) ||
    1.86                  this.type.equals(ItemType.J2EE_APPLICATION_SYSTEM) ||
    1.87 -                this.type.equals(ItemType.JDBC_RESOURCES) ||
    1.88 +                this.type.equals(ItemType.JDBC_MANAGED_DATASOURCES) ||
    1.89 +                this.type.equals(ItemType.JDBC_NATIVE_DATASOURCES) ||
    1.90                  this.type.equals(ItemType.CONNECTION_POOLS)) {
    1.91              return getIcon(type);
    1.92          } else {
    1.93 @@ -206,6 +249,12 @@
    1.94                  SystemAction.get(OpenURLAction.class),
    1.95                  SystemAction.get(UndeployModuleAction.class)
    1.96              };
    1.97 +        } else if(type.equals(ItemType.JDBC_NATIVE_DATASOURCES) ||
    1.98 +                type.equals(ItemType.JDBC_MANAGED_DATASOURCES) ||
    1.99 +                type.equals(ItemType.CONNECTION_POOLS)) {
   1.100 +            actions = new SystemAction[] {
   1.101 +                SystemAction.get(UndeployModuleAction.class)
   1.102 +            };
   1.103          }
   1.104          
   1.105          return actions;
   1.106 @@ -232,7 +281,8 @@
   1.107          public static ItemType J2EE_APPLICATION = new ItemType();
   1.108          public static ItemType J2EE_APPLICATION_SYSTEM = new ItemType();
   1.109          public static ItemType REFRESHABLE_FOLDER = new ItemType();
   1.110 -        public static ItemType JDBC_RESOURCES = new ItemType();
   1.111 +        public static ItemType JDBC_MANAGED_DATASOURCES = new ItemType();
   1.112 +        public static ItemType JDBC_NATIVE_DATASOURCES = new ItemType();
   1.113          public static ItemType CONNECTION_POOLS = new ItemType();
   1.114          
   1.115          private ItemType() {}
     2.1 --- a/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JManagedDataSourcesChildren.java	Mon Feb 26 02:40:55 2007 +0000
     2.2 +++ b/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JManagedDataSourcesChildren.java	Mon Feb 26 17:13:20 2007 +0000
     2.3 @@ -66,9 +66,10 @@
     2.4                          if(pool.length() == 0)
     2.5                              continue;
     2.6                          
     2.7 +                        String name = (String) server.getAttribute(elem, "dataSourceName");
     2.8                          String jndiName = (String) server.getAttribute(elem, "jndiName");
     2.9 -                        Node node = new OC4JItemNode(lookup, Children.LEAF, jndiName, OC4JItemNode.ItemType.JDBC_RESOURCES);
    2.10 -                        node.setShortDescription(NbBundle.getMessage(OC4JManagedDataSourcesChildren.class, "TXT_ConnectionPool")+pool);
    2.11 +                        Node node = new OC4JItemNode(lookup, Children.LEAF, name, OC4JItemNode.ItemType.JDBC_MANAGED_DATASOURCES);
    2.12 +                        node.setShortDescription(jndiName + " -> " + NbBundle.getMessage(OC4JManagedDataSourcesChildren.class, "TXT_ConnectionPool")+pool);
    2.13                          
    2.14                          keys.add(node);
    2.15                      }
     3.1 --- a/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JNativeDataSourcesChildren.java	Mon Feb 26 02:40:55 2007 +0000
     3.2 +++ b/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/OC4JNativeDataSourcesChildren.java	Mon Feb 26 17:13:20 2007 +0000
     3.3 @@ -65,10 +65,11 @@
     3.4                          if(pool.length() > 0)
     3.5                              continue;
     3.6                          
     3.7 +                        String name = (String) server.getAttribute(elem, "dataSourceName");
     3.8                          String jndiName = (String) server.getAttribute(elem, "jndiName");
     3.9                          String url = (String) server.getAttribute(elem, "url");
    3.10 -                        Node node = new OC4JItemNode(lookup, Children.LEAF, jndiName, OC4JItemNode.ItemType.JDBC_RESOURCES);
    3.11 -                        node.setShortDescription(url);
    3.12 +                        Node node = new OC4JItemNode(lookup, Children.LEAF, name, OC4JItemNode.ItemType.JDBC_NATIVE_DATASOURCES);
    3.13 +                        node.setShortDescription(jndiName + " -> " + url);
    3.14                          
    3.15                          keys.add(node);
    3.16                      }
     4.1 --- a/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/actions/UndeployModuleAction.java	Mon Feb 26 02:40:55 2007 +0000
     4.2 +++ b/j2ee.oc4j/src/org/netbeans/modules/j2ee/oc4j/nodes/actions/UndeployModuleAction.java	Mon Feb 26 17:13:20 2007 +0000
     4.3 @@ -41,15 +41,18 @@
     4.4              
     4.5              if (uCookie != null) {
     4.6                  final Task t = uCookie.undeploy();
     4.7 -                final Node pNode = node.getParentNode();
     4.8 +                final Node pNode = node.getParentNode().getParentNode();
     4.9                  
    4.10                  RequestProcessor.getDefault().post(new Runnable() {
    4.11                      public void run() {
    4.12                          t.waitFinished();
    4.13                          if(pNode != null) {
    4.14 -                            RefreshModulesCookie cookie = pNode.getCookie(RefreshModulesCookie.class);
    4.15 -                            if (cookie != null) {
    4.16 -                                cookie.refresh();
    4.17 +                            Node[] nodes = pNode.getChildren().getNodes();
    4.18 +                            for (Node node : nodes) {
    4.19 +                                RefreshModulesCookie cookie = node.getCookie(RefreshModulesCookie.class);
    4.20 +                                if (cookie != null) {
    4.21 +                                    cookie.refresh();
    4.22 +                                }
    4.23                              }
    4.24                          }
    4.25                      }