KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > filter > FilterAction


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.core.filter;
21
22 import java.awt.*;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import javax.swing.JButton JavaDoc;
28 import javax.swing.JPanel JavaDoc;
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 /** Filter the tasklist such that only tasks matching a given
43  * criteria (or with a subtask matching the given criteria) are
44  * shown.
45  *
46  * @author Tor Norbye
47  */

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         // Pick the right list to use
60
if (!(tc instanceof FilteredTopComponent)) {
61             Toolkit.getDefaultToolkit().beep();
62             return;
63         }
64         
65         final FilteredTopComponent view = (FilteredTopComponent) tc;
66
67         JPanel JavaDoc parentPanel = new JPanel JavaDoc();
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")); // NOI18N
78
d.setModal(isModal());
79
80         
81         final JButton JavaDoc ok = new JButton JavaDoc();
82         Mnemonics.setLocalizedText(ok, NbBundle.getMessage(
83             FilterAction.class, "OK")); // NOI18N
84
ok.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_OK_Hint"));
85         
86         final JButton JavaDoc cancel = new JButton JavaDoc();
87         Mnemonics.setLocalizedText(cancel, NbBundle.getMessage(
88             FilterAction.class, "Cancel")); // NOI18N
89
cancel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_Cancel_Hint"));
90         
91         final JButton JavaDoc apply = new JButton JavaDoc();
92         Mnemonics.setLocalizedText(apply, NbBundle.getMessage(
93             FilterAction.class, "BTN_Preview")); // NOI18N
94
apply.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FilterAction.class, "BTN_Preview_Hint"));
95         
96         panel.addPropertyChangeListener(FilterCondition.PROP_VALUE_VALID, new PropertyChangeListener JavaDoc() {
97             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
98                 ok.setEnabled(panel.isValueValid());
99                 apply.setEnabled(panel.isValueValid());
100             }
101         });
102
103
104         d.setOptions(new JButton JavaDoc[] {ok, cancel, apply});
105         d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
106         d.setButtonListener(new ActionListener JavaDoc() {
107
108         private FilterRepository repositoryBackup = null;
109         private Filter activeFilterBackup = null;
110
111             public void actionPerformed(ActionEvent JavaDoc e) {
112                 Object JavaDoc src = e.getSource();
113                 if (src == ok) {
114                     //view.setFilter(panel.getFilter(), true);
115
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 JavaDoc[] {ok, cancel});
133
134         
135         Dialog dlg = DialogDisplayer.getDefault().createDialog(d);
136         dlg.pack();
137         dlg.setVisible(true);
138
139     }
140
141     
142     /*
143     public final void performAction() {
144         // Pick the right list to use
145         final TaskListView view = TaskListView.getCurrent();
146         if (view == null) {
147             Toolkit.getDefaultToolkit().beep();
148             return;
149         }
150
151         JPanel parentPanel = new JPanel();
152         parentPanel.setLayout(new BorderLayout());
153         Filter exitingFilter = view.getFilter();
154         if (exitingFilter == null) exitingFilter = createFilter(view);
155         final FilterPanel panel = new FilterPanel(view, exitingFilter);
156         parentPanel.add(panel, BorderLayout.CENTER);
157         Component south = createSubpanel();
158         if (south != null) {
159             parentPanel.add(south, BorderLayout.SOUTH);
160             panel.initSubpanel((FilterSubpanel)south);
161         }
162
163     }
164 */

165     public final void performAction(SystemAction action) {
166         performAction();
167     }
168
169     /**
170      * Overwrite to create optional filter subpanel
171      * (placed in south). Default add subpanel with
172      * hiearchy options.
173      * @return Component implementing FilterSubpanel
174      */

175     protected Component createSubpanel() {
176         return null;
177     }
178
179     /**
180      * Creates new filter for views wihout existing one.
181      * @return default returns view's {@link TaskListView#createFilter}.
182      */

183     protected Filter createFilter(TaskListView tlv) {
184         return tlv.createFilter();
185     }
186
187     /** Return name of the action, as shown in menus etc. */
188     public String JavaDoc getName() {
189         return NbBundle.getMessage(FilterAction.class, "Filter"); // NOI18N
190
}
191
192     protected String JavaDoc iconResource() {
193         return "org/netbeans/modules/tasklist/core/filter/filter.png"; // NOI18N
194
}
195
196     public HelpCtx getHelpCtx() {
197         return HelpCtx.DEFAULT_HELP;
198         // If you will provide context help then use:
199
// return new HelpCtx (MyAction.class);
200
}
201
202     protected boolean isModal() {
203         return false;
204     }
205
206 }
207
Popular Tags