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 | 40558 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.app.project.documents.view; |
25 | |||
26 | 46184 | fdiaz | import java.text.NumberFormat; |
27 | import java.util.ArrayList; |
||
28 | import java.util.Collections; |
||
29 | import java.util.Comparator; |
||
30 | 44281 | jjdelcerro | import java.util.HashMap; |
31 | import java.util.Iterator; |
||
32 | import java.util.List; |
||
33 | 41081 | jjdelcerro | import java.util.Map; |
34 | 40435 | jjdelcerro | import javax.swing.ImageIcon; |
35 | 44281 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
36 | 47045 | jjdelcerro | import org.apache.commons.lang3.tuple.ImmutablePair; |
37 | import org.apache.commons.lang3.tuple.Pair; |
||
38 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
39 | import org.gvsig.andami.PluginServices; |
||
40 | 41081 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
41 | import org.gvsig.andami.actioninfo.ActionInfo; |
||
42 | import org.gvsig.andami.actioninfo.ActionInfoManager; |
||
43 | 46184 | fdiaz | import org.gvsig.andami.messages.NotificationManager; |
44 | 40435 | jjdelcerro | import org.gvsig.andami.ui.mdiManager.IWindow; |
45 | 44281 | jjdelcerro | import org.gvsig.app.project.Project; |
46 | 40435 | jjdelcerro | 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 | 46089 | omartinez | import org.gvsig.app.project.documents.view.dalactions.AddFilterToLayerAction.AddFilterToLayerActionFactory; |
56 | import org.gvsig.app.project.documents.view.dalactions.CreateTemporalLayerAction; |
||
57 | 44281 | jjdelcerro | import org.gvsig.app.project.documents.view.dalactions.ViewZoomAction.ViewZoomActionFactory; |
58 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
59 | import org.gvsig.app.project.documents.view.gui.ViewProperties; |
||
60 | 41559 | jjdelcerro | import org.gvsig.app.project.documents.view.toc.AbstractActionInfoAdapterToTocContextMenuAction; |
61 | 46184 | fdiaz | 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 | 44304 | jjdelcerro | import org.gvsig.fmap.dal.AbstractStoresRepository; |
66 | 44281 | jjdelcerro | 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 | 46737 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
72 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContext; |
73 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
74 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
75 | 41350 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesHelper; |
76 | 44281 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.FLayer; |
77 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
78 | 40435 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
79 | import org.gvsig.tools.dynobject.DynStruct; |
||
80 | 41081 | jjdelcerro | import org.gvsig.tools.extensionpoint.ExtensionBuilder; |
81 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
82 | 41104 | jjdelcerro | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
83 | 40435 | jjdelcerro | import org.gvsig.tools.persistence.PersistenceManager; |
84 | 44281 | jjdelcerro | import org.gvsig.tools.util.UnmodifiableBasicSet; |
85 | import org.gvsig.tools.util.UnmodifiableBasicSetAdapter; |
||
86 | 40435 | jjdelcerro | import org.slf4j.Logger; |
87 | import org.slf4j.LoggerFactory; |
||
88 | |||
89 | /**
|
||
90 | * Factory of View.
|
||
91 | *
|
||
92 | 45543 | jjdelcerro | * @author gvSIG Team
|
93 | 44281 | jjdelcerro | *
|
94 | 40435 | jjdelcerro | */
|
95 | public class ViewManager extends AbstractDocumentManager { |
||
96 | 44281 | jjdelcerro | |
97 | private static final Logger LOGGER = LoggerFactory.getLogger(ViewManager.class); |
||
98 | |||
99 | 44304 | jjdelcerro | private static class ViewDocumentStoresRepository extends AbstractStoresRepository { |
100 | 44281 | jjdelcerro | |
101 | 44304 | jjdelcerro | public ViewDocumentStoresRepository(String name) { |
102 | super(name);
|
||
103 | } |
||
104 | |||
105 | 46737 | jjdelcerro | 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 | 47045 | jjdelcerro | |
121 | private Map<String, Pair<DataStoreParameters,DataStore>> getAll() { |
||
122 | Map<String, Pair<DataStoreParameters,DataStore>> all = new HashMap<>(); |
||
123 | 46737 | jjdelcerro | List<ViewDocument> views = getOrderedViews();
|
124 | for (ViewDocument view : views) {
|
||
125 | for (FLayer layer : view.layers()) {
|
||
126 | 44281 | jjdelcerro | if (layer instanceof FLyrVect) { |
127 | FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
||
128 | 47045 | jjdelcerro | 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 | 44281 | jjdelcerro | } |
140 | } |
||
141 | } |
||
142 | } |
||
143 | if (all.isEmpty()) {
|
||
144 | return null; |
||
145 | } |
||
146 | return all;
|
||
147 | } |
||
148 | |||
149 | 47045 | jjdelcerro | private Map<String, Pair<FeatureType,FeatureStore>> getAllFeatureTypes() { |
150 | Map<String, Pair<FeatureType,FeatureStore>> all = new HashMap<>(); |
||
151 | 46737 | jjdelcerro | Project project = ProjectManager.getInstance().getCurrentProject(); |
152 | List<Document> views = project.getDocuments(TYPENAME); |
||
153 | 47045 | jjdelcerro | // MutablePair<DataStore,String> storeAndName = new MutablePair<>();
|
154 | 46737 | jjdelcerro | for (Document view : views) { |
155 | for (FLayer layer : ((ViewDocument) view).layers()) {
|
||
156 | if (layer instanceof FLyrVect) { |
||
157 | FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
||
158 | 47045 | jjdelcerro | 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 | 46737 | jjdelcerro | } |
174 | } |
||
175 | 47045 | jjdelcerro | // if (limit > 0 && all.size() >= limit) {
|
176 | // break;
|
||
177 | // }
|
||
178 | 46737 | jjdelcerro | } |
179 | } |
||
180 | if (all.isEmpty()) {
|
||
181 | return null; |
||
182 | } |
||
183 | return all;
|
||
184 | } |
||
185 | |||
186 | 44281 | jjdelcerro | @Override
|
187 | 44304 | jjdelcerro | protected DataStoreParameters getMyParameters(final String name) { |
188 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
189 | 44281 | jjdelcerro | if (all == null) { |
190 | return null; |
||
191 | } |
||
192 | 47051 | jjdelcerro | Pair<DataStoreParameters, DataStore> data = all.get(name); |
193 | if( data == null ) { |
||
194 | return null; |
||
195 | } |
||
196 | return data.getLeft();
|
||
197 | 44281 | jjdelcerro | } |
198 | |||
199 | @Override
|
||
200 | 46737 | jjdelcerro | protected FeatureType getMyFeatureType(String name) { |
201 | 47051 | jjdelcerro | Map<String, Pair<FeatureType, FeatureStore>> all = this.getAllFeatureTypes(); |
202 | 46737 | jjdelcerro | if (all == null) { |
203 | return null; |
||
204 | } |
||
205 | 47051 | jjdelcerro | Pair<FeatureType, FeatureStore> data = all.get(name); |
206 | if( data == null ) { |
||
207 | return null; |
||
208 | } |
||
209 | 47045 | jjdelcerro | return all.get(name).getLeft();
|
210 | 46737 | jjdelcerro | } |
211 | |||
212 | @Override
|
||
213 | 46575 | jjdelcerro | public DataStore getStore(String name) { |
214 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
215 | 47045 | jjdelcerro | if (all == null) { |
216 | return null; |
||
217 | 46575 | jjdelcerro | } |
218 | 47051 | jjdelcerro | Pair<DataStoreParameters, DataStore> data = all.get(name); |
219 | if( data == null ) { |
||
220 | return null; |
||
221 | } |
||
222 | return data.getRight();
|
||
223 | 46575 | jjdelcerro | } |
224 | |||
225 | @Override
|
||
226 | 44281 | jjdelcerro | public boolean containsKey(final String key) { |
227 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all =this.getAll(); |
228 | 44281 | jjdelcerro | if (all == null) { |
229 | return false; |
||
230 | } |
||
231 | return all.containsKey(key);
|
||
232 | } |
||
233 | |||
234 | @Override
|
||
235 | 44304 | jjdelcerro | protected UnmodifiableBasicSet<String> getMyKeySet() { |
236 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
237 | 44281 | jjdelcerro | if (all == null) { |
238 | return null; |
||
239 | } |
||
240 | return new UnmodifiableBasicSetAdapter<>(all.keySet()); |
||
241 | } |
||
242 | |||
243 | @Override
|
||
244 | 44304 | jjdelcerro | protected boolean isEmptyMyRepository() { |
245 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
246 | 44281 | jjdelcerro | return all.isEmpty();
|
247 | } |
||
248 | |||
249 | @Override
|
||
250 | 44304 | jjdelcerro | protected int getMySize() { |
251 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
252 | 44281 | jjdelcerro | return all.size();
|
253 | } |
||
254 | |||
255 | @Override
|
||
256 | public Iterator<DataStoreParameters> iterator() { |
||
257 | 47051 | jjdelcerro | Map<String, Pair<DataStoreParameters, DataStore>> all = this.getAll(); |
258 | 47045 | jjdelcerro | 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 | 44281 | jjdelcerro | } |
271 | |||
272 | public static void selfRegister() { |
||
273 | DataManager dataManager = DALLocator.getDataManager(); |
||
274 | 44306 | jjdelcerro | dataManager.getStoresRepository().addRepository(new ViewDocumentStoresRepository("Project layers")); |
275 | 44281 | jjdelcerro | } |
276 | } |
||
277 | 47045 | jjdelcerro | |
278 | 44281 | jjdelcerro | private static final String PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME |
279 | = "DefaultViewDocument";
|
||
280 | 40435 | jjdelcerro | public static String TYPENAME = "project.document.view2d"; |
281 | private DynStruct persistenceDefinition;
|
||
282 | 46184 | fdiaz | private static int countSeparators = 0; |
283 | |||
284 | 40435 | jjdelcerro | public ViewManager() {
|
285 | 44281 | jjdelcerro | // Do nothing
|
286 | 40435 | jjdelcerro | } |
287 | 44281 | jjdelcerro | |
288 | 45543 | jjdelcerro | @Override
|
289 | 40435 | jjdelcerro | public int getPriority() { |
290 | return 0; |
||
291 | } |
||
292 | |||
293 | 45543 | jjdelcerro | @Override
|
294 | 40435 | jjdelcerro | public ImageIcon getIcon() { |
295 | 44281 | jjdelcerro | return PluginServices.getIconTheme().get("document-view-icon"); |
296 | 40435 | jjdelcerro | } |
297 | |||
298 | 45543 | jjdelcerro | @Override
|
299 | 40435 | jjdelcerro | public ImageIcon getIconSelected() { |
300 | 44281 | jjdelcerro | return PluginServices.getIconTheme().get("document-view-icon-sel"); |
301 | 40435 | jjdelcerro | } |
302 | |||
303 | 45543 | jjdelcerro | @Override
|
304 | 40435 | jjdelcerro | public String getTitle() { |
305 | return PluginServices.getText(this, "Vista"); |
||
306 | } |
||
307 | |||
308 | 45543 | jjdelcerro | @Override
|
309 | 40435 | jjdelcerro | public String getTypeName() { |
310 | return TYPENAME;
|
||
311 | } |
||
312 | 44281 | jjdelcerro | |
313 | 45543 | jjdelcerro | @Override
|
314 | 40435 | jjdelcerro | public Class getMainWindowClass() { |
315 | return DefaultViewPanel.class;
|
||
316 | } |
||
317 | 44281 | jjdelcerro | |
318 | 45543 | jjdelcerro | @Override
|
319 | 40435 | jjdelcerro | public AbstractDocument createDocument() { |
320 | 41634 | jjdelcerro | AbstractDocument doc = new DefaultViewDocument(this); |
321 | 44281 | jjdelcerro | if (this.notifyObservers(NOTIFY_AFTER_CREATEDOCUMENT, doc).isCanceled()) { |
322 | 41634 | jjdelcerro | return null; |
323 | } |
||
324 | 44281 | jjdelcerro | return doc;
|
325 | |||
326 | 40435 | jjdelcerro | } |
327 | |||
328 | 42873 | jjdelcerro | @Override
|
329 | 41634 | jjdelcerro | public IWindow getMainWindow(Document doc, WindowLayout layout) { |
330 | 42873 | jjdelcerro | IDocumentWindow win = (IDocumentWindow) super.getMainWindow(doc, layout);
|
331 | 44281 | jjdelcerro | if (win == null) { |
332 | 42873 | jjdelcerro | win = this.createDocumentWindow(doc);
|
333 | 44281 | jjdelcerro | if (layout != null && win != null) { |
334 | 42873 | jjdelcerro | win.setWindowLayout(layout); |
335 | } |
||
336 | 44281 | jjdelcerro | if (this.notifyObservers(NOTIFY_AFTER_CREATEMAINWINDOW, win).isCanceled()) { |
337 | 43633 | jjdelcerro | return null; |
338 | } |
||
339 | 41634 | jjdelcerro | } |
340 | 44281 | jjdelcerro | if (this.notifyObservers(NOTIFY_AFTER_GETMAINWINDOW, win).isCanceled()) { |
341 | 41634 | jjdelcerro | return null; |
342 | } |
||
343 | ((AbstractDocument) doc).raiseEventCreateWindow(win);
|
||
344 | return win;
|
||
345 | } |
||
346 | 40435 | jjdelcerro | |
347 | 42873 | jjdelcerro | @Override
|
348 | 41634 | jjdelcerro | public IWindow getPropertiesWindow(Document doc) { |
349 | 42873 | jjdelcerro | IWindow win = super.getPropertiesWindow(doc);
|
350 | 44281 | jjdelcerro | if (win == null) { |
351 | 42873 | jjdelcerro | win = new ViewProperties((DefaultViewDocument) doc);
|
352 | 44281 | jjdelcerro | if (this.notifyObservers(NOTIFY_AFTER_CREATEPROPERTIESWINDOW, win).isCanceled()) { |
353 | 43633 | jjdelcerro | return null; |
354 | } |
||
355 | 42873 | jjdelcerro | } |
356 | 44281 | jjdelcerro | if (this.notifyObservers(NOTIFY_AFTER_GETPROPERTIESWINDOW, win).isCanceled()) { |
357 | 41634 | jjdelcerro | return null; |
358 | } |
||
359 | return win;
|
||
360 | } |
||
361 | |||
362 | 41081 | jjdelcerro | public void addTOCContextAction(String theAction) { |
363 | 44281 | jjdelcerro | 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 | 41081 | jjdelcerro | } |
372 | 44281 | jjdelcerro | |
373 | 42175 | jjdelcerro | public void addTOCContextAction(String theAction, String group, int groupOrder, int order) { |
374 | 44281 | jjdelcerro | 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 | 45130 | omartinez | new ActionInfoAdapterToContextMenuAction(action, group, groupOrder, order)
|
384 | 42175 | jjdelcerro | ); |
385 | } |
||
386 | 44281 | jjdelcerro | |
387 | 41081 | jjdelcerro | public void addTOCContextAction(ActionInfo action) { |
388 | 44281 | jjdelcerro | this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, "default", 9000)); |
389 | 41081 | jjdelcerro | } |
390 | 44281 | jjdelcerro | |
391 | 41559 | jjdelcerro | public void addTOCContextAction(ActionInfo action, String group, int groupOrder) { |
392 | 44281 | jjdelcerro | this.addTOCContextAction(action.getName(), new ActionInfoAdapterToContextMenuAction(action, group, groupOrder)); |
393 | 41559 | jjdelcerro | } |
394 | 44281 | jjdelcerro | |
395 | 45945 | fdiaz | public void addTOCSeparator(String group, int groupOrder, int order) { |
396 | 46184 | fdiaz | |
397 | String effectiveGroup = group + "/-" + (countSeparators++) + "-"; |
||
398 | |||
399 | 45945 | fdiaz | this.addTOCContextAction(
|
400 | 46184 | fdiaz | // group + "/-",
|
401 | effectiveGroup, |
||
402 | 45945 | fdiaz | 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 | 46184 | fdiaz | return effectiveGroup; //group + "/-"; |
420 | 45945 | fdiaz | } |
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 | 41559 | jjdelcerro | class ActionInfoAdapterToContextMenuAction extends AbstractActionInfoAdapterToTocContextMenuAction { |
446 | 44281 | jjdelcerro | |
447 | ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder) { |
||
448 | 41559 | jjdelcerro | super(action, group, groupOrder);
|
449 | 44281 | jjdelcerro | } |
450 | |||
451 | ActionInfoAdapterToContextMenuAction(ActionInfo action, String group, int groupOrder, int order) { |
||
452 | super(action, group, groupOrder, order);
|
||
453 | } |
||
454 | 41081 | jjdelcerro | } |
455 | 44281 | jjdelcerro | |
456 | 41559 | jjdelcerro | /**
|
457 | 44281 | jjdelcerro | * @deprecated use addTOCContextAction(ActionInfo action, String group, int
|
458 | * groupOrder)
|
||
459 | 41559 | jjdelcerro | * @param id
|
460 | 44281 | jjdelcerro | * @param action
|
461 | 41559 | jjdelcerro | */
|
462 | 41081 | jjdelcerro | public void addTOCContextAction(String id, IContextMenuAction action) { |
463 | 44281 | jjdelcerro | 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 | 41081 | jjdelcerro | } |
472 | |||
473 | class ContextMenuActionAdapterToExtensionBuilder implements ExtensionBuilder { |
||
474 | 44281 | jjdelcerro | |
475 | IContextMenuAction menuAction = null;
|
||
476 | |||
477 | ContextMenuActionAdapterToExtensionBuilder(IContextMenuAction menuAction) { |
||
478 | this.menuAction = menuAction;
|
||
479 | } |
||
480 | |||
481 | 45543 | jjdelcerro | @Override
|
482 | 44281 | jjdelcerro | public Object create() { |
483 | return this.menuAction; |
||
484 | } |
||
485 | |||
486 | 45543 | jjdelcerro | @Override
|
487 | 44281 | jjdelcerro | public Object create(Object[] args) { |
488 | return this.menuAction; |
||
489 | } |
||
490 | |||
491 | 45543 | jjdelcerro | @Override
|
492 | 44281 | jjdelcerro | public Object create(Map args) { |
493 | return this.menuAction; |
||
494 | } |
||
495 | 41081 | jjdelcerro | } |
496 | 44281 | jjdelcerro | |
497 | 41104 | jjdelcerro | private static void initializeRegisterTOCActions() { |
498 | 44281 | jjdelcerro | ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
499 | 41104 | jjdelcerro | |
500 | 44281 | jjdelcerro | 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 | 41104 | jjdelcerro | } |
510 | 44281 | jjdelcerro | |
511 | 40435 | jjdelcerro | /**
|
512 | * Registers in the points of extension the Factory with alias.
|
||
513 | *
|
||
514 | */
|
||
515 | public static void register() { |
||
516 | ViewManager factory = new ViewManager();
|
||
517 | 44281 | jjdelcerro | ProjectManager.getInstance().registerDocumentFactory(factory); |
518 | |||
519 | 40435 | jjdelcerro | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
520 | manager.registerFactory(factory); |
||
521 | |||
522 | 41104 | jjdelcerro | initializeRegisterTOCActions(); |
523 | 40435 | jjdelcerro | |
524 | 44281 | jjdelcerro | 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 | 46261 | jjdelcerro | IconThemeHelper.registerIcon("cursor", "cursor-busy", ViewManager.class); |
532 | 44281 | jjdelcerro | 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 | 41121 | jldominguez | IconThemeHelper.registerIcon("cursor", "cursor-select-by-polygon", ViewManager.class); |
538 | IconThemeHelper.registerIcon("cursor", "cursor-select-by-rectangle", ViewManager.class); |
||
539 | 44281 | jjdelcerro | IconThemeHelper.registerIcon("cursor", "cursor-zoom-in", ViewManager.class); |
540 | IconThemeHelper.registerIcon("cursor", "cursor-zoom-out", ViewManager.class); |
||
541 | 40435 | jjdelcerro | |
542 | 44281 | jjdelcerro | 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 | 47423 | jjdelcerro | 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 | 40435 | jjdelcerro | |
565 | 44281 | jjdelcerro | 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 | 40435 | jjdelcerro | |
569 | 44281 | jjdelcerro | 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 | 40435 | jjdelcerro | factory.persistenceDefinition = manager.addDefinition( |
579 | 44281 | jjdelcerro | ViewDocument.class, |
580 | PERSISTENCE_VIEW_DOCUMENT_DEFINITION_NAME, |
||
581 | "Default view document persistence definition",
|
||
582 | null,
|
||
583 | null
|
||
584 | 40435 | jjdelcerro | ); |
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 | 41350 | jjdelcerro | factory.persistenceDefinition.addDynFieldObject("propertiesHelper").setClassOfValue(ExtendedPropertiesHelper.class)
|
591 | 44281 | jjdelcerro | .setMandatory(false);
|
592 | |||
593 | 40435 | jjdelcerro | } |
594 | 44281 | jjdelcerro | ViewDocumentStoresRepository.selfRegister(); |
595 | ViewZoomActionFactory.selfRegister(); |
||
596 | 46089 | omartinez | AddFilterToLayerActionFactory.selfRegister(); |
597 | CreateTemporalLayerAction.CreateTemporalLayerActionFactory.selfRegister(); |
||
598 | 40435 | jjdelcerro | } |
599 | |||
600 | @SuppressWarnings("rawtypes") |
||
601 | 45543 | jjdelcerro | @Override
|
602 | 40435 | jjdelcerro | public DynStruct getDefinition(String className) { |
603 | |||
604 | 44281 | jjdelcerro | if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) { |
605 | 40435 | jjdelcerro | return this.persistenceDefinition; |
606 | } |
||
607 | 44281 | jjdelcerro | if (this.persistenceDefinition.getFullName().equalsIgnoreCase(className)) { |
608 | 40435 | jjdelcerro | return this.persistenceDefinition; |
609 | } |
||
610 | 44281 | jjdelcerro | if (this.getDocumentClass().getName().equals(className)) { |
611 | 40435 | jjdelcerro | return this.persistenceDefinition; |
612 | } |
||
613 | |||
614 | return null; |
||
615 | } |
||
616 | |||
617 | @SuppressWarnings("rawtypes") |
||
618 | 45543 | jjdelcerro | @Override
|
619 | 40435 | jjdelcerro | protected Class getDocumentClass() { |
620 | return DefaultViewDocument.class;
|
||
621 | } |
||
622 | |||
623 | 45543 | jjdelcerro | @Override
|
624 | 40435 | jjdelcerro | public boolean manages(Object object) { |
625 | return object instanceof ViewDocument; |
||
626 | } |
||
627 | 46184 | fdiaz | |
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 | 40435 | jjdelcerro | } |