Revision 38564 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/extension/ShowDevelInfoExtension.java
ShowDevelInfoExtension.java | ||
---|---|---|
1 | 1 |
package org.gvsig.app.extension; |
2 | 2 |
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.event.ActionEvent; |
|
6 |
import java.awt.event.ActionListener; |
|
7 |
import java.io.File; |
|
8 |
import java.io.FileWriter; |
|
9 |
import java.io.IOException; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.Collections; |
|
12 |
import java.util.Comparator; |
|
13 |
import java.util.Iterator; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Set; |
|
16 |
import java.util.TreeSet; |
|
17 |
|
|
18 |
import javax.swing.BorderFactory; |
|
19 |
import javax.swing.Box; |
|
20 |
import javax.swing.BoxLayout; |
|
21 |
import javax.swing.JButton; |
|
22 |
import javax.swing.JPanel; |
|
23 |
import javax.swing.JScrollPane; |
|
24 |
import javax.swing.JTextPane; |
|
25 |
|
|
26 |
import org.gvsig.andami.iconthemes.IIconTheme; |
|
27 |
import org.gvsig.andami.iconthemes.IconThemeManager; |
|
28 | 3 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.andami.ui.mdiManager.MDIManager.UIActionTool; |
|
30 |
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory; |
|
31 |
import org.gvsig.app.ApplicationLocator; |
|
4 |
import org.gvsig.app.extension.develtools.ActionsInfoDevelTool; |
|
5 |
import org.gvsig.app.extension.develtools.IconThemeDevelTool; |
|
6 |
import org.gvsig.app.extension.develtools.MenusDevelTool; |
|
7 |
import org.gvsig.app.extension.develtools.PersistenceDevelTool; |
|
32 | 8 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
34 |
import org.gvsig.tools.dynobject.DynField; |
|
35 |
import org.gvsig.tools.dynobject.DynStruct; |
|
36 |
import org.gvsig.tools.persistence.PersistenceFactory; |
|
37 | 9 |
import org.gvsig.tools.persistence.PersistenceManager; |
38 |
import org.gvsig.tools.persistence.Persistent; |
|
39 | 10 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
41 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
42 | 11 |
import org.slf4j.Logger; |
43 | 12 |
import org.slf4j.LoggerFactory; |
44 | 13 |
|
45 | 14 |
public class ShowDevelInfoExtension extends Extension { |
46 | 15 |
|
47 |
private Logger logger = LoggerFactory |
|
16 |
private static Logger logger = LoggerFactory
|
|
48 | 17 |
.getLogger(ShowDevelInfoExtension.class); |
49 | 18 |
|
50 | 19 |
public void initialize() { |
... | ... | |
66 | 35 |
} |
67 | 36 |
|
68 | 37 |
public void execute(String actionCommand) { |
69 |
if ("ShowPersistenceFactories".equalsIgnoreCase(actionCommand)) { |
|
70 |
showInfoPanel("Persistence factories", WindowManager.MODE.WINDOW, |
|
71 |
this.getPersistenceFactories()); |
|
72 |
} else if ("ShowIconThemeInformation".equalsIgnoreCase(actionCommand)) { |
|
73 |
showInfoPanel("Icon theme information", WindowManager.MODE.WINDOW, |
|
74 |
this.getIconThemeInformation()); |
|
75 |
} else if ("ShowActionsInformation".equalsIgnoreCase(actionCommand)) { |
|
76 |
showInfoPanel("Actions information", WindowManager.MODE.WINDOW, |
|
77 |
this.getActionsInformation()); |
|
38 |
if ("tools-devel-show-persistencefactories".equalsIgnoreCase(actionCommand)) { |
|
39 |
new PersistenceDevelTool().showPersistenceFactories(); |
|
40 |
} else if ("tools-devel-show-icontheme".equalsIgnoreCase(actionCommand)) { |
|
41 |
new IconThemeDevelTool().showDefaultIconTheme(); |
|
42 |
} else if ("tools-devel-show-actions".equalsIgnoreCase(actionCommand)) { |
|
43 |
new ActionsInfoDevelTool().showActions(); |
|
44 |
} else if ("tools-devel-show-menus".equalsIgnoreCase(actionCommand)) { |
|
45 |
new MenusDevelTool().showAllMenus(); |
|
46 |
} else if ("tools-devel-show-menus-by-plugin".equalsIgnoreCase(actionCommand)) { |
|
47 |
new MenusDevelTool().showAllMenusByPlugin(); |
|
78 | 48 |
} |
79 |
|
|
80 | 49 |
} |
81 | 50 |
|
82 |
private String getActionsInformation() { |
|
83 |
StringBuffer buffer = new StringBuffer(); |
|
84 | 51 |
|
85 |
buffer.append("<html>\n"); |
|
86 |
buffer.append("<body>\n"); |
|
87 |
buffer.append("<h2>Actions information</h2>\n"); |
|
88 |
buffer.append("<br>\n"); |
|
89 |
|
|
90 |
buffer.append("<table border=\"0\">\n"); |
|
91 |
buffer.append(" <tr>\n"); |
|
92 |
buffer.append(" <td>Name</td>\n"); |
|
93 |
buffer.append(" <td>Extension</td>\n"); |
|
94 |
buffer.append(" <td>Position</td>\n"); |
|
95 |
buffer.append(" <td>Text</td>\n"); |
|
96 |
buffer.append(" <td>Command</td>\n"); |
|
97 |
buffer.append(" <td>Icon</td>\n"); |
|
98 |
buffer.append(" <td>Tip</td>\n"); |
|
99 |
buffer.append(" <td>Enabled text</td>\n"); |
|
100 |
buffer.append(" </tr>\n"); |
|
101 |
Iterator<UIActionTool> actions = MDIManagerFactory.createManager() |
|
102 |
.getActionTools(); |
|
103 |
while (actions.hasNext()) { |
|
104 |
UIActionTool action = actions.next(); |
|
105 |
buffer.append(" <tr>\n"); |
|
106 |
buffer.append(" <td>").append(action.getName()) |
|
107 |
.append("</td>\n"); |
|
108 |
buffer.append(" <td>").append(action.getExtensionName()) |
|
109 |
.append("</td>\n"); |
|
110 |
buffer.append(" <td>").append(action.getPosition()) |
|
111 |
.append("</td>\n"); |
|
112 |
buffer.append(" <td>").append(action.getText()) |
|
113 |
.append("</td>\n"); |
|
114 |
buffer.append(" <td>").append(action.getCommand()) |
|
115 |
.append("</td>\n"); |
|
116 |
buffer.append(" <td>").append(action.getIconName()) |
|
117 |
.append("</td>\n"); |
|
118 |
buffer.append(" <td>").append(action.getTooptip()) |
|
119 |
.append("</td>\n"); |
|
120 |
buffer.append(" <td>").append(action.getEnableText()) |
|
121 |
.append("</td>\n"); |
|
122 |
buffer.append(" </tr>\n"); |
|
123 |
} |
|
124 |
buffer.append("</table>\n"); |
|
125 |
buffer.append("</body>\n"); |
|
126 |
buffer.append("</html>\n"); |
|
127 |
|
|
128 |
save2file("actionsinfo", buffer.toString()); |
|
129 |
|
|
130 |
return buffer.toString(); |
|
131 |
} |
|
132 |
|
|
133 |
private String getIconThemeInformation() { |
|
134 |
StringBuffer buffer = new StringBuffer(); |
|
135 |
|
|
136 |
IconThemeManager manager = IconThemeManager.getIconThemeManager(); |
|
137 |
IIconTheme theme = manager.getCurrent(); |
|
138 |
|
|
139 |
buffer.append("<html>\n"); |
|
140 |
buffer.append("<body>\n"); |
|
141 |
buffer.append("<h2>Icon theme information</h2>\n"); |
|
142 |
buffer.append("<br>\n"); |
|
143 |
buffer.append("Theme: "); |
|
144 |
buffer.append(theme.getName()); |
|
145 |
buffer.append("<br>\n"); |
|
146 |
buffer.append("Description: "); |
|
147 |
buffer.append(theme.getDescription()); |
|
148 |
buffer.append("<br>\n"); |
|
149 |
buffer.append("Version: "); |
|
150 |
buffer.append(theme.getVersion()); |
|
151 |
buffer.append("<br>\n"); |
|
152 |
|
|
153 |
buffer.append("<table border=\"0\">\n"); |
|
154 |
buffer.append(" <tr>\n"); |
|
155 |
buffer.append(" <td>Name</td>\n"); |
|
156 |
buffer.append(" <td>Resource id</td>\n"); |
|
157 |
buffer.append(" </tr>\n"); |
|
158 |
Iterator<String> names = theme.iterator(); |
|
159 |
while (names.hasNext()) { |
|
160 |
String name = names.next(); |
|
161 |
buffer.append(" <tr>\n"); |
|
162 |
buffer.append(" <td>").append(name).append("</td>\n"); |
|
163 |
buffer.append(" <td>").append(theme.getResourceID(name)) |
|
164 |
.append("</td>\n"); |
|
165 |
buffer.append(" </tr>\n"); |
|
166 |
} |
|
167 |
buffer.append("</table>\n"); |
|
168 |
buffer.append("</body>\n"); |
|
169 |
buffer.append("</html>\n"); |
|
170 |
|
|
171 |
save2file("iconthemeinfo", buffer.toString()); |
|
172 |
|
|
173 |
return buffer.toString(); |
|
174 |
} |
|
175 |
|
|
176 |
private void save2file(String name, String contents) { |
|
177 |
File file; |
|
178 |
try { |
|
179 |
file = File.createTempFile("gvsig-" + name, ".html"); |
|
180 |
FileWriter fwriter = new FileWriter(file); |
|
181 |
fwriter.append(contents); |
|
182 |
fwriter.close(); |
|
183 |
} catch (IOException e) { |
|
184 |
logger.warn("Can't save contents to temp file gvsig-" + name, e); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 | 52 |
public boolean isEnabled() { |
189 | 53 |
return true; |
190 | 54 |
} |
... | ... | |
192 | 56 |
public boolean isVisible() { |
193 | 57 |
return true; |
194 | 58 |
} |
195 |
|
|
196 |
private void showInfoPanel(String title, WindowManager.MODE mode, |
|
197 |
String html) { |
|
198 |
JPanel panel = new JInfoPanel(html); |
|
199 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
|
200 |
wm.showWindow(panel, title, mode); |
|
201 |
} |
|
202 |
|
|
203 |
private class JInfoPanel extends JPanel { |
|
204 |
/** |
|
205 |
* |
|
206 |
*/ |
|
207 |
private static final long serialVersionUID = 7164653790859770568L; |
|
208 |
|
|
209 |
private JButton accept = null; |
|
210 |
private JButton copy = null; |
|
211 |
private JTextPane text = null; |
|
212 |
|
|
213 |
public JInfoPanel(final String html) { |
|
214 |
this.setLayout(new BorderLayout()); |
|
215 |
this.setPreferredSize(new Dimension(500, 300)); |
|
216 |
this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
|
217 |
|
|
218 |
text = new JTextPane(); |
|
219 |
text.setContentType("text/html"); |
|
220 |
text.setEditable(false); |
|
221 |
text.setText(html); |
|
222 |
text.setCaretPosition(0); |
|
223 |
|
|
224 |
JScrollPane scrollPane = new JScrollPane(text); |
|
225 |
scrollPane.setPreferredSize(new Dimension(500, 220)); |
|
226 |
|
|
227 |
accept = new JButton("Accept"); |
|
228 |
accept.addActionListener(new ActionListener() { |
|
229 |
public void actionPerformed(ActionEvent arg0) { |
|
230 |
setVisible(false); |
|
231 |
} |
|
232 |
}); |
|
233 |
copy = new JButton("Copy to clipboard"); |
|
234 |
copy.addActionListener(new ActionListener() { |
|
235 |
public void actionPerformed(ActionEvent arg0) { |
|
236 |
ApplicationLocator.getManager().putInClipboard( |
|
237 |
text.getText()); |
|
238 |
} |
|
239 |
}); |
|
240 |
|
|
241 |
JPanel buttonsPanel = new JPanel(); |
|
242 |
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, |
|
243 |
BoxLayout.LINE_AXIS)); |
|
244 |
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
|
245 |
|
|
246 |
buttonsPanel.add(Box.createHorizontalGlue()); |
|
247 |
buttonsPanel.add(copy); |
|
248 |
buttonsPanel.add(accept); |
|
249 |
|
|
250 |
this.add(scrollPane, BorderLayout.CENTER); |
|
251 |
this.add(buttonsPanel, BorderLayout.SOUTH); |
|
252 |
this.setVisible(true); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
public class PersistenceInfo implements Comparable<PersistenceInfo> { |
|
257 |
PersistenceFactory factory; |
|
258 |
@SuppressWarnings("rawtypes") |
|
259 |
Class theClass; |
|
260 |
DynStruct definition; |
|
261 |
|
|
262 |
PersistenceInfo(PersistenceFactory factory, |
|
263 |
@SuppressWarnings("rawtypes") Class theClass, |
|
264 |
DynStruct definition) { |
|
265 |
this.factory = factory; |
|
266 |
this.theClass = theClass; |
|
267 |
this.definition = definition; |
|
268 |
} |
|
269 |
|
|
270 |
String getDefinitionName() { |
|
271 |
if (definition == null) { |
|
272 |
return ""; |
|
273 |
} |
|
274 |
return definition.getFullName(); |
|
275 |
} |
|
276 |
|
|
277 |
String getDefinitionDescription() { |
|
278 |
if (definition == null) { |
|
279 |
return ""; |
|
280 |
} |
|
281 |
return definition.getDescription(); |
|
282 |
} |
|
283 |
|
|
284 |
String getClassName() { |
|
285 |
if (theClass == null) { |
|
286 |
return ""; |
|
287 |
} |
|
288 |
return theClass.getName(); |
|
289 |
} |
|
290 |
|
|
291 |
String getFactoryName() { |
|
292 |
if (factory == null) { |
|
293 |
return ""; |
|
294 |
} |
|
295 |
return factory.getClass().getName(); |
|
296 |
} |
|
297 |
|
|
298 |
public int compareTo(PersistenceInfo other) { |
|
299 |
int r = this.factory.getClass().getName() |
|
300 |
.compareTo(other.factory.getClass().getName()); |
|
301 |
if (r == 0) { |
|
302 |
return this.theClass.getName().compareTo( |
|
303 |
other.theClass.getName()); |
|
304 |
} |
|
305 |
return r; |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
@SuppressWarnings("rawtypes") |
|
310 |
public class ClassComparator implements Comparator { |
|
311 |
|
|
312 |
public int compare(Object o1, Object o2) { |
|
313 |
if (o1 == null || o2 == null || ((Class) o1).getName() == null) { |
|
314 |
logger.warn("Esto no deberia estar pasando."); |
|
315 |
return 0; // FIXME |
|
316 |
} |
|
317 |
return ((Class) o1).getName().compareTo(((Class) o2).getName()); |
|
318 |
} |
|
319 |
|
|
320 |
} |
|
321 |
|
|
322 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
323 |
private String getPersistenceFactories() { |
|
324 |
int warningsCounter = 0; |
|
325 |
List<PersistenceInfo> classes = new ArrayList<PersistenceInfo>(); |
|
326 |
Set<Class> referencedClasses = new TreeSet<Class>(new ClassComparator()); |
|
327 |
|
|
328 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
329 |
|
|
330 |
List<PersistenceFactory> factories = manager.getFactories(); |
|
331 |
for (PersistenceFactory factory : factories) { |
|
332 |
List<Class> theClasses = factory.getManagedClasses(); |
|
333 |
for (Class theClass : theClasses) { |
|
334 |
|
|
335 |
DynStruct definition = manager.getDefinition(theClass); |
|
336 |
List defs = factory.getDefinitions(); |
|
337 |
if (definition == null && defs != null && !defs.isEmpty()) { |
|
338 |
for (int i = 0; i < defs.size(); i++) { |
|
339 |
definition = (DynStruct) defs.get(i); |
|
340 |
classes.add(new PersistenceInfo(factory, theClass, |
|
341 |
definition)); |
|
342 |
} |
|
343 |
} else { |
|
344 |
classes.add(new PersistenceInfo(factory, theClass, |
|
345 |
definition)); |
|
346 |
} |
|
347 |
} |
|
348 |
} |
|
349 |
Collections.sort(classes); |
|
350 |
|
|
351 |
StringBuffer buffer = new StringBuffer(); |
|
352 |
StringBuffer warnings = new StringBuffer(); |
|
353 |
|
|
354 |
buffer.append("<html>\n"); |
|
355 |
buffer.append("<body>\n"); |
|
356 |
buffer.append("<h2>Supported persistent classes</h2>\n"); |
|
357 |
buffer.append("<br>\n"); |
|
358 |
|
|
359 |
buffer.append("<ol>\n"); |
|
360 |
for (PersistenceInfo classInfo : classes) { |
|
361 |
StringBuffer classBuffer = new StringBuffer(); |
|
362 |
boolean warning = false; |
|
363 |
classBuffer.append(" <li>\n "); |
|
364 |
classBuffer.append("Class: <i>"); |
|
365 |
classBuffer.append(classInfo.getClassName()); |
|
366 |
classBuffer.append("</i><br>\n Persistent: <i>"); |
|
367 |
if (Persistent.class.isAssignableFrom(classInfo.theClass)) { |
|
368 |
classBuffer.append(" yes."); |
|
369 |
} else { |
|
370 |
classBuffer.append(" through a factory."); |
|
371 |
} |
|
372 |
classBuffer.append("<br>\n Factory: <i>"); |
|
373 |
classBuffer.append(classInfo.getFactoryName()).append( |
|
374 |
"</i><br>\n Definition name: <i>"); |
|
375 |
classBuffer.append(classInfo.getDefinitionName()).append( |
|
376 |
"</i><br>\n Description: \n"); |
|
377 |
classBuffer.append(classInfo.getDefinitionDescription()).append( |
|
378 |
"<br>\n "); |
|
379 |
DataTypesManager dataTypesManager = ToolsLocator |
|
380 |
.getDataTypesManager(); |
|
381 |
DynStruct definition = classInfo.definition; |
|
382 |
if (definition == null) { |
|
383 |
classBuffer.append("Definition for ") |
|
384 |
.append(classInfo.getClassName()) |
|
385 |
.append(" is null.<br>\n "); |
|
386 |
warningsCounter++; |
|
387 |
warning = true; |
|
388 |
} else { |
|
389 |
DynField[] fields = definition.getDynFields(); |
|
390 |
for (int i = 0; i < fields.length; i++) { |
|
391 |
DynField field = fields[i]; |
|
392 |
if (dataTypesManager.isContainer(field.getType())) { |
|
393 |
if (field.getClassOfItems() == null) { |
|
394 |
classBuffer |
|
395 |
.append("Field <b>") |
|
396 |
.append(field.getName()) |
|
397 |
.append("</b>, container, can't has class for value of items.<br>\n "); |
|
398 |
warningsCounter++; |
|
399 |
warning = true; |
|
400 |
} else { |
|
401 |
classBuffer.append("Field ") |
|
402 |
.append(field.getName()) |
|
403 |
.append(", container of '") |
|
404 |
.append(field.getClassOfItems().getName()) |
|
405 |
.append("'.<br>\n "); |
|
406 |
referencedClasses.add(field.getClassOfItems()); |
|
407 |
} |
|
408 |
} else if (dataTypesManager.isObject(field.getType())) { |
|
409 |
if (field.getClassOfValue() == null) { |
|
410 |
classBuffer |
|
411 |
.append("Field <b>") |
|
412 |
.append(field.getName()) |
|
413 |
.append("</b> can't has class of value.<br>\n "); |
|
414 |
warningsCounter++; |
|
415 |
warning = true; |
|
416 |
} else { |
|
417 |
classBuffer.append("Field ") |
|
418 |
.append(field.getName()).append(" of '") |
|
419 |
.append(field.getClassOfValue()) |
|
420 |
.append("'.<br>\n "); |
|
421 |
referencedClasses.add(field.getClassOfValue()); |
|
422 |
} |
|
423 |
} |
|
424 |
} |
|
425 |
} |
|
426 |
classBuffer.append("<br>\n </li>\n"); |
|
427 |
buffer.append(classBuffer); |
|
428 |
if (warning) { |
|
429 |
warnings.append(classBuffer); |
|
430 |
} |
|
431 |
} |
|
432 |
buffer.append("</ol>\n"); |
|
433 |
buffer.append("<br>\n"); |
|
434 |
buffer.append("<br>\n"); |
|
435 |
|
|
436 |
buffer.append("<h2>Persistent classes with problems</h2>\n"); |
|
437 |
buffer.append("<ol>\n"); |
|
438 |
buffer.append(warnings); |
|
439 |
buffer.append("</ol>\n"); |
|
440 |
buffer.append("<br>\n<p>Total warnigs: ").append(warningsCounter) |
|
441 |
.append("</p>"); |
|
442 |
|
|
443 |
buffer.append("<h2>Not persistents used classes</h2>\n"); |
|
444 |
buffer.append("<ol>\n"); |
|
445 |
for (Class theClass : referencedClasses) { |
|
446 |
// if( manager.canPersist(theClass) ) { |
|
447 |
// continue; |
|
448 |
// } |
|
449 |
if (Persistent.class.isAssignableFrom(theClass)) { |
|
450 |
continue; |
|
451 |
} |
|
452 |
if (manager.getFactories().get(theClass) != null) { |
|
453 |
continue; |
|
454 |
} |
|
455 |
buffer.append(" <li>\n"); |
|
456 |
buffer.append(" <i>").append(theClass.getName()) |
|
457 |
.append("</i><br>\n"); |
|
458 |
buffer.append(" </li>\n"); |
|
459 |
warningsCounter++; |
|
460 |
} |
|
461 |
buffer.append("</ol>\n"); |
|
462 |
|
|
463 |
buffer.append("</body>\n"); |
|
464 |
buffer.append("</html>\n"); |
|
465 |
|
|
466 |
save2file("persistenceinfo", buffer.toString()); |
|
467 |
|
|
468 |
return buffer.toString(); |
|
469 |
} |
|
470 |
|
|
471 | 59 |
} |
Also available in: Unified diff