svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ViewInvertSelection.java @ 44535
History | View | Annotate | Download (4.88 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | 41248 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40435 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40435 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40435 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | import org.gvsig.andami.IconThemeHelper; |
||
26 | import org.gvsig.andami.messages.NotificationManager; |
||
27 | import org.gvsig.andami.plugins.Extension; |
||
28 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
29 | import org.gvsig.app.ApplicationManager; |
||
30 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
31 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
32 | 41264 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
33 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
34 | import org.gvsig.fmap.dal.exception.DataException; |
||
35 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
36 | 44437 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType; |
37 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContext; |
38 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
39 | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
||
40 | 44437 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
41 | 40435 | jjdelcerro | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; |
||
43 | |||
44 | /**
|
||
45 | * Extension that handles the selection tools, selection tools have sense on
|
||
46 | * vectorial layers only.
|
||
47 | *
|
||
48 | */
|
||
49 | public class ViewInvertSelection extends Extension { |
||
50 | 41248 | jjdelcerro | |
51 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
52 | .getLogger(ViewInvertSelection.class); |
||
53 | 41248 | jjdelcerro | private DefaultViewPanel vista;
|
54 | 40435 | jjdelcerro | |
55 | 41248 | jjdelcerro | public void initialize() { |
56 | IconThemeHelper.registerIcon("action", "selection-reverse", this); |
||
57 | } |
||
58 | 40435 | jjdelcerro | |
59 | 41248 | jjdelcerro | public void postInitialize() { |
60 | } |
||
61 | 40435 | jjdelcerro | |
62 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
63 | ApplicationManager application = ApplicationLocator.getManager(); |
||
64 | 40435 | jjdelcerro | |
65 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
66 | if (view == null) { |
||
67 | return ;
|
||
68 | 41248 | jjdelcerro | } |
69 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
70 | 40435 | jjdelcerro | |
71 | 41248 | jjdelcerro | MapContext mapa = document.getMapContext(); |
72 | 40435 | jjdelcerro | |
73 | 41248 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-reverse-view")) { |
74 | FLayer[] actives = mapa.getLayers().getActives();
|
||
75 | for (FLayer lyr : actives) {
|
||
76 | if (lyr.isAvailable() && lyr instanceof SingleLayer) { |
||
77 | SingleLayer lyrSingle = (SingleLayer) lyr; |
||
78 | DataStore ds = lyrSingle.getDataStore(); |
||
79 | if (ds instanceof FeatureStore) { |
||
80 | try {
|
||
81 | ((FeatureStore) ds).getFeatureSelection().reverse(); |
||
82 | document.setModified(true);
|
||
83 | } catch (DataException e) {
|
||
84 | NotificationManager.addError(e); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | 40435 | jjdelcerro | |
92 | 44437 | jjdelcerro | @Override
|
93 | 41248 | jjdelcerro | public boolean isEnabled() { |
94 | ApplicationManager application = ApplicationLocator.getManager(); |
||
95 | 40435 | jjdelcerro | |
96 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
97 | if (view == null) { |
||
98 | 41248 | jjdelcerro | return false; |
99 | } |
||
100 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
101 | 44437 | jjdelcerro | if( document == null ) { |
102 | return false; |
||
103 | } |
||
104 | boolean hasActiveVectorLayers = false; |
||
105 | for (FLayer layer : document.getMapContext().getLayers()) {
|
||
106 | if( layer.isActive() && layer.isAvailable() && layer instanceof FLyrVect ) { |
||
107 | try {
|
||
108 | hasActiveVectorLayers = true;
|
||
109 | FeatureStore store = ((FLyrVect)layer).getFeatureStore(); |
||
110 | if( !store.getFeatureSelection().isAvailable() ) {
|
||
111 | return false; |
||
112 | } |
||
113 | } catch (Exception ex) { |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | return hasActiveVectorLayers;
|
||
118 | 41248 | jjdelcerro | } |
119 | 40435 | jjdelcerro | |
120 | 41248 | jjdelcerro | public boolean isVisible() { |
121 | ApplicationManager application = ApplicationLocator.getManager(); |
||
122 | 40435 | jjdelcerro | |
123 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
124 | if (view == null) { |
||
125 | 41248 | jjdelcerro | return false; |
126 | } |
||
127 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
128 | 41248 | jjdelcerro | return document.getMapContext().hasVectorLayers();
|
129 | } |
||
130 | |||
131 | 40435 | jjdelcerro | } |