KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > query > QueryUnusedGlobals


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * QueryUnusedGlobals.java
21  *
22  * Created on April 10, 2006, 2:55 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.schema.refactoring.query;
29
30 import javax.swing.JDialog JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.SwingUtilities JavaDoc;
33 import org.netbeans.api.progress.ProgressHandle;
34 import org.netbeans.api.progress.ProgressHandleFactory;
35 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
36 import org.netbeans.modules.xml.refactoring.ui.CancelGraph;
37 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
38 import org.netbeans.modules.xml.schema.model.SchemaModel;
39 import org.netbeans.modules.xml.schema.refactoring.query.views.QueryUnusedGlobalsCustomizerPanel;
40 import org.netbeans.modules.xml.schema.refactoring.query.views.QueryUnusedGlobalsView;
41 import org.netbeans.modules.xml.schema.refactoring.ui.QueryPanel;
42 import org.netbeans.modules.xml.schema.refactoring.ui.QueryPanelContainer;
43 import org.openide.DialogDescriptor;
44 import org.openide.DialogDisplayer;
45 import org.openide.ErrorManager;
46 import org.openide.NotifyDescriptor;
47 import org.openide.util.NbBundle;
48 import org.openide.util.RequestProcessor;
49
50 /**
51  *
52  * @author Jeri Lockhart
53  */

54 public class QueryUnusedGlobals implements Query {
55     
56 // private boolean isCancelRequested;
57
private String JavaDoc shortName;
58     private String JavaDoc displayName;
59     private SchemaModel model;
60 // private FUnCustomizer customizer;
61
Boolean JavaDoc excludeGEs;
62     private CustomizerResults results;
63     private QueryUnusedGlobalsView view;
64     
65     /** Creates a new instance of QueryUnusedGlobals */
66     public QueryUnusedGlobals(SchemaModel model) {
67         this.model = model;
68         this.shortName = NbBundle.getMessage(
69                 QueryUnusedGlobals.class, "LBL_QueryUnusedGlobal_Shortname");
70         this.displayName = NbBundle.getMessage(
71                 QueryUnusedGlobals.class, "LBL_QueryUnusedGlobal_Display_Name");
72     }
73     
74     /**
75      * Setter for property shortName - used on customizer column button
76      *
77      * @param shortName New value of property shortName.
78      */

79     public void setShortName(String JavaDoc shortName) {
80         this.shortName = shortName;
81     }
82     
83     /**
84      * Setter for property displayName.
85      *
86      * @param displayName New value of property displayName.
87      */

88     public void setDisplayName(String JavaDoc displayName) {
89         this.displayName = displayName;
90     }
91     
92     /**
93      * Getter for property shortName - used on customizer column button
94      *
95      * @return Value of property shortName.
96      */

97     public String JavaDoc getShortName() {
98         return shortName;
99     }
100     
101     
102     
103     /**
104      * Implement RunQuery interface
105      *
106      *
107      */

108     public void runQuery(final QueryPanel queryPanel, final AnalysisViewer analysisViewer) {
109         showCustomizerDialog();
110         if (results.wasCanceled()){
111             return;
112         }
113         excludeGEs = getExcludeGEs();
114         view = new QueryUnusedGlobalsView(model, excludeGEs);
115         final CancelGraph cancelSignal = new CancelGraph();
116         RequestProcessor.getDefault().post(new Runnable JavaDoc(){
117             public void run() {
118                 ProgressHandle ph = ProgressHandleFactory.createHandle(
119                         NbBundle.getMessage(QueryUnusedGlobals.class,
120                         "LBL_Finding_Unused_Global_Components"),
121                         cancelSignal
122                         );
123                 ph.start();
124                 ph.switchToIndeterminate();
125                 view.createModels(cancelSignal); // CancelSignal
126
if (cancelSignal.isCancelRequested()){
127                     ph.finish();
128                     return;
129                 }
130                 // uncomment to test progress bar
131
// try {
132
// Thread.currentThread().sleep(5000);
133
// } catch (InterruptedException ex) {
134
// ex.printStackTrace();
135
// }
136

137 // if(Thread.currentThread().isInterrupted()){
138
// return;
139
// }
140
ph.finish();
141                 SwingUtilities.invokeLater(new Runnable JavaDoc(){
142                     public void run() {
143                         
144                         if (view != null){
145                             if (!queryPanel.getIsVisible()) {
146                                 // dock it into output window area and display
147
QueryPanelContainer cont =
148                                         QueryPanelContainer.getUsagesComponent();
149                                 if (cont == null){
150                                     ErrorManager.getDefault().log(
151                                             ErrorManager.ERROR,
152                                             "XML Schema Query Failed to open QueryPanelContainer. The problem could be that the XML settings and wstcref files in userdir Windows2Local are obsolete. Try removing xml-schema-query.* and restart the IDE.");
153                                     return;
154                                 }
155                                 cont.open();
156                                 cont.requestActive();
157                                 cont.addPanel(queryPanel);
158                                 queryPanel.setIsVisible(true);
159                             }
160                             
161                             
162                             
163 // queryPanel.requestFocus();
164

165                             if (view != null){
166                                 view.showView(analysisViewer);
167                                 analysisViewer.validate();
168                                 analysisViewer.repaint();
169 // analysisViewer.requestFocus();
170
}
171                         }
172                     }
173                 });
174             }});
175             
176     }
177     
178     /**
179      *
180      *
181      */

182     public String JavaDoc toString() {
183         return displayName;
184     }
185  
186     public CustomizerResults showCustomizerDialog() {
187         results = new CustomizerResults();
188         QueryUnusedGlobalsCustomizerPanel panel = new QueryUnusedGlobalsCustomizerPanel();
189         results.setPanel(panel);
190         String JavaDoc title = NbBundle.getMessage(
191                 QueryUnusedGlobals.class, "LBL_QueryUnusedGlobal_Display_Name");
192         DialogDescriptor descriptor = new DialogDescriptor(panel, title);
193         JDialog JavaDoc dialog = (JDialog JavaDoc) DialogDisplayer.getDefault().createDialog(descriptor);
194         dialog.setTitle(title);
195         dialog.validate();
196 // dialog.getAccessibleContext().setAccessibleName(rui.getName());
197
// dialog.getAccessibleContext().setAccessibleDescription(ResourceBundle.getBundle("org/netbeans/modules/xml/refactoring/ui/j/spi/ui/Bundle").getString("ACSD_FindUsagesDialog"));
198

199         
200         if (DialogDisplayer.getDefault().notify(descriptor) != NotifyDescriptor.OK_OPTION) {
201             results.setWasCanceled(true);
202         }
203         return results;
204     }
205     
206 // public View getView() {
207
// return view;
208
// }
209

210     /**
211      * Get user customization option from customizer panel
212      *
213      */

214     private boolean getExcludeGEs(){
215         if (results != null){
216             JPanel JavaDoc panel = results.getPanel();
217             if (panel instanceof QueryUnusedGlobalsCustomizerPanel){
218                 QueryUnusedGlobalsCustomizerPanel cPnl = QueryUnusedGlobalsCustomizerPanel.class.cast(panel);
219                 return cPnl.getExcludeElements();
220             }
221         }
222         return false;
223     }
224
225     public SchemaModel getModel() {
226         return model;
227     }
228     
229     ///////////////////////////////////////////////////////////////////////////
230
// Inner Classes
231
///////////////////////////////////////////////////////////////////////////
232

233     
234     /**
235      *
236      *
237      *
238      */

239     public class FUnCustomizer {
240 // implements QueryCustomizer {
241

242         protected CustomizerResults[] constraints;
243         protected SchemaComponentReference[] references;
244         protected Query query;
245         protected QueryUnusedGlobalsCustomizerPanel panel;
246         
247         /** Creates a new instance of QueryCustomizerSupport */
248         public FUnCustomizer(Query query) {
249             super();
250             this.query = query;
251             initialize();
252         }
253         
254         protected void initialize() {
255             panel = new QueryUnusedGlobalsCustomizerPanel();
256 // panel.addPropertyChangeListener(QueryUnusedGlobals.this);
257

258         }
259         
260         public void setExcludeElements(boolean exclude){
261             panel.setExcludeElements(exclude);
262         }
263         
264         
265         /**
266          * Implement QueryCustomizer
267          *
268          */

269         
270         
271 // public void setQueryConstraints(final CustomizerResults[] queryConstraints) {
272
// if (queryConstraints == null){
273
// this.constraints = null;
274
// } else {
275
// this.constraints = new CustomizerResults[queryConstraints.length];
276
// System.arraycopy(queryConstraints, 0, this.constraints, 0, queryConstraints.length);
277
// }
278
// }
279
//
280
// public void setSchemaComponentReferences(final SchemaComponentReference[] schemaComponentReferences) {
281
// if (schemaComponentReferences == null){
282
// this.references = null;
283
// } else {
284
// this.references = new SchemaComponentReference[schemaComponentReferences.length];
285
// System.arraycopy(schemaComponentReferences, 0, this.references, 0, schemaComponentReferences.length);
286
// }
287
// }
288
//
289
// public SchemaComponentReference[] getSchemaComponentReferences() {
290
// SchemaComponentReference[] refsCopy = new SchemaComponentReference[references.length];
291
// System.arraycopy(references, 0, refsCopy, 0, references.length);
292
// return refsCopy;
293
// }
294
//
295
// public JPanel getQueryCustomizerPanel() {
296
// return panel;
297
// }
298
//
299
// public CustomizerResults[] getQueryConstraints() {
300
// CustomizerResults[] constraintsCopy = new CustomizerResults[constraints.length];
301
// System.arraycopy(constraints, 0, constraintsCopy, 0, constraints.length);
302
// return constraintsCopy;
303
// }
304
}
305 }
306
Popular Tags