1 19 27 28 package org.netbeans.modules.xml.schema.refactoring.query; 29 30 import javax.swing.JDialog ; 31 import javax.swing.JPanel ; 32 import javax.swing.SwingUtilities ; 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 54 public class QueryUnusedGlobals implements Query { 55 56 private String shortName; 58 private String displayName; 59 private SchemaModel model; 60 Boolean excludeGEs; 62 private CustomizerResults results; 63 private QueryUnusedGlobalsView view; 64 65 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 79 public void setShortName(String shortName) { 80 this.shortName = shortName; 81 } 82 83 88 public void setDisplayName(String displayName) { 89 this.displayName = displayName; 90 } 91 92 97 public String getShortName() { 98 return shortName; 99 } 100 101 102 103 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 (){ 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); if (cancelSignal.isCancelRequested()){ 127 ph.finish(); 128 return; 129 } 130 137 ph.finish(); 141 SwingUtilities.invokeLater(new Runnable (){ 142 public void run() { 143 144 if (view != null){ 145 if (!queryPanel.getIsVisible()) { 146 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 165 if (view != null){ 166 view.showView(analysisViewer); 167 analysisViewer.validate(); 168 analysisViewer.repaint(); 169 } 171 } 172 } 173 }); 174 }}); 175 176 } 177 178 182 public String 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 title = NbBundle.getMessage( 191 QueryUnusedGlobals.class, "LBL_QueryUnusedGlobal_Display_Name"); 192 DialogDescriptor descriptor = new DialogDescriptor(panel, 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 return results; 204 } 205 206 210 214 private boolean getExcludeGEs(){ 215 if (results != null){ 216 JPanel 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 233 234 239 public class FUnCustomizer { 240 242 protected CustomizerResults[] constraints; 243 protected SchemaComponentReference[] references; 244 protected Query query; 245 protected QueryUnusedGlobalsCustomizerPanel panel; 246 247 248 public FUnCustomizer(Query query) { 249 super(); 250 this.query = query; 251 initialize(); 252 } 253 254 protected void initialize() { 255 panel = new QueryUnusedGlobalsCustomizerPanel(); 256 258 } 259 260 public void setExcludeElements(boolean exclude){ 261 panel.setExcludeElements(exclude); 262 } 263 264 265 269 270 271 } 305 } 306 | Popular Tags |