svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / DefaultLayoutManager.java @ 1714
History | View | Annotate | Download (16.4 KB)
1 | 5 | jldominguez | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.app.project.documents.layout; |
||
23 | |||
24 | import java.awt.geom.AffineTransform; |
||
25 | import java.lang.reflect.Array; |
||
26 | import java.text.NumberFormat; |
||
27 | import java.util.ArrayList; |
||
28 | import java.util.Arrays; |
||
29 | import java.util.Comparator; |
||
30 | import java.util.Iterator; |
||
31 | import java.util.List; |
||
32 | import javax.swing.ImageIcon; |
||
33 | import org.gvsig.andami.PluginServices; |
||
34 | 216 | cmartinez | import org.gvsig.andami.PluginsLocator; |
35 | 5 | jldominguez | import org.gvsig.andami.messages.NotificationManager; |
36 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
37 | 216 | cmartinez | import org.gvsig.app.gui.preferencespage.PreferenceKeys; |
38 | 5 | jldominguez | import org.gvsig.app.project.ProjectManager; |
39 | import org.gvsig.app.project.documents.AbstractDocument; |
||
40 | import org.gvsig.app.project.documents.AbstractDocumentManager; |
||
41 | import org.gvsig.app.project.documents.Document; |
||
42 | 345 | cmartinez | import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
43 | import org.gvsig.app.project.documents.actions.CutDocumentAction; |
||
44 | import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
||
45 | 5 | jldominguez | import org.gvsig.app.project.documents.gui.WindowLayout; |
46 | import org.gvsig.app.project.documents.layout.contextmenu.gui.AbstractLayoutContextMenuAction; |
||
47 | import org.gvsig.app.project.documents.layout.fframes.FrameFactory; |
||
48 | import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
||
49 | 1714 | fdiaz | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel; |
50 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.gui.DefaultLayoutPanel; |
51 | import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
||
52 | 376 | cmartinez | import org.gvsig.app.project.documents.layout.gui.LayoutPanelImpl; |
53 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.gui.MapProperties; |
54 | import org.gvsig.app.project.documents.view.IContextMenuAction; |
||
55 | 1714 | fdiaz | import org.gvsig.layout.mapbox.MapBoxUtils; |
56 | 5 | jldominguez | import org.gvsig.tools.ToolsLocator; |
57 | import org.gvsig.tools.dynobject.DynStruct; |
||
58 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
59 | import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
||
60 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
61 | import org.gvsig.tools.persistence.PersistenceManager; |
||
62 | 216 | cmartinez | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
63 | 5 | jldominguez | import org.gvsig.utils.XMLEntity; |
64 | 216 | cmartinez | import org.slf4j.Logger; |
65 | import org.slf4j.LoggerFactory; |
||
66 | 5 | jldominguez | |
67 | /**
|
||
68 | * Factory of maps.
|
||
69 | *
|
||
70 | * @author Vicente Caballero Navarro
|
||
71 | */
|
||
72 | public class DefaultLayoutManager extends AbstractDocumentManager implements |
||
73 | LayoutManager {
|
||
74 | static final Logger LOG = LoggerFactory |
||
75 | .getLogger(DefaultLayoutManager.class); |
||
76 | |||
77 | static final String KEY_LAYOUT_FFRAMEDIALOG = |
||
78 | "app.project.documents.layout.fframes.gui";
|
||
79 | static final String KEY_LAYOUT_FFRAME = |
||
80 | "app.project.documents.layout.fframes";
|
||
81 | |||
82 | 147 | cmartinez | public static final String PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME = |
83 | 5 | jldominguez | "LayoutDocument";
|
84 | |||
85 | private static final String LAYOUT_CONTEXT_MENUS = "Layout_ContextMenus"; |
||
86 | |||
87 | ExtensionPointManager extensionPoints = ToolsLocator |
||
88 | .getExtensionPointManager(); |
||
89 | |||
90 | private Boolean defaultShowGrid = null; |
||
91 | private Boolean defaultAdjustToGrid = null; |
||
92 | private Boolean defaultShowRulers = null; |
||
93 | |||
94 | private DynStruct persistenceDefinition;
|
||
95 | |||
96 | /**
|
||
97 | * Returns image of button.
|
||
98 | *
|
||
99 | * @return Image button.
|
||
100 | */
|
||
101 | 1714 | fdiaz | @Override
|
102 | 5 | jldominguez | public ImageIcon getIcon() { |
103 | 216 | cmartinez | return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon"); |
104 | 5 | jldominguez | } |
105 | |||
106 | /**
|
||
107 | * Returns image of selected button.
|
||
108 | *
|
||
109 | * @return Image button.
|
||
110 | */
|
||
111 | 1714 | fdiaz | @Override
|
112 | 5 | jldominguez | public ImageIcon getIconSelected() { |
113 | 216 | cmartinez | return ToolsSwingLocator.getIconThemeManager().getCurrent().get("document-map-icon-sel"); |
114 | 5 | jldominguez | } |
115 | |||
116 | /**
|
||
117 | * Returns the name of registration in the point of extension.
|
||
118 | *
|
||
119 | * @return Name of registration
|
||
120 | */
|
||
121 | 1714 | fdiaz | @Override
|
122 | 5 | jldominguez | public String getTypeName() { |
123 | return TYPENAME;
|
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * Returns the name of ProjectDocument.
|
||
128 | *
|
||
129 | * @return Name of ProjectDocument.
|
||
130 | */
|
||
131 | 1714 | fdiaz | @Override
|
132 | 5 | jldominguez | public String getTitle() { |
133 | 262 | cmartinez | return PluginServices.getText(this, "Mapa"); |
134 | 5 | jldominguez | } |
135 | |||
136 | 1714 | fdiaz | @Override
|
137 | 5 | jldominguez | public AbstractDocument createDocument() { |
138 | return new DefaultLayoutDocument(this); |
||
139 | } |
||
140 | |||
141 | 1714 | fdiaz | @Override
|
142 | 5 | jldominguez | public Class getMainWindowClass() { |
143 | 376 | cmartinez | return LayoutPanelImpl.class;
|
144 | 5 | jldominguez | } |
145 | |||
146 | 1714 | fdiaz | @Override
|
147 | 5 | jldominguez | public IWindow getMainWindow(Document doc, WindowLayout layout) { |
148 | 567 | jjdelcerro | LayoutPanel layoutPanel = (LayoutPanel) super.getMainWindow(doc, layout);
|
149 | if (layoutPanel == null) { |
||
150 | layoutPanel = (LayoutPanel) this.createDocumentWindow(doc);
|
||
151 | if (layout != null) { |
||
152 | layoutPanel.setWindowLayout(layout); |
||
153 | layoutPanel.setLayoutManager(this);
|
||
154 | layoutPanel.getLayoutControl().fullRect(); |
||
155 | layoutPanel.getWindowInfo().setTitle( |
||
156 | PluginServices.getText(this, "Mapa") + " : " |
||
157 | + layoutPanel.getName()); |
||
158 | } |
||
159 | 5 | jldominguez | } |
160 | ((AbstractDocument) doc).raiseEventCreateWindow(layoutPanel);
|
||
161 | return layoutPanel;
|
||
162 | } |
||
163 | |||
164 | 1714 | fdiaz | @Override
|
165 | public IFFramePanel createFFrameDialog(IFFrame fframe,
|
||
166 | 5 | jldominguez | LayoutPanel layoutPanel, AffineTransform affineTransform) {
|
167 | ExtensionPoint ep = extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG); |
||
168 | |||
169 | try {
|
||
170 | Object[] args = new Object[2]; |
||
171 | args[0] = layoutPanel;
|
||
172 | args[1] = fframe;
|
||
173 | Object obj = ep.create(fframe.getName(), args);
|
||
174 | if (obj != null) { |
||
175 | 1714 | fdiaz | IFFramePanel fframedialog = (IFFramePanel) obj; |
176 | 5 | jldominguez | fframedialog.setRectangle(fframe |
177 | .getBoundingBox(affineTransform)); |
||
178 | return fframedialog;
|
||
179 | } |
||
180 | } catch (Exception e) { |
||
181 | 273 | cmartinez | LOG.error("Error creating a FFrameDialog", e);
|
182 | 5 | jldominguez | } |
183 | return null; |
||
184 | } |
||
185 | |||
186 | 1714 | fdiaz | @Override
|
187 | public IFFramePanel createFFrameDialog(IFFrame fframe,
|
||
188 | 5 | jldominguez | LayoutPanel layoutPanel) { |
189 | return createFFrameDialog(fframe, layoutPanel, layoutPanel
|
||
190 | .getLayoutControl().getAT()); |
||
191 | } |
||
192 | |||
193 | 1714 | fdiaz | @Override
|
194 | 5 | jldominguez | public void registerFrameFactory(FrameFactory frameFactory, String alias) { |
195 | ExtensionPoint ep = |
||
196 | ToolsLocator.getExtensionPointManager().add(KEY_LAYOUT_FFRAME); |
||
197 | ep.append(frameFactory.getRegisterName(), "", frameFactory);
|
||
198 | if (alias != null) { |
||
199 | ep.addAlias(frameFactory.getRegisterName(), alias); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | 1714 | fdiaz | @Override
|
204 | 5 | jldominguez | public void registerFrameFactory(FrameFactory frameFactory) { |
205 | registerFrameFactory(frameFactory, null);
|
||
206 | } |
||
207 | |||
208 | @SuppressWarnings("unchecked") |
||
209 | 1714 | fdiaz | @Override
|
210 | 5 | jldominguez | public IFFrame createFrame(String frameName) { |
211 | |||
212 | Iterator<Extension> iterator =
|
||
213 | ToolsLocator.getExtensionPointManager().get(KEY_LAYOUT_FFRAME) |
||
214 | .iterator(); |
||
215 | while (iterator.hasNext()) {
|
||
216 | try {
|
||
217 | FrameFactory frameFactory = |
||
218 | (FrameFactory) iterator.next().create(); |
||
219 | if (frameFactory.getRegisterName().equals(frameName)) {
|
||
220 | IFFrame frame = frameFactory.createFrame(); |
||
221 | if (frame == null) { |
||
222 | return null; |
||
223 | } |
||
224 | frame.setFrameFactory(frameFactory); |
||
225 | return frame;
|
||
226 | } |
||
227 | } catch (Exception e) { |
||
228 | NotificationManager.addError(e); |
||
229 | } |
||
230 | } |
||
231 | return null; |
||
232 | } |
||
233 | |||
234 | @SuppressWarnings("unchecked") |
||
235 | 1714 | fdiaz | @Override
|
236 | 5 | jldominguez | public void registerFFrameDialog(String name, Class clazz) { |
237 | 1714 | fdiaz | if (!IFFramePanel.class.isAssignableFrom(clazz)) {
|
238 | 5 | jldominguez | throw new IllegalArgumentException(clazz.getName() |
239 | + " must implement the IFFrameDialog interface");
|
||
240 | } |
||
241 | ExtensionPoint extensionPoint = |
||
242 | extensionPoints.add(KEY_LAYOUT_FFRAMEDIALOG, "");
|
||
243 | extensionPoint.append(name, name, clazz); |
||
244 | } |
||
245 | |||
246 | 567 | jjdelcerro | @Override
|
247 | 5 | jldominguez | public IWindow getPropertiesWindow(Document doc) { |
248 | 567 | jjdelcerro | IWindow win = super.getPropertiesWindow(doc);
|
249 | if( win == null ) { |
||
250 | win = new MapProperties((LayoutDocument) doc);
|
||
251 | } |
||
252 | return win;
|
||
253 | 5 | jldominguez | } |
254 | |||
255 | /**
|
||
256 | * Registers in the points of extension the Factory with alias.
|
||
257 | *
|
||
258 | */
|
||
259 | public static void register() { |
||
260 | DefaultLayoutManager factory = new DefaultLayoutManager();
|
||
261 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
262 | manager.registerFactory(factory); |
||
263 | |||
264 | ProjectManager.getInstance().registerDocumentFactory(factory); |
||
265 | 345 | cmartinez | |
266 | ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CopyDocumentAction());
|
||
267 | ProjectManager.getInstance().registerDocumentAction(TYPENAME,new CutDocumentAction());
|
||
268 | ProjectManager.getInstance().registerDocumentAction(TYPENAME,new PasteDocumentAction());
|
||
269 | 5 | jldominguez | |
270 | 345 | cmartinez | |
271 | 5 | jldominguez | if (factory.persistenceDefinition == null) { |
272 | factory.persistenceDefinition = |
||
273 | manager.addDefinition(LayoutDocument.class, |
||
274 | PERSISTENCE_LAYOUT_DOCUMENT_DEFINITION_NAME, |
||
275 | 62 | jldominguez | "Layout document Persistence definition", null, null); |
276 | 5 | jldominguez | factory.persistenceDefinition.extend(manager |
277 | .getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
||
278 | |||
279 | factory.persistenceDefinition |
||
280 | 147 | cmartinez | .addDynFieldObject(DefaultLayoutDocument.LAYOUT_CONTEXT_OBJECT) |
281 | 5 | jldominguez | .setClassOfValue(LayoutContext.class).setMandatory(false);
|
282 | |||
283 | DefaultLayoutPanel.registerPersistent(); |
||
284 | DefaultLayoutContext.registerPersistent(); |
||
285 | 1714 | fdiaz | MapBoxUtils.registerPersistence(); |
286 | 5 | jldominguez | } |
287 | } |
||
288 | |||
289 | 1714 | fdiaz | @Override
|
290 | 5 | jldominguez | public int getPriority() { |
291 | return 2; |
||
292 | } |
||
293 | |||
294 | /**
|
||
295 | 216 | cmartinez | * Sets whether the grid should be shown.
|
296 | 5 | jldominguez | *
|
297 | * @param showGrid
|
||
298 | */
|
||
299 | public void setDefaultShowGrid(boolean showGrid) { |
||
300 | 1714 | fdiaz | defaultShowGrid = showGrid; |
301 | 5 | jldominguez | } |
302 | |||
303 | /**
|
||
304 | 216 | cmartinez | * Sets whether the snapping to grid should be enabled or not
|
305 | 5 | jldominguez | *
|
306 | * @param gridEnable
|
||
307 | */
|
||
308 | public void setDefaultAdjustToGrid(boolean gridEnabled) { |
||
309 | 1714 | fdiaz | defaultAdjustToGrid = gridEnabled; |
310 | 5 | jldominguez | } |
311 | |||
312 | /**
|
||
313 | 216 | cmartinez | * Sets whether the ruler should be shown or not
|
314 | 5 | jldominguez | *
|
315 | * @param showRuler
|
||
316 | */
|
||
317 | public void setDefaultShowRulers(boolean showRules) { |
||
318 | 1714 | fdiaz | defaultShowRulers = showRules; |
319 | 5 | jldominguez | } |
320 | |||
321 | /**
|
||
322 | 216 | cmartinez | * Returns if the grid should be shown.
|
323 | 5 | jldominguez | *
|
324 | 216 | cmartinez | * @return True if the grid should be shown.
|
325 | 5 | jldominguez | */
|
326 | public boolean getDefaultShowGrid() { |
||
327 | if (defaultShowGrid == null) { |
||
328 | 216 | cmartinez | XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
329 | if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME)) {
|
||
330 | 5 | jldominguez | defaultShowGrid = |
331 | 1714 | fdiaz | xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_GRID_KEY_NAME); |
332 | 5 | jldominguez | } else {
|
333 | 1714 | fdiaz | defaultShowGrid = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_SHOW; |
334 | 5 | jldominguez | } |
335 | } |
||
336 | 1714 | fdiaz | return defaultShowGrid;
|
337 | 5 | jldominguez | } |
338 | |||
339 | /**
|
||
340 | 216 | cmartinez | * Returns if the adjust to grid should be active.
|
341 | 5 | jldominguez | *
|
342 | 216 | cmartinez | * @return True if the adjust to grid should be active.
|
343 | 5 | jldominguez | */
|
344 | public boolean getDefaultAdjustToGrid() { |
||
345 | if (defaultAdjustToGrid == null) { |
||
346 | 216 | cmartinez | XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
347 | if (xml.contains(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME)) {
|
||
348 | 5 | jldominguez | defaultAdjustToGrid = |
349 | 1714 | fdiaz | xml.getBooleanProperty(PreferenceKeys.DEFAULT_ENABLE_LAYOUT_GRID_KEY_NAME); |
350 | 5 | jldominguez | } else {
|
351 | 1714 | fdiaz | defaultAdjustToGrid = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_GRID_ENABLE; |
352 | 5 | jldominguez | } |
353 | } |
||
354 | 1714 | fdiaz | return defaultAdjustToGrid;
|
355 | 5 | jldominguez | } |
356 | |||
357 | /**
|
||
358 | 216 | cmartinez | * Returns if the ruler should be shown.
|
359 | 5 | jldominguez | *
|
360 | 216 | cmartinez | * @return True if the ruler should be shown.
|
361 | 5 | jldominguez | */
|
362 | public boolean getDefaultShowRulers() { |
||
363 | if (defaultShowRulers == null) { |
||
364 | 216 | cmartinez | XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
365 | if (xml.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME)) {
|
||
366 | 5 | jldominguez | defaultShowRulers = |
367 | 1714 | fdiaz | xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_RULERS_KEY_NAME); |
368 | 5 | jldominguez | } else {
|
369 | 1714 | fdiaz | defaultShowRulers = PreferenceKeys.FACTORY_DEFAULT_LAYOUT_ENABLE_RULERS; |
370 | 5 | jldominguez | } |
371 | } |
||
372 | 1714 | fdiaz | return defaultShowRulers;
|
373 | 5 | jldominguez | } |
374 | |||
375 | 216 | cmartinez | public boolean getDefaultShowInitialPageConfigDialog() { |
376 | XMLEntity xml = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
|
||
377 | boolean value;
|
||
378 | if (xml.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
|
||
379 | value = xml.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME); |
||
380 | } else {
|
||
381 | value = PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT; |
||
382 | } |
||
383 | return value;
|
||
384 | } |
||
385 | |||
386 | 1714 | fdiaz | @Override
|
387 | 5 | jldominguez | public DynStruct getDefinition(String className) { |
388 | |||
389 | if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
||
390 | return this.persistenceDefinition; |
||
391 | } |
||
392 | if (this.persistenceDefinition.getFullName() |
||
393 | .equalsIgnoreCase(className)) { |
||
394 | return this.persistenceDefinition; |
||
395 | } |
||
396 | if (this.getDocumentClass().getName().equals(className)) { |
||
397 | return this.persistenceDefinition; |
||
398 | } |
||
399 | return null; |
||
400 | } |
||
401 | |||
402 | @SuppressWarnings("unchecked") |
||
403 | 1714 | fdiaz | @Override
|
404 | 5 | jldominguez | protected Class getDocumentClass() { |
405 | return DefaultLayoutDocument.class;
|
||
406 | } |
||
407 | |||
408 | 1714 | fdiaz | @Override
|
409 | 5 | jldominguez | public boolean manages(Object object) { |
410 | return object instanceof LayoutDocument; |
||
411 | } |
||
412 | |||
413 | 1714 | fdiaz | @Override
|
414 | 5 | jldominguez | public void registerLayoutMenuAction(String name, |
415 | Class<? extends IContextMenuAction> clazz) { |
||
416 | ExtensionPoint extensionPoint = |
||
417 | ToolsLocator.getExtensionPointManager().add(LAYOUT_CONTEXT_MENUS); |
||
418 | extensionPoint.append(name, "", clazz);
|
||
419 | } |
||
420 | |||
421 | 1714 | fdiaz | @Override
|
422 | 5 | jldominguez | public IContextMenuAction[] createLayoutMenuActions(LayoutPanel layoutPanel) { |
423 | List<IContextMenuAction> actionArrayList =
|
||
424 | 1714 | fdiaz | new ArrayList<>(); |
425 | 5 | jldominguez | @SuppressWarnings("unchecked") |
426 | Iterator<ExtensionPoint.Extension> iter =
|
||
427 | ToolsLocator.getExtensionPointManager().get(LAYOUT_CONTEXT_MENUS).iterator(); |
||
428 | AbstractLayoutContextMenuAction action; |
||
429 | while (iter.hasNext()) {
|
||
430 | action = null;
|
||
431 | try {
|
||
432 | action = (AbstractLayoutContextMenuAction) iter.next().create(); |
||
433 | 1714 | fdiaz | } catch (InstantiationException | IllegalAccessException e) { |
434 | 5 | jldominguez | LOG.error("Error creating the context menu", e);
|
435 | } |
||
436 | if (action != null) { |
||
437 | action.setLayout(layoutPanel); |
||
438 | 140 | cmartinez | if (action.isVisible(null, layoutPanel.getLayoutContext().getSelectedFFrames())) { |
439 | 5 | jldominguez | actionArrayList.add(action); |
440 | } |
||
441 | } |
||
442 | } |
||
443 | IContextMenuAction[] result =
|
||
444 | (IContextMenuAction[]) Array.newInstance(IContextMenuAction.class, |
||
445 | actionArrayList.size()); |
||
446 | System.arraycopy(actionArrayList.toArray(), 0, result, 0, |
||
447 | actionArrayList.size()); |
||
448 | Arrays.sort(result, new CompareAction()); |
||
449 | return result;
|
||
450 | } |
||
451 | |||
452 | private class CompareAction implements Comparator<IContextMenuAction> { |
||
453 | |||
454 | 1714 | fdiaz | @Override
|
455 | 5 | jldominguez | public int compare(IContextMenuAction o1, IContextMenuAction o2) { |
456 | NumberFormat formater = NumberFormat.getInstance(); |
||
457 | formater.setMinimumIntegerDigits(3);
|
||
458 | String key1 =
|
||
459 | "" + formater.format(o1.getGroupOrder()) + o1.getGroup()
|
||
460 | + formater.format(o1.getOrder()); |
||
461 | String key2 =
|
||
462 | "" + formater.format(o2.getGroupOrder()) + o2.getGroup()
|
||
463 | + formater.format(o2.getOrder()); |
||
464 | return key1.compareTo(key2);
|
||
465 | } |
||
466 | } |
||
467 | } |