KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > runtime > actions > EnableDisableAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 /**
33  *
34  *
35  */

36 public class EnableDisableAction extends NodeAction {
37     
38     private boolean enabled;
39     
40     
41     /**
42      *
43      *
44      */

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 JavaDoc 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 JavaDoc 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     /**
82      *
83      *
84      */

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 JavaDoc 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 JavaDoc rex) {
104                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,rex);
105             }
106         }
107         
108         return (nodes.length >= 1) ? true : false;
109     }
110     
111     
112     /**
113      *
114      *
115      */

116     protected boolean asynchronous() {
117         return false;
118     }
119     
120     
121     /**
122      *
123      *
124      */

125     public HelpCtx getHelpCtx() {
126         return HelpCtx.DEFAULT_HELP;
127     }
128     
129     
130     /**
131      *
132      */

133     public String JavaDoc 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