KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > bugs > NewQueryAction


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.bugs;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.Dimension JavaDoc;
24 import org.netbeans.modules.tasklist.core.TaskListView;
25
26 import org.openide.DialogDescriptor;
27 import org.openide.NotifyDescriptor;
28 import org.openide.DialogDisplayer;
29 import org.openide.cookies.EditorCookie;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileUtil;
32 import org.openide.loaders.DataObject;
33 import org.openide.nodes.Node;
34 import org.openide.text.CloneableEditorSupport;
35 import org.openide.text.NbDocument;
36 import org.openide.util.HelpCtx;
37 import org.openide.util.NbBundle;
38 import org.openide.util.actions.NodeAction;
39 import org.openide.windows.Mode;
40 import org.openide.windows.TopComponent;
41 import org.openide.windows.WindowManager;
42
43
44 /**
45  * Action which brings up a dialog where you can create
46  * a new query.
47  * @author Tor Norbye, Trond Norbye, serff
48  */

49 public class NewQueryAction extends NodeAction {
50
51     private static final long serialVersionUID = 1;
52
53     protected boolean enable(Node[] node) {
54         return true;
55     }
56
57     /** Utility method which attempts to find the activated nodes
58     for the currently showing topcomponent in the editor window.
59     */

60     private static Node[] getEditorNodes() {
61         // First try to get the editor window itself; if you right click
62
// on a node in the Todo Window, that node becomes the activated
63
// node (which is good - it makes the properties window show the
64
// todo item's properties, etc.) but that means that we can't
65
// find the editor position via the normal means.
66
// So, we go hunting for the topmosteditor tab, and when we find it,
67
// ask for its nodes.
68
Node[] nodes = null;
69         WindowManager wm = WindowManager.getDefault();
70         
71         // HACK ALERT !!! HACK ALERT!!! HACK ALERT!!!
72
// Look for the source editor window, and then go through its
73
// top components, pick the one that is showing - that's the
74
// front one!
75
Mode mode = wm.findMode(CloneableEditorSupport.EDITOR_MODE);
76     if (mode == null) {
77         return null;
78     }
79         TopComponent [] tcs = mode.getTopComponents();
80         for (int j = 0; j < tcs.length; j++) {
81             TopComponent tc = tcs[j];
82             if (tc instanceof org.openide.text.EditorSupport.Editor) {
83                 // Found the source editor...
84
if (tcs[j].isShowing()) {
85                     nodes = tcs[j].getActivatedNodes();
86                     break;
87                 }
88             }
89         }
90     return nodes;
91     }
92      
93     protected void performAction(Node[] node) {
94         BugQuery query = new BugQuery();
95         EditQueryPanel panel = new EditQueryPanel(query, false);
96
97         DialogDescriptor d = new DialogDescriptor(panel,
98              NbBundle.getMessage(NewQueryAction.class,
99                                  "TITLE_NEW_QUERY")); // NOI18N
100
d.setModal(true);
101         d.setHelpCtx(new HelpCtx("NewQuery")); // NOI18N
102
d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
103         d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
104         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(d);
105         dlg.pack();
106         dlg.show();
107
108         if (d.getValue() == NotifyDescriptor.OK_OPTION) {
109             //do the new bug query
110
String JavaDoc bugEngine = panel.getBugEngine();
111             String JavaDoc queryString = panel.getQueryString();
112             query = panel.getQuery();
113             System.out.println("bugEngine = " + bugEngine + "\nqueryString = " + queryString);
114
115             TaskListView tv = new BugsView(query);
116             tv.showInMode();
117         }
118     }
119
120     protected boolean asynchronous() {
121         return false;
122     }
123     /**
124      * @param parentNode default parent; if null, don't parent
125      * @param filename suggested filename
126      * @parem line suggested line number (1-based)
127      * @param associate if true, set the checkbox for the filename by default (only
128      * makes sense if filename != null)
129      */

130 // public static void performAction(final Task parent,
131
// final String filename,
132
// final int line,
133
// final boolean associate) {
134
// // We've gotta do this from the AWT thread, and for some reason, even though
135
// // these actions are initiated through Swing actions, they come in on
136
// // the ModuleActions thread. So dispatch to the AWT thread.
137
// SwingUtilities.invokeLater(new Runnable() {
138
// public void run() {
139
// // Pick the right list to use
140
// UserTaskView view = (UserTaskView)UserTaskView.getCurrent();
141
// UserTaskList taskList = null;
142
// if (view != null) {
143
// taskList = (UserTaskList)view.getList();
144
// } else {
145
// taskList = UserTaskList.getDefault();
146
// }
147
// EditTaskPanel panel = new EditTaskPanel(taskList,
148
// (UserTask)parent, null,
149
// false);
150
// if (filename != null) {
151
// panel.setFilename(filename);
152
// if (line != 0) {
153
// panel.setLineNumber(line);
154
// }
155
// panel.setAssociatedFilePos(associate);
156
// }
157
//
158
// panel.setPreferredSize(new Dimension(600,500));
159
// DialogDescriptor d = new DialogDescriptor(panel,
160
// NbBundle.getMessage(NewQueryAction.class,
161
// "TITLE_add_todo")); // NOI18N
162
// d.setModal(true);
163
// d.setHelpCtx(new HelpCtx("NewTask")); // NOI18N
164
// d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
165
// d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
166
// Dialog dlg = TopManager.getDefault().createDialog(d);
167
// dlg.pack();
168
// dlg.show();
169
//
170
// if (d.getValue() == NotifyDescriptor.OK_OPTION) {
171
// String description = panel.getSummary();
172
// int priority = panel.getPrio();
173
// String details = panel.getDetails();
174
// String fname = null;
175
// int lineno = 0;
176
// if (panel.hasAssociatedFilePos()) {
177
// fname = panel.getFilename();
178
// lineno = panel.getLineNumber();
179
// }
180
// String category = panel.getCategory();
181
// UserTask parent = (UserTask)panel.getParentItem();
182
// UserTask item = new UserTask(description, false, priority,
183
// fname, lineno, details,
184
// category, parent);
185
// // See if the user wants to append or prepend
186
// boolean append = panel.getAppend();
187
// item.setDueDate(panel.getDueDate());
188
// taskList.add(item, append, true);
189
//
190
// // After the add - view the todo list as well!
191
// if (view != null) {
192
// view.select(item);
193
// view.showInMode();
194
// } else {
195
// ViewTasksAction.show();
196
// }
197
// }
198
// }
199
// });
200
// }
201

202     public String JavaDoc getName() {
203         return "New Query"; // NOI18N
204
}
205     
206     protected String JavaDoc iconResource() {
207     // I made a taskView.png, but it had ugly display artifacts (it
208
// looked fine in gimp but not when running the IDE)
209
return "org/netbeans/modules/tasklist/bugs/bugsView.gif"; // NOI18N
210
}
211     
212     public HelpCtx getHelpCtx() {
213         return HelpCtx.DEFAULT_HELP;
214         // If you will provide context help then use:
215
// return new HelpCtx (NewTodoItemAction.class);
216
}
217     
218 }
219
Popular Tags