KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > EnableAction


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
20 package org.netbeans.modules.tasklist.suggestions;
21
22 import java.awt.event.ActionListener JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import javax.swing.event.MenuListener JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import javax.swing.event.*;
28 import javax.swing.JMenuItem JavaDoc;
29 import javax.swing.JMenu JavaDoc;
30
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33 import org.openide.util.actions.*;
34 import org.openide.awt.*;
35 import org.netbeans.modules.tasklist.client.SuggestionManager;
36 import org.netbeans.modules.tasklist.suggestions.settings.ManagerSettings;
37
38 /**
39  * Let the re-enable disabled suggestion types
40  * <p>
41  * <b>XXX Note - this class is no longer used. Remove it as soon as
42  * the "Edit Suggestions..." functionality is "complete".</b>
43  * <p>
44  *
45  * @author Tor Norbye
46  */

47 public final class EnableAction extends CallableSystemAction
48     implements Presenter.Menu {
49
50     private static final long serialVersionUID = 1;
51
52     public EnableAction() {
53     }
54
55     protected boolean asynchronous() {
56         return false;
57     }
58     
59     public HelpCtx getHelpCtx () {
60         return HelpCtx.DEFAULT_HELP;
61     }
62     
63     
64     /* @return Returns localized name of this action */
65     public String JavaDoc getName() {
66         return NbBundle.getMessage(EnableAction.class,
67                    "EnableAction"); // NOI18N
68
}
69
70     /* Returns a submneu that will present this action in a Menu.
71     * @return the JMenuItem representation for this action
72     */

73     public JMenuItem JavaDoc getMenuPresenter () {
74     JMenu JavaDoc mainItem = new JMenuPlus();
75         Mnemonics.setLocalizedText(mainItem, getName());
76         //mainItem.setIcon (SystemAction.get(
77
// EnableAction.class).getIcon());
78
//HelpCtx.setHelpIDString (mainItem,
79
// EnableAction.class.getName());
80
mainItem.addMenuListener(new MainItemListener());
81         return mainItem;
82     }
83
84     /* Returns a submneu that will present this action in a PopupMenu.
85     * @return the JMenuItem representation for this action
86     */

87     public JMenuItem JavaDoc getPopupPresenter() {
88     JMenu JavaDoc mainItem = new JMenuPlus();
89         Mnemonics.setLocalizedText(mainItem, getName());
90         //HelpCtx.setHelpIDString (mainItem,
91
// EnableAction.class.getName());
92
mainItem.addMenuListener(new MainItemListener());
93         return mainItem;
94     }
95
96     /** Presentation in toolbar? */
97     /* Not yet implemented
98     public java.awt.Component getToolbarPresenter () {
99         ExplorerPanel ep = new ExplorerPanel ();
100         ep.add (new ChoiceView ());
101         ep.getExplorerManager ().setRootContext (getRecentNode ());
102         
103         return ep;
104     }
105     */

106     
107     public void performAction () {
108         // all functionality is accomplished by menu listeners
109
}
110
111     // innerclasses .......................................................
112

113     /** Listens to selecting of main item and expands it to the
114      * submenu of exiting and new modes
115      */

116     private static final class MainItemListener
117         implements MenuListener JavaDoc, ActionListener JavaDoc {
118
119         public void menuCanceled (MenuEvent e) {
120         }
121
122         public void menuDeselected (MenuEvent e) {
123             JMenu JavaDoc menu = (JMenu JavaDoc)e.getSource();
124             menu.removeAll();
125         }
126
127         public void menuSelected (MenuEvent e) {
128             JMenu JavaDoc menu = (JMenu JavaDoc)e.getSource();
129
130         // Add the disabled types
131
int n = 0;
132             SuggestionTypes types = SuggestionTypes.getDefault();
133             
134             Iterator JavaDoc it = types.getAllTypes().iterator();
135             while (it.hasNext()) {
136                 SuggestionType type = (SuggestionType) it.next();
137                 if (false == ManagerSettings.getDefault().isEnabled(type.getName())) {
138                     String JavaDoc category = type.getLocalizedName();
139                     menu.add(createMenuItem(category, type));
140                     n++;
141                 }
142             }
143             if (n == 0) {
144                 JMenuItem JavaDoc item = createMenuItem(
145                     NbBundle.getMessage(EnableAction.class, "Empty"), null); // NOI18N
146
item.setEnabled(false);
147                 menu.add(item);
148             }
149         }
150
151         // Property I attach suggestion types to on menu items
152
private final static String JavaDoc TYPE = "type"; // NOI18N
153

154         private JMenuItem JavaDoc createMenuItem(final String JavaDoc category,
155                                          SuggestionType type) {
156         JMenuItem JavaDoc curMenuItem = new JMenuItem JavaDoc(category);
157         curMenuItem.addActionListener(this);
158             if (type != null) {
159                 curMenuItem.putClientProperty(TYPE, type); // NOI18N
160
}
161         return curMenuItem;
162         }
163
164         // Select the given category
165
public void actionPerformed(ActionEvent JavaDoc e) {
166             JMenuItem JavaDoc item = (JMenuItem JavaDoc)e.getSource();
167             SuggestionType type = (SuggestionType)(item.getClientProperty(TYPE));
168             assert type != null;
169             SuggestionManagerImpl manager =
170                 (SuggestionManagerImpl)SuggestionManager.getDefault();
171             manager.setEnabled(type.getName(), true, false);
172         }
173     }
174 }
175
Popular Tags