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