svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ClearSelectionExtension.java @ 22932
History | View | Annotate | Download (6.36 KB)
1 |
/*
|
---|---|
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 |
import org.gvsig.fmap.data.DataCollection; |
50 |
import org.gvsig.fmap.data.DataException; |
51 |
import org.gvsig.fmap.data.ReadException; |
52 |
import org.gvsig.fmap.data.feature.FeatureStore; |
53 |
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 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.andami.messages.NotificationManager; |
61 |
import com.iver.andami.plugins.Extension; |
62 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
63 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
64 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
65 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
66 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
67 |
|
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 |
com.iver.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow(); |
82 |
|
83 |
if (view instanceof BaseView){ |
84 |
BaseView vista = (BaseView) view; |
85 |
IProjectView model = vista.getModel(); |
86 |
MapContext mapa = model.getMapContext(); |
87 |
MapControl mapCtrl = vista.getMapControl(); |
88 |
FLayers layers = mapa.getLayers(); |
89 |
refresh = clearSelectionOfView(layers); |
90 |
|
91 |
// if (refresh) {
|
92 |
// mapCtrl.drawMap(false);
|
93 |
// }
|
94 |
((ProjectDocument)vista.getModel()).setModified(true);
|
95 |
}else if (view instanceof Table){ |
96 |
Table table = (Table) view; |
97 |
ProjectTable model = table.getModel(); |
98 |
FeatureStore featureStore=null;
|
99 |
// try {
|
100 |
featureStore = model.getModel(); |
101 |
// } catch (ReadException e) {
|
102 |
// e.printStackTrace();
|
103 |
// }
|
104 |
if (featureStore.getSelection().size() != 0) { |
105 |
refresh = true;
|
106 |
} |
107 |
featureStore.getSelection().clear(); |
108 |
// if (refresh) {
|
109 |
// table.refresh();
|
110 |
// }
|
111 |
table.getModel().setModified(true);
|
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
|
117 |
private boolean clearSelectionOfView(FLayers layers){ |
118 |
boolean refresh=false; |
119 |
|
120 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
121 |
FLayer lyr =layers.getLayer(i); |
122 |
if (lyr instanceof FLayers){ |
123 |
refresh = refresh || clearSelectionOfView((FLayers) lyr); |
124 |
} else if (lyr instanceof FLyrVect) { |
125 |
FLyrVect lyrVect = (FLyrVect) lyr; |
126 |
if (lyrVect.isActive()) {
|
127 |
try {
|
128 |
FeatureStore featureStore; |
129 |
|
130 |
featureStore = ((FLyrVect)lyr).getFeatureStore(); |
131 |
if (featureStore.getSelection().size() != 0) { |
132 |
refresh = true;
|
133 |
} |
134 |
DataCollection dc=featureStore.createSelection(); |
135 |
featureStore.setSelection(dc); |
136 |
} catch (ReadException e) {
|
137 |
e.printStackTrace(); |
138 |
} catch (DataException e) {
|
139 |
// TODO Auto-generated catch block
|
140 |
e.printStackTrace(); |
141 |
} |
142 |
} |
143 |
} |
144 |
} |
145 |
return refresh;
|
146 |
} |
147 |
/**
|
148 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
149 |
*/
|
150 |
public boolean isVisible() { |
151 |
com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
152 |
|
153 |
if (view == null) { |
154 |
return false; |
155 |
} |
156 |
if (view instanceof BaseView) { |
157 |
MapContext mapa = ((BaseView) view).getModel().getMapContext(); |
158 |
return mapa.getLayers().getLayersCount() > 0; |
159 |
} |
160 |
if (view instanceof Table) { |
161 |
return true; |
162 |
} |
163 |
|
164 |
return false; |
165 |
} |
166 |
|
167 |
/**
|
168 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
169 |
*/
|
170 |
public boolean isEnabled() { |
171 |
com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
172 |
if (view == null) { |
173 |
return false; |
174 |
} |
175 |
if (view instanceof BaseView){ |
176 |
MapContext mapa = ((BaseView) view).getMapControl().getMapContext(); |
177 |
return hasVectorLayersWithSelection(mapa.getLayers());
|
178 |
} |
179 |
if (view instanceof Table){ |
180 |
return ((Table)view).getSelectedRowIndices().length>0; |
181 |
} |
182 |
return false; |
183 |
} |
184 |
|
185 |
private boolean hasVectorLayersWithSelection(FLayers layers) { |
186 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
187 |
FLayer lyr =layers.getLayer(i); |
188 |
if (lyr instanceof FLayers){ |
189 |
if (hasVectorLayersWithSelection((FLayers) lyr)){
|
190 |
return true; |
191 |
} |
192 |
} else if (lyr instanceof FLyrVect) { |
193 |
FLyrVect lyrVect = (FLyrVect) lyr; |
194 |
if (lyrVect.isActive()) {
|
195 |
if (lyrVect.isAvailable()){
|
196 |
try {
|
197 |
if (lyrVect.getFeatureStore().getSelection().size() > 0) |
198 |
return true; |
199 |
} catch (ReadException e) {
|
200 |
e.printStackTrace(); |
201 |
NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
202 |
} |
203 |
} |
204 |
} |
205 |
} |
206 |
} |
207 |
return false; |
208 |
} |
209 |
|
210 |
/**
|
211 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
212 |
*/
|
213 |
public void initialize() { |
214 |
registerIcons(); |
215 |
} |
216 |
|
217 |
private void registerIcons(){ |
218 |
PluginServices.getIconTheme().registerDefault( |
219 |
"view-clear-selection",
|
220 |
this.getClass().getClassLoader().getResource("images/delselection.png") |
221 |
); |
222 |
} |
223 |
} |