svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / ViewManager.java @ 46586
History | View | Annotate | Download (25.2 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view; |
25 |
|
26 |
import java.text.NumberFormat; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Collections; |
29 |
import java.util.Comparator; |
30 |
import java.util.HashMap; |
31 |
import java.util.Iterator; |
32 |
import java.util.List; |
33 |
import java.util.Map; |
34 |
import java.util.function.Predicate; |
35 |
import javax.swing.ImageIcon; |
36 |
import org.apache.commons.lang3.StringUtils; |
37 |
import org.gvsig.andami.IconThemeHelper; |
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.andami.PluginsLocator; |
40 |
import org.gvsig.andami.actioninfo.ActionInfo; |
41 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
42 |
import org.gvsig.andami.messages.NotificationManager; |
43 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
44 |
import org.gvsig.app.project.Project; |
45 |
import org.gvsig.app.project.ProjectManager; |
46 |
import org.gvsig.app.project.documents.AbstractDocument; |
47 |
import org.gvsig.app.project.documents.AbstractDocumentManager; |
48 |
import org.gvsig.app.project.documents.Document; |
49 |
import org.gvsig.app.project.documents.actions.CopyDocumentAction; |
50 |
import org.gvsig.app.project.documents.actions.CutDocumentAction; |
51 |
import org.gvsig.app.project.documents.actions.PasteDocumentAction; |
52 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
53 |
import org.gvsig.app.project.documents.gui.WindowLayout; |
54 |
import org.gvsig.app.project.documents.view.dalactions.AddFilterToLayerAction.AddFilterToLayerActionFactory; |
55 |
import org.gvsig.app.project.documents.view.dalactions.CreateTemporalLayerAction; |
56 |
import org.gvsig.app.project.documents.view.dalactions.ViewZoomAction.ViewZoomActionFactory; |
57 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
58 |
import org.gvsig.app.project.documents.view.gui.ViewProperties; |
59 |
import org.gvsig.app.project.documents.view.toc.AbstractActionInfoAdapterToTocContextMenuAction; |
60 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
61 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
62 |
import org.gvsig.app.project.documents.view.toc.TocItemBranch; |
63 |
import org.gvsig.app.project.documents.view.toc.actions.OldTocContextMenuAction; |
64 |
import org.gvsig.fmap.dal.AbstractStoresRepository; |
65 |
import org.gvsig.fmap.dal.DALLocator; |
66 |
import org.gvsig.fmap.dal.DataManager; |
67 |
import org.gvsig.fmap.dal.DataStore; |
68 |
import org.gvsig.fmap.dal.DataStoreParameters; |
69 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
70 |
import org.gvsig.fmap.mapcontext.MapContext; |
71 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
72 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
73 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesHelper; |
74 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
75 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
76 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
77 |
import org.gvsig.tools.ToolsLocator; |
78 |
import org.gvsig.tools.dispose.DisposeUtils; |
79 |
import org.gvsig.tools.dynobject.DynStruct; |
80 |
import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
81 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
82 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
83 |
import org.gvsig.tools.persistence.PersistenceManager; |
84 |
import org.gvsig.tools.util.UnmodifiableBasicSet; |
85 |
import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
86 |
import org.slf4j.Logger; |
87 |
import org.slf4j.LoggerFactory; |
88 |
|
89 |
/**
|
90 |
* Factory of View.
|
91 |
*
|
92 |
* @author gvSIG Team
|
93 |
*
|
94 |
*/
|
95 |
public class ViewManager extends AbstractDocumentManager { |
96 |
|
97 |
private static final Logger LOGGER = LoggerFactory.getLogger(ViewManager.class); |
98 |
|
99 |
private static class ViewDocumentStoresRepository extends AbstractStoresRepository { |
100 |
|
101 |
public ViewDocumentStoresRepository(String name) { |
102 |
super(name);
|
103 |
} |
104 |
|
105 |
private Map<String, DataStoreParameters> getAll(Predicate<DataStore> filter, int limit) { |
106 |
Map<String, DataStoreParameters> all = new HashMap<>(); |
107 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
108 |
List<Document> views = project.getDocuments(TYPENAME); |
109 |
for (Document view : views) { |
110 |
for (FLayer layer : ((ViewDocument) view).layers()) {
|
111 |
if (layer instanceof FLyrVect) { |
112 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
113 |
if (store!=null && (filter == null || filter.test(store))) { |
114 |
all.put(store.getName(), store.getParameters()); |
115 |
} |
116 |
// UnmodifiableBasicMap<String, DataStore> children = store.getChildren();
|
117 |
// if (children != null) {
|
118 |
// for (DataStore dataStore : children) {
|
119 |
// if (filter == null || filter.test(dataStore)) {
|
120 |
// all.put(dataStore.getName(), dataStore.getParameters());
|
121 |
// }
|
122 |
// }
|
123 |
// }
|
124 |
} |
125 |
if (limit > 0 && all.size() >= limit) { |
126 |
break;
|
127 |
} |
128 |
} |
129 |
} |
130 |
if (all.isEmpty()) {
|
131 |
return null; |
132 |
} |
133 |
return all;
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
protected DataStoreParameters getMyParameters(final String name) { |
138 |
Map<String, DataStoreParameters> all = this.getAll((DataStore t) -> { |
139 |
String x = t==null? null:t.getName(); |
140 |
return StringUtils.equalsIgnoreCase(name, x);
|
141 |
}, 1);
|
142 |
if (all == null) { |
143 |
return null; |
144 |
} |
145 |
return all.get(name);
|
146 |
} |
147 |
|
148 |
@Override
|
149 |
public DataStore getStore(String name) { |
150 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
151 |
List<Document> views = project.getDocuments(TYPENAME); |
152 |
for (Document view : views) { |
153 |
for (FLayer layer : ((ViewDocument) view).layers()) {
|
154 |
if (layer instanceof SingleLayer) { |
155 |
DataStore store = ((SingleLayer) layer).getDataStore(); |
156 |
if (store!=null && StringUtils.equals(name, store.getName())) { |
157 |
DisposeUtils.bind(store); |
158 |
return store;
|
159 |
} |
160 |
} |
161 |
} |
162 |
} |
163 |
return null; |
164 |
} |
165 |
|
166 |
@Override
|
167 |
public boolean containsKey(final String key) { |
168 |
Map<String, DataStoreParameters> all = this.getAll((DataStore t) -> { |
169 |
String x = t==null? null:t.getName(); |
170 |
return StringUtils.equalsIgnoreCase(key, x);
|
171 |
}, 1);
|
172 |
if (all == null) { |
173 |
return false; |
174 |
} |
175 |
return all.containsKey(key);
|
176 |
} |
177 |
|
178 |
@Override
|
179 |
protected UnmodifiableBasicSet<String> getMyKeySet() { |
180 |
Map<String, DataStoreParameters> all = this.getAll(null, 0); |
181 |
if (all == null) { |
182 |
return null; |
183 |
} |
184 |
return new UnmodifiableBasicSetAdapter<>(all.keySet()); |
185 |
} |
186 |
|
187 |
@Override
|
188 |
protected boolean isEmptyMyRepository() { |
189 |
Map<String, DataStoreParameters> all = this.getAll(null, 1); |
190 |
return all.isEmpty();
|
191 |
} |
192 |
|
193 |
@Override
|
194 |
protected int getMySize() { |
195 |
Map<String, DataStoreParameters> all = this.getAll(null, 0); |
196 |
return all.size();
|
197 |
} |
198 |
|
199 |
@Override
|
200 |
public Iterator<DataStoreParameters> iterator() { |
201 |
Map<String, DataStoreParameters> all = this.getAll(null, 0); |
202 |
return all.values().iterator();
|
203 |
} |
204 |
|
205 |
public static void selfRegister() { |
206 |
DataManager dataManager = DALLocator.getDataManager(); |
207 |
dataManager.getStoresRepository().addRepository(new ViewDocumentStoresRepository("Project layers")); |
208 |
} |
209 |
} |
210 |
private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME |
211 |
= "DefaultViewDocument";
|
212 |
public static String TYPENAME = "project.document.view2d"; |
213 |
private DynStruct persistenceDefinition;
|
214 |
private static int countSeparators = 0; |
215 |
|
216 |
public ViewManager() {
|
217 |
// Do nothing
|
218 |
} |
219 |
|
220 |
@Override
|
221 |
public int getPriority() { |
222 |
return 0; |
223 |
} |
224 |
|
225 |
@Override
|
226 |
public ImageIcon getIcon() { |
227 |
return PluginServices.getIconTheme().get("document-view-icon"); |
228 |
} |
229 |
|
230 |
@Override
|
231 |
public ImageIcon getIconSelected() { |
232 |
return PluginServices.getIconTheme().get("document-view-icon-sel"); |
233 |
} |
234 |
|
235 |
@Override
|
236 |
public String getTitle() { |
237 |
return PluginServices.getText(this, "Vista"); |
238 |
} |
239 |
|
240 |
@Override
|
241 |
public String getTypeName() { |
242 |
return TYPENAME;
|
243 |
} |
244 |
|
245 |
@Override
|
246 |
public Class getMainWindowClass() { |
247 |
return DefaultViewPanel.class;
|
248 |
} |
249 |
|
250 |
@Override
|
251 |
public AbstractDocument createDocument() { |
252 |
AbstractDocument doc = new DefaultViewDocument(this); |
253 |
if (this.notifyObservers(NOTIFY_AFTER_CREATEDOCUMENT, doc).isCanceled()) { |
254 |
return null; |
255 |
} |
256 |
return doc;
|
257 |
|
258 |
} |
259 |
|
260 |
@Override
|
261 |
public IWindow getMainWindow(Document doc, WindowLayout layout) { |
262 |
IDocumentWindow win = (IDocumentWindow) super.getMainWindow(doc, layout);
|
263 |
if (win == null) { |
264 |
win = this.createDocumentWindow(doc);
|
265 |
if (layout != null && win != null) { |
266 |
win.setWindowLayout(layout); |
267 |
} |
268 |
if (this.notifyObservers(NOTIFY_AFTER_CREATEMAINWINDOW, win).isCanceled()) { |
269 |
return null; |
270 |
} |
271 |
} |
272 |
if (this.notifyObservers(NOTIFY_AFTER_GETMAINWINDOW, win).isCanceled()) { |
273 |
return null; |
274 |
} |
275 |
((AbstractDocument) doc).raiseEventCreateWindow(win);
|
276 |
return win;
|
277 |
} |
278 |
|
279 |
@Override
|
280 |
public IWindow getPropertiesWindow(Document doc) { |
281 |
IWindow win = super.getPropertiesWindow(doc);
|
282 |
if (win == null) { |
283 |
win = new ViewProperties((DefaultViewDocument) doc);
|
284 |
if (this.notifyObservers(NOTIFY_AFTER_CREATEPROPERTIESWINDOW, win).isCanceled()) { |
285 |
return null; |
286 |
} |
287 |
} |
288 |
if (this.notifyObservers(NOTIFY_AFTER_GETPROPERTIESWINDOW, win).isCanceled()) { |
289 |
return null; |
290 |
} |
291 |
return win;
|
292 |
} |
293 |
|
294 |
public void addTOCContextAction(String theAction) { |
295 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
296 |
ActionInfo action = actionManager.getAction(theAction); |
297 |
if (action == null) { |
298 |
String errmsg = "Action '" + theAction + "' not found"; |
299 |
LOGGER.info(errmsg); |
300 |
throw new RuntimeException(errmsg); |
301 |
} |
302 |
this.addTOCContextAction(action);
|
303 |
} |
304 |
|
305 |
public void addTOCContextAction(String theAction, String group, int groupOrder, int order) { |
306 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
307 |
ActionInfo action = actionManager.getAction(theAction); |
308 |
if (action == null) { |
309 |
String errmsg = "Action '" + theAction + "' not found"; |
310 |
LOGGER.info(errmsg); |
311 |
throw new RuntimeException(errmsg); |
312 |
} |
313 |
this.addTOCContextAction(
|
314 |
action.getName(), |
315 |
new ActionInfoAdapterToContextMenuAction(action, group, groupOrder, order)
|
316 |
); |
317 |
} |
318 |
|
319 |
public void addTOCContextAction(ActionInfo action) { |
320 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, "default", 9000)); |
321 |
} |
322 |
|
323 |
public void addTOCContextAction(ActionInfo action, String group, int groupOrder) { |
324 |
this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, group, groupOrder)); |
325 |
} |
326 |
|
327 |
public void addTOCSeparator(String group, int groupOrder, int order) { |
328 |
|
329 |
String effectiveGroup = group + "/-" + (countSeparators++) + "-"; |
330 |
|
331 |
this.addTOCContextAction(
|
332 |
// group + "/-",
|
333 |
effectiveGroup, |
334 |
new IContextMenuAction() {
|
335 |
@Override
|
336 |
public boolean isVisible(Object item, Object[] selectedItems) { |
337 |
return true; |
338 |
} |
339 |
|
340 |
@Override
|
341 |
public boolean isEnabled(Object item, Object[] selectedItems) { |
342 |
return true; |
343 |
} |
344 |
|
345 |
@Override
|
346 |
public void execute(Object item, Object[] selectedItems) { |
347 |
} |
348 |
|
349 |
@Override
|
350 |
public String getGroup() { |
351 |
return effectiveGroup; //group + "/-"; |
352 |
} |
353 |
|
354 |
@Override
|
355 |
public int getGroupOrder() { |
356 |
return groupOrder;
|
357 |
} |
358 |
|
359 |
@Override
|
360 |
public int getOrder() { |
361 |
return order;
|
362 |
} |
363 |
|
364 |
@Override
|
365 |
public String getText() { |
366 |
return "-"; |
367 |
} |
368 |
|
369 |
@Override
|
370 |
public String getDescription() { |
371 |
return ""; |
372 |
} |
373 |
} |
374 |
); |
375 |
} |
376 |
|
377 |
class ActionInfoAdapterToContextMenuAction extends AbstractActionInfoAdapterToTocContextMenuAction { |
378 |
|
379 |
ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder) { |
380 |
super(action, group, groupOrder);
|
381 |
} |
382 |
|
383 |
ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder, int order) { |
384 |
super(action, group, groupOrder, order);
|
385 |
} |
386 |
} |
387 |
|
388 |
/**
|
389 |
* @deprecated use addTOCContextAction(ActionInfo action, String group, int
|
390 |
* groupOrder)
|
391 |
* @param id
|
392 |
* @param action
|
393 |
*/
|
394 |
public void addTOCContextAction(String id, IContextMenuAction action) { |
395 |
initializeRegisterTOCActions(); |
396 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add( |
397 |
"View_TocActions", ""); |
398 |
if (action instanceof ExtensionBuilder) { |
399 |
exPoint.append(id, "", (ExtensionBuilder) action);
|
400 |
return;
|
401 |
} |
402 |
exPoint.append(id, "", new ContextMenuActionAdapterToExtensionBuilder(action)); |
403 |
} |
404 |
|
405 |
class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
406 |
|
407 |
IContextMenuAction menuAction = null;
|
408 |
|
409 |
ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
410 |
this.menuAction = menuAction;
|
411 |
} |
412 |
|
413 |
@Override
|
414 |
public Object create() { |
415 |
return this.menuAction; |
416 |
} |
417 |
|
418 |
@Override
|
419 |
public Object create(Object[] args) { |
420 |
return this.menuAction; |
421 |
} |
422 |
|
423 |
@Override
|
424 |
public Object create(Map args) { |
425 |
return this.menuAction; |
426 |
} |
427 |
} |
428 |
|
429 |
private static void initializeRegisterTOCActions() { |
430 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
431 |
|
432 |
if (!epManager.has("View_TocActions")) { |
433 |
epManager.add( |
434 |
"View_TocActions",
|
435 |
"Context menu options of the TOC "
|
436 |
+ " in the view window "
|
437 |
+ "(register instances of "
|
438 |
+ "org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
439 |
); |
440 |
} |
441 |
} |
442 |
|
443 |
/**
|
444 |
* Registers in the points of extension the Factory with alias.
|
445 |
*
|
446 |
*/
|
447 |
public static void register() { |
448 |
ViewManager factory = new ViewManager();
|
449 |
ProjectManager.getInstance().registerDocumentFactory(factory); |
450 |
|
451 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
452 |
manager.registerFactory(factory); |
453 |
|
454 |
initializeRegisterTOCActions(); |
455 |
|
456 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, new CopyDocumentAction());
|
457 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, new CutDocumentAction());
|
458 |
ProjectManager.getInstance().registerDocumentAction(TYPENAME, new PasteDocumentAction());
|
459 |
|
460 |
IconThemeHelper.registerIcon("document", "document-view-icon", ViewManager.class); |
461 |
IconThemeHelper.registerIcon("document", "document-view-icon-sel", ViewManager.class); |
462 |
|
463 |
IconThemeHelper.registerIcon("cursor", "cursor-busy", ViewManager.class); |
464 |
IconThemeHelper.registerIcon("cursor", "cursor-crux", ViewManager.class); |
465 |
IconThemeHelper.registerIcon("cursor", "cursor-info-by-point", ViewManager.class); |
466 |
IconThemeHelper.registerIcon("cursor", "cursor-pan", ViewManager.class); |
467 |
IconThemeHelper.registerIcon("cursor", "cursor-query-area", ViewManager.class); |
468 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-point", ViewManager.class); |
469 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
470 |
IconThemeHelper.registerIcon("cursor", "cursor-select-by-rectangle", ViewManager.class); |
471 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
472 |
IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
473 |
|
474 |
IconThemeHelper.registerIcon("layer", "layer-icon", ViewManager.class); |
475 |
IconThemeHelper.registerIcon("layer", "layer-icon-group", ViewManager.class); |
476 |
IconThemeHelper.registerIcon("layer", "layer-icon-vectorial", ViewManager.class); |
477 |
IconThemeHelper.registerIcon("layer", "layer-icon-csv", ViewManager.class); |
478 |
IconThemeHelper.registerIcon("layer", "layer-icon-dgn", ViewManager.class); |
479 |
IconThemeHelper.registerIcon("layer", "layer-icon-dxf", ViewManager.class); |
480 |
IconThemeHelper.registerIcon("layer", "layer-icon-postgresql", ViewManager.class); |
481 |
IconThemeHelper.registerIcon("layer", "layer-icon-mysql", ViewManager.class); |
482 |
IconThemeHelper.registerIcon("layer", "layer-icon-jdbc", ViewManager.class); |
483 |
//IconThemeHelper.registerIcon("layer", "layer-icon-unavailable", ViewManager.class);
|
484 |
IconThemeHelper.registerIcon("layer", "layer-chk-unavailable", ViewManager.class); |
485 |
IconThemeHelper.registerIcon("layer", "layer-chk-temporary", ViewManager.class); |
486 |
IconThemeHelper.registerIcon("layer", "active-layer-bring-front", ViewManager.class); |
487 |
IconThemeHelper.registerIcon("layer", "active-layer-move-ahead", ViewManager.class); |
488 |
IconThemeHelper.registerIcon("layer", "active-layer-move-behind", ViewManager.class); |
489 |
IconThemeHelper.registerIcon("layer", "active-layer-send-back", ViewManager.class); |
490 |
IconThemeHelper.registerIcon("layer", "active-layer-set-hide", ViewManager.class); |
491 |
IconThemeHelper.registerIcon("layer", "active-layer-set-visible", ViewManager.class); |
492 |
IconThemeHelper.registerIcon("layer", "layer-set-visible", ViewManager.class); |
493 |
IconThemeHelper.registerIcon("layer", "layer-set-hide", ViewManager.class); |
494 |
IconThemeHelper.registerIcon("layer", "layer-set-inactive", ViewManager.class); |
495 |
IconThemeHelper.registerIcon("layer", "layer-set-active", ViewManager.class); |
496 |
|
497 |
IconThemeHelper.registerIcon("legend", "legend-overview-single-symbol", ViewManager.class); |
498 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-interval", ViewManager.class); |
499 |
IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-unique-value", ViewManager.class); |
500 |
|
501 |
MapContextManager mapContextMgr = MapContextLocator.getMapContextManager(); |
502 |
mapContextMgr.registerIconLayer("CSV", "layer-icon-csv"); |
503 |
mapContextMgr.registerIconLayer("DGN", "layer-icon-dgn"); |
504 |
mapContextMgr.registerIconLayer("DXF", "layer-icon-dxf"); |
505 |
mapContextMgr.registerIconLayer("jdbc", "layer-icon-jdbc"); |
506 |
mapContextMgr.registerIconLayer("PostgreSQL", "layer-icon-postgresql"); |
507 |
mapContextMgr.registerIconLayer("MySQL", "layer-icon-mysql"); |
508 |
|
509 |
if (factory.persistenceDefinition == null) { |
510 |
factory.persistenceDefinition = manager.addDefinition( |
511 |
ViewDocument.class, |
512 |
PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
513 |
"Default view document persistence definition",
|
514 |
null,
|
515 |
null
|
516 |
); |
517 |
factory.persistenceDefinition.extend(manager.getDefinition(AbstractDocument.PERSISTENCE_DEFINITION_NAME));
|
518 |
|
519 |
factory.persistenceDefinition.addDynFieldBoolean("useMapOverview").setMandatory(true); |
520 |
factory.persistenceDefinition.addDynFieldObject("mainMapContext").setClassOfValue(MapContext.class).setMandatory(true); |
521 |
factory.persistenceDefinition.addDynFieldObject("overviewMapContext").setClassOfValue(MapContext.class).setMandatory(false); |
522 |
factory.persistenceDefinition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
523 |
.setMandatory(false);
|
524 |
|
525 |
} |
526 |
ViewDocumentStoresRepository.selfRegister(); |
527 |
ViewZoomActionFactory.selfRegister(); |
528 |
AddFilterToLayerActionFactory.selfRegister(); |
529 |
CreateTemporalLayerAction.CreateTemporalLayerActionFactory.selfRegister(); |
530 |
} |
531 |
|
532 |
@SuppressWarnings("rawtypes") |
533 |
@Override
|
534 |
public DynStruct getDefinition(String className) { |
535 |
|
536 |
if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
537 |
return this.persistenceDefinition; |
538 |
} |
539 |
if (this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
540 |
return this.persistenceDefinition; |
541 |
} |
542 |
if (this.getDocumentClass().getName().equals(className)) { |
543 |
return this.persistenceDefinition; |
544 |
} |
545 |
|
546 |
return null; |
547 |
} |
548 |
|
549 |
@SuppressWarnings("rawtypes") |
550 |
@Override
|
551 |
protected Class getDocumentClass() { |
552 |
return DefaultViewDocument.class;
|
553 |
} |
554 |
|
555 |
@Override
|
556 |
public boolean manages(Object object) { |
557 |
return object instanceof ViewDocument; |
558 |
} |
559 |
|
560 |
public List<IContextMenuAction> getTOCContextMenuActions(MapContext mapContext, FLayer[] selecteds, ITocItem nodeUserObject) { |
561 |
List<IContextMenuAction> actions = new ArrayList<>(); |
562 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("View_TocActions", ""); |
563 |
Iterator<org.gvsig.tools.extensionpoint.ExtensionPoint.Extension> iter = exPoint.iterator();
|
564 |
IContextMenuAction action; |
565 |
boolean contains = false; |
566 |
ITocItem tocItem = nodeUserObject; |
567 |
if (tocItem instanceof TocItemBranch) { |
568 |
for (int i = 0; i < selecteds.length; i++) { |
569 |
if (selecteds[i].equals(((TocItemBranch) tocItem)
|
570 |
.getLayer())) { |
571 |
contains = true;
|
572 |
break;
|
573 |
} |
574 |
} |
575 |
} else {
|
576 |
contains = true;
|
577 |
} |
578 |
if (contains) {
|
579 |
while (iter.hasNext()) {
|
580 |
action = null;
|
581 |
try {
|
582 |
action = (IContextMenuAction) iter.next().create(); |
583 |
} catch (Exception e) { |
584 |
NotificationManager.addError(e); |
585 |
} |
586 |
if (action != null ) { |
587 |
if( action instanceof AbstractTocContextMenuAction |
588 |
&& !(action instanceof OldTocContextMenuAction)) {
|
589 |
((AbstractTocContextMenuAction)action).setMapContext(mapContext); |
590 |
} |
591 |
if (action.isVisible(nodeUserObject,
|
592 |
selecteds)) { |
593 |
actions.add(action); |
594 |
} |
595 |
} |
596 |
|
597 |
} |
598 |
Collections.sort(actions, new CompareAction()); |
599 |
return actions;
|
600 |
} |
601 |
return null; |
602 |
} |
603 |
|
604 |
private class CompareAction implements Comparator<IContextMenuAction> { |
605 |
|
606 |
public int compare(IContextMenuAction o1, IContextMenuAction o2) { |
607 |
// FIXME: falta formatear los enteros!!!!
|
608 |
NumberFormat formater = NumberFormat.getInstance(); |
609 |
formater.setMinimumIntegerDigits(6);
|
610 |
String key1 =
|
611 |
"" + formater.format(o1.getGroupOrder()) + formater.format(o1.getOrder()) + o1.getGroup();
|
612 |
String key2 =
|
613 |
"" + formater.format(o2.getGroupOrder()) + formater.format(o2.getOrder()) + o2.getGroup();
|
614 |
return key1.compareTo(key2);
|
615 |
} |
616 |
} |
617 |
|
618 |
public boolean existsTOCContextMenuActions(String name) { |
619 |
ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("View_TocActions", ""); |
620 |
Iterator<org.gvsig.tools.extensionpoint.ExtensionPoint.Extension> iter = exPoint.iterator();
|
621 |
while (iter.hasNext()) {
|
622 |
ExtensionPoint.Extension action = iter.next(); |
623 |
if (action != null ) { |
624 |
if(StringUtils.equalsIgnoreCase(name, action.getName())){
|
625 |
return true; |
626 |
} |
627 |
} |
628 |
} |
629 |
return false; |
630 |
} |
631 |
|
632 |
|
633 |
} |