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