1 19 20 package org.netbeans.modules.tasklist.core.filter; 21 22 import java.awt.*; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeListener ; 26 import java.beans.PropertyChangeEvent ; 27 import javax.swing.JButton ; 28 import javax.swing.JPanel ; 29 import org.netbeans.modules.tasklist.core.TaskListView; 30 import org.openide.DialogDescriptor; 31 import org.openide.NotifyDescriptor; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 import org.openide.util.actions.CallableSystemAction; 35 import org.openide.util.actions.SystemAction; 36 import org.openide.DialogDisplayer; 37 import org.openide.awt.Mnemonics; 38 import org.openide.windows.TopComponent; 39 import org.openide.windows.WindowManager; 40 41 42 48 public class FilterAction extends CallableSystemAction { 49 50 private static final long serialVersionUID = 1; 51 52 protected final boolean asynchronous() { 53 return false; 54 } 55 56 public final void performAction() { 57 TopComponent tc = WindowManager.getDefault().getRegistry().getActivated(); 58 59 if (!(tc instanceof FilteredTopComponent)) { 61 Toolkit.getDefaultToolkit().beep(); 62 return; 63 } 64 65 final FilteredTopComponent view = (FilteredTopComponent) tc; 66 67 JPanel parentPanel = new JPanel (); 68 parentPanel.setLayout(new BorderLayout()); 69 parentPanel.getAccessibleContext().setAccessibleDescription 70 (NbBundle.getMessage(FilterAction.class, "ACSD_Filter")); 71 72 73 final FiltersPanel panel = new FiltersPanel(view); 74 parentPanel.add(panel, BorderLayout.CENTER); 75 DialogDescriptor d = new DialogDescriptor(parentPanel, 76 NbBundle.getMessage(FilterAction.class, 77 "TITLE_filter")); d.setModal(isModal()); 79 80 81 final JButton ok = new JButton (); 82 Mnemonics.setLocalizedText(ok, NbBundle.getMessage( 83 FilterAction.class, "OK")); ok.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_OK_Hint")); 85 86 final JButton cancel = new JButton (); 87 Mnemonics.setLocalizedText(cancel, NbBundle.getMessage( 88 FilterAction.class, "Cancel")); cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_Cancel_Hint")); 90 91 final JButton apply = new JButton (); 92 Mnemonics.setLocalizedText(apply, NbBundle.getMessage( 93 FilterAction.class, "BTN_Preview")); apply.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_Preview_Hint")); 95 96 panel.addPropertyChangeListener(FilterCondition.PROP_VALUE_VALID, new PropertyChangeListener () { 97 public void propertyChange(PropertyChangeEvent evt) { 98 ok.setEnabled(panel.isValueValid()); 99 apply.setEnabled(panel.isValueValid()); 100 } 101 }); 102 103 104 d.setOptions(new JButton [] {ok, cancel, apply}); 105 d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE); 106 d.setButtonListener(new ActionListener () { 107 108 private FilterRepository repositoryBackup = null; 109 private Filter activeFilterBackup = null; 110 111 public void actionPerformed(ActionEvent e) { 112 Object src = e.getSource(); 113 if (src == ok) { 114 panel.updateFilters(); 116 view.setFilter(view.getFilters().getActive()); 117 } else if (src == cancel) { 118 if (repositoryBackup != null) { 119 view.getFilters().assign(repositoryBackup); 120 view.setFilter(activeFilterBackup); 121 } 122 } else if (src == apply) { 123 if (repositoryBackup == null) { 124 repositoryBackup = (FilterRepository)view.getFilters().clone(); 125 activeFilterBackup = view.getFilter(); 126 } 127 panel.updateFilters(); 128 view.setFilter(view.getFilters().getActive()); 129 } 130 } 131 }); 132 d.setClosingOptions(new Object [] {ok, cancel}); 133 134 135 Dialog dlg = DialogDisplayer.getDefault().createDialog(d); 136 dlg.pack(); 137 dlg.setVisible(true); 138 139 } 140 141 142 165 public final void performAction(SystemAction action) { 166 performAction(); 167 } 168 169 175 protected Component createSubpanel() { 176 return null; 177 } 178 179 183 protected Filter createFilter(TaskListView tlv) { 184 return tlv.createFilter(); 185 } 186 187 188 public String getName() { 189 return NbBundle.getMessage(FilterAction.class, "Filter"); } 191 192 protected String iconResource() { 193 return "org/netbeans/modules/tasklist/core/filter/filter.png"; } 195 196 public HelpCtx getHelpCtx() { 197 return HelpCtx.DEFAULT_HELP; 198 } 201 202 protected boolean isModal() { 203 return false; 204 } 205 206 } 207 | Popular Tags |