root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ClearSelectionExtension.java @ 20903
History | View | Annotate | Download (6.15 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 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
50 | 6599 | caballero | import com.iver.andami.PluginServices; |
51 | 7011 | fjp | import com.iver.andami.messages.NotificationManager; |
52 | 6599 | caballero | import com.iver.andami.plugins.Extension; |
53 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
54 | 6599 | caballero | import com.iver.cit.gvsig.fmap.MapControl; |
55 | 9482 | fdiaz | import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
57 | 6599 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
58 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
59 | 9532 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
60 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
61 | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
||
62 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
63 | 18345 | vcaballero | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
64 | 6599 | caballero | |
65 | |||
66 | /**
|
||
67 | * Extensi?n encargada de limpiar la selecci?n.
|
||
68 | *
|
||
69 | * @author Vicente Caballero Navarro
|
||
70 | */
|
||
71 | public class ClearSelectionExtension extends Extension { |
||
72 | /**
|
||
73 | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
||
74 | */
|
||
75 | public void execute(String s) { |
||
76 | if (s.compareTo("DEL_SELECTION") == 0) { |
||
77 | boolean refresh = false; |
||
78 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view =PluginServices.getMDIManager().getActiveWindow(); |
79 | 6599 | caballero | |
80 | 18345 | vcaballero | if (view instanceof BaseView){ |
81 | BaseView vista = (BaseView) view; |
||
82 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
83 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
84 | 6599 | caballero | MapControl mapCtrl = vista.getMapControl(); |
85 | 9482 | fdiaz | FLayers layers = mapa.getLayers(); |
86 | refresh = clearSelectionOfView(layers); |
||
87 | 6599 | caballero | |
88 | if (refresh) {
|
||
89 | mapCtrl.drawMap(false);
|
||
90 | } |
||
91 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
92 | 6599 | caballero | }else if (view instanceof Table){ |
93 | Table table = (Table) view; |
||
94 | ProjectTable model = table.getModel(); |
||
95 | 10626 | caballero | SelectableDataSource dataSource=null;
|
96 | try {
|
||
97 | dataSource = model.getModelo().getRecordset(); |
||
98 | } catch (ReadDriverException e) {
|
||
99 | e.printStackTrace(); |
||
100 | } |
||
101 | 6599 | caballero | if (dataSource.getSelection().cardinality() != 0) { |
102 | refresh = true;
|
||
103 | } |
||
104 | dataSource.clearSelection(); |
||
105 | if (refresh) {
|
||
106 | table.refresh(); |
||
107 | } |
||
108 | 9532 | caballero | table.getModel().setModified(true);
|
109 | 6599 | caballero | } |
110 | } |
||
111 | } |
||
112 | |||
113 | 9482 | fdiaz | |
114 | private boolean clearSelectionOfView(FLayers layers){ |
||
115 | boolean refresh=false; |
||
116 | 9532 | caballero | |
117 | 9482 | fdiaz | for (int i = 0; i < layers.getLayersCount(); i++) { |
118 | FLayer lyr =layers.getLayer(i); |
||
119 | if (lyr instanceof FLayers){ |
||
120 | refresh = refresh || clearSelectionOfView((FLayers) lyr); |
||
121 | } else if (lyr instanceof FLyrVect) { |
||
122 | 9532 | caballero | FLyrVect lyrVect = (FLyrVect) lyr; |
123 | 9482 | fdiaz | if (lyrVect.isActive()) {
|
124 | try {
|
||
125 | SelectableDataSource dataSource; |
||
126 | |||
127 | dataSource = ((FLyrVect)lyr).getRecordset(); |
||
128 | if (dataSource.getSelection().cardinality() != 0) { |
||
129 | refresh = true;
|
||
130 | } |
||
131 | dataSource.clearSelection(); |
||
132 | 10626 | caballero | } catch (ReadDriverException e) {
|
133 | 9482 | fdiaz | e.printStackTrace(); |
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | return refresh;
|
||
139 | } |
||
140 | 6599 | caballero | /**
|
141 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
142 | */
|
||
143 | public boolean isVisible() { |
||
144 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
145 | 6599 | caballero | |
146 | if (view == null) { |
||
147 | return false; |
||
148 | } |
||
149 | 18345 | vcaballero | if (view instanceof BaseView) { |
150 | MapContext mapa = ((BaseView) view).getModel().getMapContext(); |
||
151 | 6599 | caballero | return mapa.getLayers().getLayersCount() > 0; |
152 | } |
||
153 | if (view instanceof Table) { |
||
154 | return true; |
||
155 | } |
||
156 | |||
157 | return false; |
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
162 | */
|
||
163 | public boolean isEnabled() { |
||
164 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
165 | 6599 | caballero | if (view == null) { |
166 | return false; |
||
167 | } |
||
168 | 18345 | vcaballero | if (view instanceof BaseView){ |
169 | MapContext mapa = ((BaseView) view).getMapControl().getMapContext(); |
||
170 | 9482 | fdiaz | return hasVectorLayersWithSelection(mapa.getLayers());
|
171 | 6599 | caballero | } |
172 | if (view instanceof Table){ |
||
173 | return ((Table)view).getSelectedRowIndices().length>0; |
||
174 | } |
||
175 | return false; |
||
176 | } |
||
177 | |||
178 | 9482 | fdiaz | private boolean hasVectorLayersWithSelection(FLayers layers) { |
179 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
180 | FLayer lyr =layers.getLayer(i); |
||
181 | if (lyr instanceof FLayers){ |
||
182 | if (hasVectorLayersWithSelection((FLayers) lyr)){
|
||
183 | return true; |
||
184 | } |
||
185 | } else if (lyr instanceof FLyrVect) { |
||
186 | 9532 | caballero | FLyrVect lyrVect = (FLyrVect) lyr; |
187 | 9482 | fdiaz | if (lyrVect.isActive()) {
|
188 | if (lyrVect.isAvailable()){
|
||
189 | try {
|
||
190 | if (lyrVect.getRecordset().getSelection().cardinality() > 0) |
||
191 | return true; |
||
192 | 10626 | caballero | } catch (ReadDriverException e) {
|
193 | 9482 | fdiaz | e.printStackTrace(); |
194 | NotificationManager.addWarning("Capa " + lyrVect.getName() + " sin recordset correcto",e); |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | } |
||
200 | return false; |
||
201 | } |
||
202 | |||
203 | 6599 | caballero | /**
|
204 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
205 | */
|
||
206 | public void initialize() { |
||
207 | 14821 | jmvivo | registerIcons(); |
208 | 6599 | caballero | } |
209 | 14821 | jmvivo | |
210 | private void registerIcons(){ |
||
211 | 15640 | jmvivo | PluginServices.getIconTheme().registerDefault( |
212 | 14821 | jmvivo | "view-clear-selection",
|
213 | this.getClass().getClassLoader().getResource("images/delselection.png") |
||
214 | ); |
||
215 | } |
||
216 | 6599 | caballero | } |