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