root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ClearSelectionExtension.java @ 38564
History | View | Annotate | Download (5.56 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 | 29596 | jpiera | package org.gvsig.app.extension; |
48 | 6599 | caballero | |
49 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
50 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
51 | import org.gvsig.andami.messages.NotificationManager; |
||
52 | import org.gvsig.andami.plugins.Extension; |
||
53 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.AbstractDocument; |
54 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
55 | import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
||
56 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
57 | import org.gvsig.fmap.dal.exception.ReadException; |
||
58 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
59 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
60 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
61 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
62 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
63 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
64 | |||
65 | 6599 | caballero | |
66 | |||
67 | /**
|
||
68 | * Extensi?n encargada de limpiar la selecci?n.
|
||
69 | *
|
||
70 | * @author Vicente Caballero Navarro
|
||
71 | */
|
||
72 | public class ClearSelectionExtension extends Extension { |
||
73 | /**
|
||
74 | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
||
75 | */
|
||
76 | public void execute(String s) { |
||
77 | 38564 | jjdelcerro | if (s.equalsIgnoreCase("selection-clear-view") ) { |
78 | 6599 | caballero | boolean refresh = false; |
79 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow(); |
80 | 6599 | caballero | |
81 | 31496 | jjdelcerro | if (view instanceof AbstractViewPanel){ |
82 | AbstractViewPanel vista = (AbstractViewPanel) view; |
||
83 | ViewDocument model = vista.getModel(); |
||
84 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
85 | 6599 | caballero | MapControl mapCtrl = vista.getMapControl(); |
86 | 9482 | fdiaz | FLayers layers = mapa.getLayers(); |
87 | refresh = clearSelectionOfView(layers); |
||
88 | 6599 | caballero | |
89 | 25970 | vcaballero | if (refresh) {
|
90 | mapCtrl.drawMap(false);
|
||
91 | } |
||
92 | 31496 | jjdelcerro | ((AbstractDocument)vista.getModel()).setModified(true); |
93 | 6599 | caballero | } |
94 | 36443 | cordinyana | } |
95 | 6599 | caballero | } |
96 | |||
97 | 9482 | fdiaz | |
98 | private boolean clearSelectionOfView(FLayers layers){ |
||
99 | boolean refresh=false; |
||
100 | 9532 | caballero | |
101 | 9482 | fdiaz | for (int i = 0; i < layers.getLayersCount(); i++) { |
102 | FLayer lyr =layers.getLayer(i); |
||
103 | if (lyr instanceof FLayers){ |
||
104 | refresh = refresh || clearSelectionOfView((FLayers) lyr); |
||
105 | } else if (lyr instanceof FLyrVect) { |
||
106 | 9532 | caballero | FLyrVect lyrVect = (FLyrVect) lyr; |
107 | 9482 | fdiaz | if (lyrVect.isActive()) {
|
108 | try {
|
||
109 | 21665 | vcaballero | FeatureStore featureStore; |
110 | 9482 | fdiaz | |
111 | 21665 | vcaballero | featureStore = ((FLyrVect)lyr).getFeatureStore(); |
112 | 24759 | jmvivo | if (featureStore.getFeatureSelection().getSize() != 0) { |
113 | 9482 | fdiaz | refresh = true;
|
114 | } |
||
115 | 24759 | jmvivo | featureStore.getFeatureSelection().deselectAll(); |
116 | 21354 | vcaballero | } catch (ReadException e) {
|
117 | 9482 | fdiaz | e.printStackTrace(); |
118 | 22367 | vcaballero | } catch (DataException e) {
|
119 | // TODO Auto-generated catch block
|
||
120 | e.printStackTrace(); |
||
121 | 9482 | fdiaz | } |
122 | } |
||
123 | } |
||
124 | } |
||
125 | return refresh;
|
||
126 | } |
||
127 | 6599 | caballero | /**
|
128 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
129 | */
|
||
130 | public boolean isVisible() { |
||
131 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
132 | 6599 | caballero | |
133 | if (view == null) { |
||
134 | return false; |
||
135 | } |
||
136 | 31496 | jjdelcerro | if (view instanceof AbstractViewPanel) { |
137 | MapContext mapa = ((AbstractViewPanel) view).getModel().getMapContext(); |
||
138 | 6599 | caballero | return mapa.getLayers().getLayersCount() > 0; |
139 | } |
||
140 | |||
141 | return false; |
||
142 | } |
||
143 | |||
144 | /**
|
||
145 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
146 | 6599 | caballero | */
|
147 | public boolean isEnabled() { |
||
148 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
149 | 6599 | caballero | if (view == null) { |
150 | return false; |
||
151 | } |
||
152 | 31496 | jjdelcerro | if (view instanceof AbstractViewPanel){ |
153 | MapContext mapa = ((AbstractViewPanel) view).getMapControl().getMapContext(); |
||
154 | 9482 | fdiaz | return hasVectorLayersWithSelection(mapa.getLayers());
|
155 | 6599 | caballero | } |
156 | return false; |
||
157 | } |
||
158 | |||
159 | 9482 | fdiaz | private boolean hasVectorLayersWithSelection(FLayers layers) { |
160 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
161 | FLayer lyr =layers.getLayer(i); |
||
162 | if (lyr instanceof FLayers){ |
||
163 | if (hasVectorLayersWithSelection((FLayers) lyr)){
|
||
164 | return true; |
||
165 | } |
||
166 | } else if (lyr instanceof FLyrVect) { |
||
167 | 9532 | caballero | FLyrVect lyrVect = (FLyrVect) lyr; |
168 | 9482 | fdiaz | if (lyrVect.isActive()) {
|
169 | if (lyrVect.isAvailable()){
|
||
170 | try {
|
||
171 | 24759 | jmvivo | if (lyrVect.getFeatureStore().getFeatureSelection()
|
172 | .getSize() > 0) {
|
||
173 | 9482 | fdiaz | return true; |
174 | 24759 | jmvivo | } |
175 | } catch (DataException e) {
|
||
176 | 9482 | fdiaz | e.printStackTrace(); |
177 | NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | return false; |
||
184 | } |
||
185 | |||
186 | 6599 | caballero | /**
|
187 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
188 | 6599 | caballero | */
|
189 | public void initialize() { |
||
190 | 38564 | jjdelcerro | IconThemeHelper.registerIcon("action", "edit-clear", this); |
191 | 6599 | caballero | } |
192 | } |