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 / ClearSelectionExtension.java @ 40558
History | View | Annotate | Download (6.5 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 | /*
|
25 | * Created on 31-may-2004
|
||
26 | *
|
||
27 | * To change the template for this generated file go to
|
||
28 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
29 | */
|
||
30 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
31 | *
|
||
32 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
33 | *
|
||
34 | * This program is free software; you can redistribute it and/or
|
||
35 | * modify it under the terms of the GNU General Public License
|
||
36 | * as published by the Free Software Foundation; either version 2
|
||
37 | * of the License, or (at your option) any later version.
|
||
38 | *
|
||
39 | * This program is distributed in the hope that it will be useful,
|
||
40 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
41 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
42 | * GNU General Public License for more details.
|
||
43 | *
|
||
44 | * You should have received a copy of the GNU General Public License
|
||
45 | * along with this program; if not, write to the Free Software
|
||
46 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
47 | *
|
||
48 | * For more information, contact:
|
||
49 | *
|
||
50 | * Generalitat Valenciana
|
||
51 | * Conselleria d'Infraestructures i Transport
|
||
52 | * Av. Blasco Ib??ez, 50
|
||
53 | * 46010 VALENCIA
|
||
54 | * SPAIN
|
||
55 | *
|
||
56 | * +34 963862235
|
||
57 | * gvsig@gva.es
|
||
58 | * www.gvsig.gva.es
|
||
59 | *
|
||
60 | * or
|
||
61 | *
|
||
62 | * IVER T.I. S.A
|
||
63 | * Salamanca 50
|
||
64 | * 46005 Valencia
|
||
65 | * Spain
|
||
66 | *
|
||
67 | * +34 963163400
|
||
68 | * dac@iver.es
|
||
69 | */
|
||
70 | package org.gvsig.app.extension; |
||
71 | |||
72 | import org.gvsig.andami.IconThemeHelper; |
||
73 | import org.gvsig.andami.PluginServices; |
||
74 | import org.gvsig.andami.messages.NotificationManager; |
||
75 | import org.gvsig.andami.plugins.Extension; |
||
76 | import org.gvsig.app.project.documents.AbstractDocument; |
||
77 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
78 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
79 | import org.gvsig.fmap.dal.exception.DataException; |
||
80 | import org.gvsig.fmap.dal.exception.ReadException; |
||
81 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
82 | import org.gvsig.fmap.mapcontext.MapContext; |
||
83 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
84 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
85 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
86 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
87 | |||
88 | |||
89 | |||
90 | /**
|
||
91 | * Extensi?n encargada de limpiar la selecci?n.
|
||
92 | *
|
||
93 | * @author Vicente Caballero Navarro
|
||
94 | */
|
||
95 | public class ClearSelectionExtension extends Extension { |
||
96 | /**
|
||
97 | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
||
98 | */
|
||
99 | public void execute(String s) { |
||
100 | if (s.equalsIgnoreCase("selection-clear-view") ) { |
||
101 | boolean refresh = false; |
||
102 | org.gvsig.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow(); |
||
103 | |||
104 | if (view instanceof AbstractViewPanel){ |
||
105 | AbstractViewPanel vista = (AbstractViewPanel) view; |
||
106 | ViewDocument model = vista.getModel(); |
||
107 | MapContext mapa = model.getMapContext(); |
||
108 | MapControl mapCtrl = vista.getMapControl(); |
||
109 | FLayers layers = mapa.getLayers(); |
||
110 | refresh = clearSelectionOfView(layers); |
||
111 | |||
112 | if (refresh) {
|
||
113 | mapCtrl.drawMap(false);
|
||
114 | } |
||
115 | ((AbstractDocument)vista.getModel()).setModified(true); |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
120 | |||
121 | private boolean clearSelectionOfView(FLayers layers){ |
||
122 | boolean refresh=false; |
||
123 | |||
124 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
125 | FLayer lyr =layers.getLayer(i); |
||
126 | if (lyr instanceof FLayers){ |
||
127 | refresh = refresh || clearSelectionOfView((FLayers) lyr); |
||
128 | } else if (lyr instanceof FLyrVect) { |
||
129 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
130 | if (lyrVect.isActive()) {
|
||
131 | try {
|
||
132 | FeatureStore featureStore; |
||
133 | |||
134 | featureStore = ((FLyrVect)lyr).getFeatureStore(); |
||
135 | if (featureStore.getFeatureSelection().getSize() != 0) { |
||
136 | refresh = true;
|
||
137 | } |
||
138 | featureStore.getFeatureSelection().deselectAll(); |
||
139 | } catch (ReadException e) {
|
||
140 | e.printStackTrace(); |
||
141 | } catch (DataException e) {
|
||
142 | // TODO Auto-generated catch block
|
||
143 | e.printStackTrace(); |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | return refresh;
|
||
149 | } |
||
150 | /**
|
||
151 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
152 | */
|
||
153 | public boolean isVisible() { |
||
154 | org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
||
155 | |||
156 | if (view == null) { |
||
157 | return false; |
||
158 | } |
||
159 | if (view instanceof AbstractViewPanel) { |
||
160 | MapContext mapa = ((AbstractViewPanel) view).getModel().getMapContext(); |
||
161 | return mapa.getLayers().getLayersCount() > 0; |
||
162 | } |
||
163 | |||
164 | return false; |
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
||
169 | */
|
||
170 | public boolean isEnabled() { |
||
171 | org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
||
172 | if (view == null) { |
||
173 | return false; |
||
174 | } |
||
175 | if (view instanceof AbstractViewPanel){ |
||
176 | MapContext mapa = ((AbstractViewPanel) view).getMapControl().getMapContext(); |
||
177 | return hasVectorLayersWithSelection(mapa.getLayers());
|
||
178 | } |
||
179 | return false; |
||
180 | } |
||
181 | |||
182 | private boolean hasVectorLayersWithSelection(FLayers layers) { |
||
183 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
184 | FLayer lyr =layers.getLayer(i); |
||
185 | if (lyr instanceof FLayers){ |
||
186 | if (hasVectorLayersWithSelection((FLayers) lyr)){
|
||
187 | return true; |
||
188 | } |
||
189 | } else if (lyr instanceof FLyrVect) { |
||
190 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
191 | if (lyrVect.isActive()) {
|
||
192 | if (lyrVect.isAvailable()){
|
||
193 | try {
|
||
194 | if (lyrVect.getFeatureStore().getFeatureSelection()
|
||
195 | .getSize() > 0) {
|
||
196 | return true; |
||
197 | } |
||
198 | } catch (DataException e) {
|
||
199 | e.printStackTrace(); |
||
200 | NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | } |
||
206 | return false; |
||
207 | } |
||
208 | |||
209 | /**
|
||
210 | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
||
211 | */
|
||
212 | public void initialize() { |
||
213 | IconThemeHelper.registerIcon("action", "edit-clear", this); |
||
214 | } |
||
215 | } |