1 19 20 28 29 package org.netbeans.modules.xml.schema.refactoring.query; 30 31 import java.text.MessageFormat ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 import javax.swing.JDialog ; 35 import javax.swing.SwingUtilities ; 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 66 public class QueryComplexTypeDerivations implements Query { 67 protected String displayName; 68 private WhereUsedExplorer customizer; 69 private SchemaModel model; 70 private String shortName; 71 private CustomizerResults results; 72 73 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 89 public void setDisplayName(String displayName) { 90 this.displayName = displayName; 91 } 92 93 94 public String toString() { 95 return displayName; 96 } 97 98 99 100 public SchemaModel getSchemaModel() { 101 return model; 102 } 103 104 109 public void setShortName(String shortName) { 110 this.shortName = shortName; 111 } 112 113 118 public String 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 (){ 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 (){ 151 public void run() { 152 153 if (view != null){ 154 if (!queryPanel.getIsVisible()) { 155 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 title = NbBundle.getMessage( 191 QueryUnusedGlobals.class, "LBL_QueryComplexTypeDerivations_ShortName"); 192 DialogDescriptor descriptor = new DialogDescriptor(customizer, title); 193 JDialog dialog = (JDialog ) DialogDisplayer.getDefault().createDialog(descriptor); 194 dialog.setTitle(title); 195 dialog.validate(); 196 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 } 220 221 222 223 @Override 224 protected Node createTree() { 225 count = 0; 228 Schema schema = model.getSchema(); 229 AbstractNode root = QueryUtilities.createCategoryNode(AnalysisConstants.GlobalTypes.BASE_COMPLEX_TYPES); 230 String icon_str = ICON_BASE + COMPLEX_TYPE_IMAGE; 231 root.setIconBaseWithExtension(icon_str); 232 233 ArrayList <QueryCustomizerNode> baseCTs = new ArrayList <QueryCustomizerNode>(); 234 for(GlobalComplexType g : schema.getComplexTypes()) { 236 createCustomizerNode(baseCTs, g, icon_str, false); 237 } 238 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 [] {count 252 } 253 )); 254 } 255 root.getChildren().add((QueryCustomizerNode[]) baseCTs.toArray(new QueryCustomizerNode[baseCTs.size()])); 256 return root; 257 } 258 259 260 264 @Override 265 protected void createCustomizerNode(List <QueryCustomizerNode> items, Named c, String 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 |