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