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