KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
21  * QuerySubstitutionGroups.java
22  *
23  * Created on January 16, 2006, 4:43 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.query;
30
31 import java.text.MessageFormat JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34 import javax.swing.JDialog JavaDoc;
35 import javax.swing.SwingUtilities JavaDoc;
36 import org.netbeans.api.progress.ProgressHandle;
37 import org.netbeans.api.progress.ProgressHandleFactory;
38 import org.netbeans.modules.xml.nbprefuse.AnalysisConstants;
39 import org.netbeans.modules.xml.nbprefuse.AnalysisViewer;
40 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
41 import org.netbeans.modules.xml.schema.model.Schema;
42 import org.netbeans.modules.xml.schema.model.SchemaComponent;
43 import org.netbeans.modules.xml.schema.model.SchemaModel;
44 import org.netbeans.modules.xml.schema.refactoring.query.views.ComplexTypeDerivationsView;
45 import org.netbeans.modules.xml.schema.refactoring.query.views.WhereUsedExplorer;
46 import org.netbeans.modules.xml.schema.refactoring.query.views.WhereUsedExplorer.QueryCustomizerNode;
47 import org.netbeans.modules.xml.schema.refactoring.ui.QueryPanel;
48 import org.netbeans.modules.xml.schema.refactoring.ui.QueryPanelContainer;
49 import org.netbeans.modules.xml.schema.refactoring.ui.QueryUtilities;
50 import org.netbeans.modules.xml.xam.Named;
51 import org.openide.DialogDescriptor;
52 import org.openide.DialogDisplayer;
53 import org.openide.ErrorManager;
54 import org.openide.NotifyDescriptor;
55 import org.openide.awt.StatusDisplayer;
56 import org.openide.nodes.AbstractNode;
57 import org.openide.nodes.Children;
58 import org.openide.nodes.Node;
59 import org.openide.util.NbBundle;
60 import org.openide.util.RequestProcessor;
61
62 /**
63  *
64  * @author Jeri Lockhart
65  */

66 public class QueryComplexTypeDerivations implements Query {
67     protected String JavaDoc displayName;
68     private WhereUsedExplorer customizer;
69     private SchemaModel model;
70     private String JavaDoc shortName;
71     private CustomizerResults results;
72     
73     /** Creates a new instance of QuerySubstitutionGroups */
74     public QueryComplexTypeDerivations(final SchemaModel model) {
75         super();
76         this.model = model;
77         setDisplayName(NbBundle.getMessage(QueryComplexTypeDerivations.class,
78                 "LBL_QueryComplexTypeDerivations"));
79         shortName = NbBundle.getMessage(QueryComplexTypeDerivations.class,
80                 "LBL_QueryComplexTypeDerivations_ShortName");
81     }
82     
83     
84     /**
85      * Setter for property displayName.
86      *
87      * @param displayName New value of property displayName.
88      */

89     public void setDisplayName(String JavaDoc displayName) {
90         this.displayName = displayName;
91     }
92     
93     
94     public String JavaDoc toString() {
95         return displayName;
96     }
97     
98     
99     
100     public SchemaModel getSchemaModel() {
101         return model;
102     }
103     
104     /**
105      * Setter for property shortName - used on customizer column button
106      *
107      * @param shortName New value of property shortName.
108      */

109     public void setShortName(String JavaDoc shortName) {
110         this.shortName = shortName;
111     }
112     
113     /**
114      * Getter for property shortName - used on customizer column button
115      *
116      * @return Value of property shortName.
117      */

118     public String JavaDoc getShortName() {
119         return shortName;
120     }
121     
122     public void runQuery(final QueryPanel queryPanel, final AnalysisViewer analysisViewer) {
123         showCustomizerDialog();
124         if (results != null && results.wasCanceled()){
125             return;
126         }
127         SchemaComponent selectedComponent = customizer.getSelectedSchemaComponent();
128         GlobalComplexType baseCT = null;
129         if (selectedComponent instanceof GlobalComplexType){
130             baseCT = (GlobalComplexType) selectedComponent;
131         }
132         else {
133             return;
134         }
135         final ComplexTypeDerivationsView view = new
136                 ComplexTypeDerivationsView( baseCT);
137         
138         RequestProcessor.getDefault().post(new Runnable JavaDoc(){
139             public void run() {
140                 ProgressHandle ph = ProgressHandleFactory.createHandle(
141                         NbBundle.getMessage(QueryComplexTypeDerivations.class,
142                         "LBL_Finding_Derivations"));
143                 ph.start();
144                 ph.switchToIndeterminate();
145                 view.createModels();
146                 if(Thread.currentThread().isInterrupted()){
147                     return;
148                 }
149                 ph.finish();
150                 SwingUtilities.invokeLater(new Runnable JavaDoc(){
151                     public void run() {
152                         
153                         if (view != null){
154                             if (!queryPanel.getIsVisible()) {
155                                 // dock it into output window area and display
156
QueryPanelContainer cont =
157                                         QueryPanelContainer.getUsagesComponent();
158                                 if (cont == null){
159                                     ErrorManager.getDefault().log(
160                                             ErrorManager.ERROR,
161                                             "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.");
162                                     return;
163                                 }
164                                 cont.open();
165                                 cont.requestActive();
166                                 cont.addPanel(queryPanel);
167                                 queryPanel.setIsVisible(true);
168                             }
169                             
170                             
171                             
172                             queryPanel.requestFocus();
173                             
174                             if (view != null){
175                                 view.showView(analysisViewer);
176                                 analysisViewer.validate();
177                                 analysisViewer.repaint();
178                             }
179                         }
180                     }
181                 });
182             }});
183     }
184     
185     
186     public CustomizerResults showCustomizerDialog() {
187         results = new CustomizerResults();
188         customizer = new CTExplorer(model);
189         results.setPanel(customizer);
190         String JavaDoc title = NbBundle.getMessage(
191                 QueryUnusedGlobals.class, "LBL_QueryComplexTypeDerivations_ShortName");
192         DialogDescriptor descriptor = new DialogDescriptor(customizer, 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         
204         return results;
205     }
206
207     public SchemaModel getModel() {
208         return model;
209     }
210     
211     
212     public class CTExplorer extends WhereUsedExplorer {
213         
214         static final private long serialVersionUID = 1L;
215         
216         public CTExplorer(SchemaModel model){
217             super( model);
218 // setNodePreferredAction(new ShowDerivationsAction());
219
}
220         
221         
222         
223         @Override JavaDoc
224         protected Node createTree() {
225             // the previewsMap is retrieved later by the view, when the
226
// query in invoked - Map<GlobalComplexType,Preview>
227
count = 0;
228             Schema schema = model.getSchema();
229             AbstractNode root = QueryUtilities.createCategoryNode(AnalysisConstants.GlobalTypes.BASE_COMPLEX_TYPES);
230             String JavaDoc icon_str = ICON_BASE + COMPLEX_TYPE_IMAGE;
231             root.setIconBaseWithExtension(icon_str);
232             
233             ArrayList JavaDoc<QueryCustomizerNode> baseCTs = new ArrayList JavaDoc<QueryCustomizerNode>();
234             // get all the global complex types (gct)
235
for(GlobalComplexType g : schema.getComplexTypes()) {
236                 createCustomizerNode(baseCTs, g, icon_str, false);
237             }
238             // Update Status Area
239
int count = baseCTs.size();
240             
241             if (count == 1) {
242                 StatusDisplayer.getDefault().setStatusText(
243                         NbBundle.getMessage(QueryComplexTypeDerivations.class,
244                         "LBL_1_ComplexType_with_Derivations_Found")
245                         );
246             } else {
247                 
248                 StatusDisplayer.getDefault().setStatusText(
249                         MessageFormat.format(NbBundle.getMessage(QueryComplexTypeDerivations.class,
250                         "LBL_ComplexTypes_with_Derivations_Found"),
251                         new Object JavaDoc[] {count
252                 }
253                 ));
254             }
255             root.getChildren().add((QueryCustomizerNode[]) baseCTs.toArray(new QueryCustomizerNode[baseCTs.size()]));
256             return root;
257         }
258         
259         
260         /**
261          *
262          * don't create duplicates
263          */

264         @Override JavaDoc
265                 protected void createCustomizerNode(List JavaDoc<QueryCustomizerNode> items, Named c, String JavaDoc icon_base_with_ext, boolean primitive){
266             QueryCustomizerNode n = null;
267             if (primitive){
268                 n = new QueryCustomizerNode(Children.LEAF, c, primitive, model);
269             } else {
270                 n = new QueryCustomizerNode(Children.LEAF, c, primitive);
271             }
272             
273             n.setIconBaseWithExtension(icon_base_with_ext);
274             n.setName(c.getName());
275             for (QueryCustomizerNode nn: items){
276                 if (nn.getSchemaComponent() == c){
277                     return;
278                 }
279             }
280             items.add(n);
281             if (!primitive){
282                 count++;
283             }
284         }
285         
286         
287     }
288     
289      
290     
291 }
292
Popular Tags