1 19 package org.netbeans.modules.j2ee.sun.ide.runtime.actions; 20 21 import org.openide.ErrorManager; 22 import org.openide.NotifyDescriptor; 23 import org.openide.nodes.Node; 24 import org.openide.util.Lookup; 25 import org.openide.util.actions.NodeAction; 26 import org.openide.util.NbBundle; 27 import org.openide.util.HelpCtx; 28 29 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtNode; 30 import org.netbeans.modules.j2ee.sun.bridge.apis.Removable; 31 import org.netbeans.modules.j2ee.sun.ide.runtime.nodes.ConnectionPoolNode; 32 import org.netbeans.modules.j2ee.sun.util.NodeTypes; 33 import org.netbeans.modules.j2ee.sun.util.GUIUtils; 34 35 import org.netbeans.modules.j2ee.sun.bridge.apis.RefreshCookie; 36 37 41 public class DeleteResourceAction extends NodeAction { 42 43 44 48 protected void performAction(Node[] activatedNodes) { 49 if (activatedNodes==null){ 50 return; 51 } 52 53 for (int i=0;i<activatedNodes.length;i++){ 54 Node node = activatedNodes[i]; 55 Lookup lookup = node.getLookup(); 56 57 Object obj2 = lookup.lookup(AppserverMgmtNode.class); 58 String nodeType = null; 59 60 if(obj2 instanceof AppserverMgmtNode) { 61 AppserverMgmtNode appMgmtNode = (AppserverMgmtNode) obj2; 62 nodeType = appMgmtNode.getNodeType(); 63 } 64 65 try { 66 70 if(NodeTypes.CONNECTION_POOL.equals(nodeType)) { 71 Object proceed = 72 GUIUtils.showWarning( 73 getLocalizedString("dependent_resources_notify")); 74 if(proceed == NotifyDescriptor.OK_OPTION){ 75 deleteDependentResources(node); 76 removeResource(node); 77 } 78 } else { 79 removeResource(node); 80 } 81 82 Node parentNode = node.getParentNode(); 84 RefreshCookie refreshAction = 85 (RefreshCookie)parentNode.getCookie(RefreshCookie.class); 86 if (refreshAction != null){ 87 refreshAction.refresh(); 88 } 89 } catch(java.lang.RuntimeException rex) { 90 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,rex); 91 } 92 } 93 } 94 95 96 101 private void removeResource(final Node node) { 102 Lookup lookup = node.getLookup(); 103 Object obj = lookup.lookup(Removable.class); 104 if(obj instanceof Removable) { 105 Removable removeableObj = (Removable)obj; 106 removeableObj.remove(); 107 } 108 } 109 110 111 115 private void deleteDependentResources(final Node node) { 116 Lookup lookup = node.getLookup(); 117 Object obj = lookup.lookup(ConnectionPoolNode.class); 118 if(obj instanceof ConnectionPoolNode) { 119 ConnectionPoolNode connPoolNode = (ConnectionPoolNode) obj; 120 connPoolNode.removeDependentJDBCResources(); 121 } 122 refreshJDBCResourcesFolder(node); 123 } 124 125 129 private void refreshJDBCResourcesFolder(final Node node){ 130 try { 131 Node parentNode = node.getParentNode(); 132 org.openide.nodes.Children ch = parentNode.getParentNode().getChildren(); 133 Node[] resourceNodes = ch.getNodes(true); 134 if(resourceNodes.length > 0){ 135 Node jdbcMgmtNode = resourceNodes[0]; 136 RefreshCookie refreshAction = (RefreshCookie)jdbcMgmtNode.getCookie(RefreshCookie.class); 137 if (refreshAction != null) { 138 refreshAction.refresh(); 139 } 140 } 141 }catch(Exception ex){ 142 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,ex); 145 } 146 } 147 148 152 protected boolean enable(Node[] nodes) { 153 return ((nodes != null) && (nodes.length >= 1)) ? true : false; 154 } 155 156 157 161 protected boolean asynchronous() { 162 return false; 163 } 164 165 166 170 public HelpCtx getHelpCtx() { 171 return HelpCtx.DEFAULT_HELP; 172 } 173 174 177 public String getName() { 178 return NbBundle.getMessage(DeleteResourceAction.class, 179 "LBL_DeleteResourceAction"); 180 } 181 182 183 187 private static String getLocalizedString(final String bundleStrProp) { 188 return NbBundle.getMessage(DeleteResourceAction.class, bundleStrProp); 189 } 190 191 } 192 | Popular Tags |