svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / develtools / MenusDevelTool.java @ 39104
History | View | Annotate | Download (4.16 KB)
1 | 38564 | jjdelcerro | package org.gvsig.app.extension.develtools; |
---|---|---|---|
2 | |||
3 | 38763 | jjdelcerro | import java.util.ArrayList; |
4 | 38564 | jjdelcerro | import java.util.Collections; |
5 | import java.util.Comparator; |
||
6 | import java.util.List; |
||
7 | |||
8 | import org.gvsig.andami.Launcher; |
||
9 | import org.gvsig.andami.Launcher.PluginMenuItem; |
||
10 | import org.gvsig.andami.actioninfo.ActionInfo; |
||
11 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
12 | |||
13 | public class MenusDevelTool { |
||
14 | public void showAllMenus() { |
||
15 | 38763 | jjdelcerro | String html = "<html>\n<body>\n"+ this.getAllMenus()+"</body>\n</html>\n"; |
16 | InfoPanel.save2file("menus-report", html);
|
||
17 | 38564 | jjdelcerro | InfoPanel.showPanel("Menu information", WindowManager.MODE.WINDOW, html);
|
18 | } |
||
19 | public void showAllMenusByPlugin() { |
||
20 | 38763 | jjdelcerro | String html = "<html>\n<body>\n"+ this.getAllMenusByPlugin()+"</body>\n</html>\n"; |
21 | InfoPanel.save2file("menus-report-sorted-by-plugin", html);
|
||
22 | 38564 | jjdelcerro | InfoPanel.showPanel("Menu by plugin information", WindowManager.MODE.WINDOW, html);
|
23 | } |
||
24 | |||
25 | public String getAllMenus() { |
||
26 | Launcher launcher = Launcher.getInstance(); |
||
27 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
28 | |||
29 | return this.getAllMenus(menuItems); |
||
30 | } |
||
31 | |||
32 | 38763 | jjdelcerro | public String getMenusOfPlugin(String pluginName) { |
33 | Launcher launcher = Launcher.getInstance(); |
||
34 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
35 | List<PluginMenuItem> pluginMenus = new ArrayList<Launcher.PluginMenuItem>(); |
||
36 | |||
37 | for (PluginMenuItem pluginMenuItem : menuItems) {
|
||
38 | if( pluginName.equalsIgnoreCase(pluginMenuItem.getPluginName())) {
|
||
39 | pluginMenus.add(pluginMenuItem); |
||
40 | } |
||
41 | } |
||
42 | if( pluginMenus.isEmpty() ) {
|
||
43 | return ""; |
||
44 | } |
||
45 | return this.getAllMenus(pluginMenus); |
||
46 | } |
||
47 | |||
48 | |||
49 | 38564 | jjdelcerro | public String getAllMenusByPlugin() { |
50 | Launcher launcher = Launcher.getInstance(); |
||
51 | List<PluginMenuItem> menuItems = launcher.getPluginMenuItems();
|
||
52 | |||
53 | Collections.sort(menuItems, new Comparator<PluginMenuItem>() { |
||
54 | public int compare(PluginMenuItem o1, PluginMenuItem o2) { |
||
55 | String s1 = String.format("%s:%012d:%s", o1.getPluginName(), o1.getPosition(), o1.getText()); |
||
56 | String s2 = String.format("%s:%012d:%s", o2.getPluginName(), o2.getPosition(), o2.getText()); |
||
57 | return s1.compareTo(s2);
|
||
58 | } |
||
59 | }); |
||
60 | return this.getAllMenus(menuItems); |
||
61 | } |
||
62 | |||
63 | private String getAllMenus(List<PluginMenuItem> menuItems) { |
||
64 | StringBuffer buffer = new StringBuffer(); |
||
65 | |||
66 | // String warning_open = "<b>";
|
||
67 | // String warning_close = "</b>";
|
||
68 | |||
69 | String error_open = "<b><font color=\"red\">"; |
||
70 | String error_close = "</font></b>"; |
||
71 | |||
72 | 38763 | jjdelcerro | buffer.append("<div>\n");
|
73 | 38564 | jjdelcerro | buffer.append("<h2>Menu information </h2>\n");
|
74 | buffer.append("<br>\n");
|
||
75 | |||
76 | buffer.append("<table border=\"0\">\n");
|
||
77 | buffer.append(" <tr>\n");
|
||
78 | buffer.append(" <td>Position</td>\n");
|
||
79 | buffer.append(" <td>Text</td>\n");
|
||
80 | buffer.append(" <td>Action</td>\n");
|
||
81 | buffer.append(" <td>Plugin</td>\n");
|
||
82 | buffer.append(" </tr>\n");
|
||
83 | |||
84 | |||
85 | for (PluginMenuItem menu : menuItems) {
|
||
86 | buffer.append(" <tr valign=\"top\">\n");
|
||
87 | buffer |
||
88 | .append(" <td>")
|
||
89 | 38608 | jjdelcerro | .append(formatPosition( menu.getPosition())) |
90 | 38564 | jjdelcerro | .append("</td>\n");
|
91 | buffer |
||
92 | .append(" <td>")
|
||
93 | .append(menu.getText()) |
||
94 | .append("</td>\n");
|
||
95 | if( menu.isParent() ) {
|
||
96 | buffer |
||
97 | .append(" <td>")
|
||
98 | .append("----")
|
||
99 | .append("</td>\n");
|
||
100 | buffer |
||
101 | .append(" <td>")
|
||
102 | .append(menu.getPluginName()) |
||
103 | .append("</td>\n");
|
||
104 | } else {
|
||
105 | ActionInfo action = menu.getAction(); |
||
106 | if( action == null ) { |
||
107 | buffer |
||
108 | .append(" <td>")
|
||
109 | .append(error_open) |
||
110 | .append(menu.getName()) |
||
111 | .append(error_close) |
||
112 | .append("</td>\n");
|
||
113 | buffer |
||
114 | .append(" <td>")
|
||
115 | .append(menu.getPluginName()) |
||
116 | .append("</td>\n");
|
||
117 | } else {
|
||
118 | buffer |
||
119 | .append(" <td>")
|
||
120 | .append(action.getName()) |
||
121 | .append("</td>\n");
|
||
122 | buffer |
||
123 | .append(" <td>")
|
||
124 | .append(action.getPluginName()) |
||
125 | .append("</td>\n");
|
||
126 | } |
||
127 | } |
||
128 | buffer.append(" </tr>\n");
|
||
129 | } |
||
130 | buffer.append("</table>\n");
|
||
131 | 38763 | jjdelcerro | buffer.append("</div>\n");
|
132 | 38564 | jjdelcerro | |
133 | return buffer.toString();
|
||
134 | } |
||
135 | 38608 | jjdelcerro | |
136 | static String formatPosition(long position) { |
||
137 | String pos = String.format("%012d",position); |
||
138 | if( pos.length() != 12) { |
||
139 | return pos;
|
||
140 | } |
||
141 | String posf = pos.substring(0, 5) + "-" + |
||
142 | pos.substring(5,8) + "-" + |
||
143 | pos.substring(8,11) + "-" + |
||
144 | pos.substring(11);
|
||
145 | return posf;
|
||
146 | } |
||
147 | 38564 | jjdelcerro | } |