1 19 20 package org.netbeans.modules.tasklist.suggestions; 21 22 import java.awt.event.ActionListener ; 23 import java.awt.event.ActionEvent ; 24 import javax.swing.event.MenuListener ; 25 import java.util.Iterator ; 26 27 import javax.swing.event.*; 28 import javax.swing.JMenuItem ; 29 import javax.swing.JMenu ; 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 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 65 public String getName() { 66 return NbBundle.getMessage(EnableAction.class, 67 "EnableAction"); } 69 70 73 public JMenuItem getMenuPresenter () { 74 JMenu mainItem = new JMenuPlus(); 75 Mnemonics.setLocalizedText(mainItem, getName()); 76 mainItem.addMenuListener(new MainItemListener()); 81 return mainItem; 82 } 83 84 87 public JMenuItem getPopupPresenter() { 88 JMenu mainItem = new JMenuPlus(); 89 Mnemonics.setLocalizedText(mainItem, getName()); 90 mainItem.addMenuListener(new MainItemListener()); 93 return mainItem; 94 } 95 96 97 106 107 public void performAction () { 108 } 110 111 113 116 private static final class MainItemListener 117 implements MenuListener , ActionListener { 118 119 public void menuCanceled (MenuEvent e) { 120 } 121 122 public void menuDeselected (MenuEvent e) { 123 JMenu menu = (JMenu )e.getSource(); 124 menu.removeAll(); 125 } 126 127 public void menuSelected (MenuEvent e) { 128 JMenu menu = (JMenu )e.getSource(); 129 130 int n = 0; 132 SuggestionTypes types = SuggestionTypes.getDefault(); 133 134 Iterator it = types.getAllTypes().iterator(); 135 while (it.hasNext()) { 136 SuggestionType type = (SuggestionType) it.next(); 137 if (false == ManagerSettings.getDefault().isEnabled(type.getName())) { 138 String category = type.getLocalizedName(); 139 menu.add(createMenuItem(category, type)); 140 n++; 141 } 142 } 143 if (n == 0) { 144 JMenuItem item = createMenuItem( 145 NbBundle.getMessage(EnableAction.class, "Empty"), null); item.setEnabled(false); 147 menu.add(item); 148 } 149 } 150 151 private final static String TYPE = "type"; 154 private JMenuItem createMenuItem(final String category, 155 SuggestionType type) { 156 JMenuItem curMenuItem = new JMenuItem (category); 157 curMenuItem.addActionListener(this); 158 if (type != null) { 159 curMenuItem.putClientProperty(TYPE, type); } 161 return curMenuItem; 162 } 163 164 public void actionPerformed(ActionEvent e) { 166 JMenuItem item = (JMenuItem )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 |