KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > ui > ScanSuggestionsAction


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.ui;
21
22
23 import java.io.IOException JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import javax.swing.*;
26
27 import org.netbeans.modules.tasklist.client.SuggestionManager;
28 import org.netbeans.modules.tasklist.core.TaskList;
29 import org.netbeans.modules.tasklist.suggestions.ui.SuggestionsView;
30 import org.netbeans.modules.tasklist.suggestions.SuggestionList;
31 import org.netbeans.modules.tasklist.suggestions.SuggestionsScanner;
32 import org.openide.ErrorManager;
33 import org.openide.awt.StatusDisplayer;
34 import org.openide.cookies.EditorCookie;
35 import org.openide.loaders.DataFolder;
36 import org.openide.loaders.DataObject;
37 import org.openide.util.actions.CookieAction;
38 import org.openide.util.Utilities;
39 import org.openide.util.RequestProcessor;
40 import org.openide.nodes.Node;
41 import org.openide.util.HelpCtx;
42 import org.openide.util.NbBundle;
43
44 /**
45  * Scan a set of directories for suggestions
46  *
47  * @todo Provide a progress dialog, with a Cancel button
48  * @todo Modifications to files opened in the background should
49  * get saved!
50  *
51  * @todo It's probably overkill for me to go and open the Documents
52  * for every file I'm scanning; a buffered file reader inside of
53  * a StringReader would do the trick, provided SourceScanner would
54  * accept a String argument. That's a simple refactoring operation
55  * since most of the internals in the SourceScanner is dealing with
56  * the String value of the document. I should probably do a getDocument
57  * though in case a file is already open - that way I get the current
58  * (edited, not saved) version of the file which is what we want - or
59  * it not?
60  *
61  * @author Tor Norbye
62  */

63 public class ScanSuggestionsAction extends CookieAction {
64
65     private static final long serialVersionUID = 1;
66
67     protected boolean asynchronous() {
68         return true;
69     }
70
71     protected void performAction(final Node[] nodes) {
72         if (nodes == null) {
73             return;
74         }
75
76         final SuggestionsView[] view = new SuggestionsView[] {null};
77         try {
78             final SuggestionList list = new SuggestionList();
79             SwingUtilities.invokeLater( new Runnable JavaDoc() {
80                 public void run() {
81                     // The category should be DIFFERENT from the category used
82
// for the default suggestion view (the active scanning view)
83
// such that the "Show Suggestions View" action does not
84
// locate and reuse these windows - and so they can have different
85
// column configurations (filename is not useful in the active
86
// suggestions view window, but is critical in the directory
87
// scan for example.)
88
view[0] = new SuggestionsView("suggestionsscan", // NOI18N
89
NbBundle.getMessage(ScanSuggestionsAction.class,
90                             "ScannedTasks"), // NOI18N
91
list, false,
92                         "org/netbeans/modules/tasklist/suggestions/folderscan.gif"); // NOI18N
93
view[0].showInMode();
94                     view[0].setCursor(Utilities.createProgressCursor(view[0]));
95                 }
96             });
97
98             DataObject.Container[] folders = new DataObject.Container[nodes.length];
99             for (int i = 0; i < nodes.length; i++) {
100                 folders[i] = (DataObject.Container) nodes[i].getCookie(DataObject.Container.class);
101             }
102             SuggestionsScanner.getDefault().scan(folders, list, null);
103             
104             Integer JavaDoc count = new Integer JavaDoc(list.size());
105             StatusDisplayer.getDefault ().setStatusText(
106                 NbBundle.getMessage(ScanSuggestionsAction.class,
107                                    "ScanDone", count)); // NOI18N
108
} finally {
109             SwingUtilities.invokeLater( new Runnable JavaDoc() {
110                 public void run() {
111                     if (view[0] != null) {
112                         view[0].setCursor(null);
113                     }
114                 }
115             });
116         }
117     }
118
119     public String JavaDoc getName() {
120         return NbBundle.getMessage(ScanSuggestionsAction.class, "ScanDir"); // NOI18N
121
}
122
123     protected String JavaDoc iconResource() {
124         return "org/netbeans/modules/tasklist/suggestions/ui/scanDir.gif"; // NOI18N
125
}
126     
127     public HelpCtx getHelpCtx() {
128         return HelpCtx.DEFAULT_HELP;
129     }
130
131     protected int mode() {
132         return MODE_ALL;
133     }
134     
135     protected Class JavaDoc[] cookieClasses() {
136         return new Class JavaDoc[] { DataObject.Container.class };
137     }
138
139 }
140
Popular Tags