1 19 package org.netbeans.modules.j2ee.sun.ide.runtime.actions; 20 21 import org.openide.ErrorManager; 22 import org.openide.nodes.Node; 23 import org.openide.util.Lookup; 24 import org.openide.util.actions.NodeAction; 25 import org.openide.util.NbBundle; 26 import org.openide.util.HelpCtx; 27 28 import org.netbeans.modules.j2ee.sun.bridge.apis.Enableable; 29 30 import org.netbeans.modules.j2ee.sun.bridge.apis.RefreshCookie; 31 32 36 public class EnableDisableAction extends NodeAction { 37 38 private boolean enabled; 39 40 41 45 protected void performAction(Node[] activatedNodes) { 46 if (activatedNodes==null){ 47 return; 48 } 49 50 for (int i=0;i<activatedNodes.length;i++){ 51 Node node = activatedNodes[i]; 52 Lookup lookup = node.getLookup(); 53 Object obj = lookup.lookup(Enableable.class); 54 55 try { 56 if(obj instanceof Enableable) { 57 Enableable enableableObj = (Enableable)obj; 58 if(enableableObj.isEnabled()) { 59 enableableObj.setEnabled(false); 60 enabled = false; 61 } else { 62 enableableObj.setEnabled(true); 63 enabled = true; 64 } 65 } 66 } catch(java.lang.RuntimeException rex) { 67 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,rex); 68 } 69 70 Node parentNode = node.getParentNode(); 71 RefreshCookie refreshAction = 72 (RefreshCookie)parentNode.getCookie(RefreshCookie.class); 73 if (refreshAction != null){ 74 refreshAction.refresh(); 75 } 76 } 77 78 } 79 80 81 85 protected boolean enable(Node[] nodes) { 86 if (null == nodes) { 87 return false; 88 } 89 if(nodes.length > 0) { 90 Node node = nodes[0]; 91 Lookup lookup = node.getLookup(); 92 Object obj = lookup.lookup(Enableable.class); 93 94 try { 95 if(obj instanceof Enableable) { 96 Enableable enableableObj = (Enableable)obj; 97 if(enableableObj.isEnabled()) { 98 enabled = false; 99 } else { 100 enabled = true; 101 } 102 } 103 } catch(java.lang.RuntimeException rex) { 104 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,rex); 105 } 106 } 107 108 return (nodes.length >= 1) ? true : false; 109 } 110 111 112 116 protected boolean asynchronous() { 117 return false; 118 } 119 120 121 125 public HelpCtx getHelpCtx() { 126 return HelpCtx.DEFAULT_HELP; 127 } 128 129 130 133 public String getName() { 134 if(enabled) { 135 return NbBundle.getMessage(EnableDisableAction.class, "LBL_EnableAction"); 136 } else { 137 return NbBundle.getMessage(EnableDisableAction.class, "LBL_DisableAction"); 138 } 139 } 140 141 } 142 | Popular Tags |