svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ClearSelectionExtension.java @ 6828
History | View | Annotate | Download (5.29 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 | import com.iver.andami.PluginServices; |
||
50 | import com.iver.andami.plugins.Extension; |
||
51 | import com.iver.cit.gvsig.fmap.DriverException; |
||
52 | import com.iver.cit.gvsig.fmap.FMap; |
||
53 | import com.iver.cit.gvsig.fmap.MapControl; |
||
54 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
55 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
56 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
57 | import com.iver.cit.gvsig.gui.Table; |
||
58 | import com.iver.cit.gvsig.gui.View; |
||
59 | import com.iver.cit.gvsig.project.ProjectTable; |
||
60 | import com.iver.cit.gvsig.project.ProjectView; |
||
61 | |||
62 | |||
63 | /**
|
||
64 | * Extensi?n encargada de limpiar la selecci?n.
|
||
65 | *
|
||
66 | * @author Vicente Caballero Navarro
|
||
67 | */
|
||
68 | public class ClearSelectionExtension extends Extension { |
||
69 | /**
|
||
70 | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
||
71 | */
|
||
72 | public void execute(String s) { |
||
73 | if (s.compareTo("DEL_SELECTION") == 0) { |
||
74 | boolean refresh = false; |
||
75 | com.iver.andami.ui.mdiManager.View view =PluginServices.getMDIManager().getActiveView(); |
||
76 | |||
77 | if (view instanceof View){ |
||
78 | View vista = (View) view; |
||
79 | ProjectView model = vista.getModel(); |
||
80 | FMap mapa = model.getMapContext(); |
||
81 | MapControl mapCtrl = vista.getMapControl(); |
||
82 | for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
||
83 | /* JMV: Esto deberia de ser asi (Las capas son 'Selectable' o no)
|
||
84 | * pero de momento lo cambiamos para que use una capa vectorial
|
||
85 | *
|
||
86 | |||
87 | if (map.getLayers().getLayer(i) instanceof Selectable) {
|
||
88 | if (mapa.getLayers().getLayer(i).isActive()) {
|
||
89 | Selectable selectable = (Selectable) mapa.getLayers().getLayer(i);
|
||
90 | |||
91 | if (selectable.getSelection().cardinality() != 0) {
|
||
92 | refresh = true;
|
||
93 | }
|
||
94 | selectable.clearSelection();
|
||
95 | }
|
||
96 | }
|
||
97 | |||
98 | */
|
||
99 | if (mapa.getLayers().getLayer(i) instanceof FLyrVect) { |
||
100 | if (mapa.getLayers().getLayer(i).isActive()) {
|
||
101 | |||
102 | try {
|
||
103 | SelectableDataSource dataSource; |
||
104 | |||
105 | dataSource = ((FLyrVect)mapa.getLayers().getLayer(i)).getRecordset(); |
||
106 | if (dataSource.getSelection().cardinality() != 0) { |
||
107 | refresh = true;
|
||
108 | } |
||
109 | dataSource.clearSelection(); |
||
110 | } catch (DriverException e) {
|
||
111 | e.printStackTrace(); |
||
112 | } |
||
113 | |||
114 | } |
||
115 | } |
||
116 | } |
||
117 | |||
118 | if (refresh) {
|
||
119 | mapCtrl.drawMap(false);
|
||
120 | } |
||
121 | }else if (view instanceof Table){ |
||
122 | Table table = (Table) view; |
||
123 | ProjectTable model = table.getModel(); |
||
124 | SelectableDataSource dataSource; |
||
125 | dataSource = model.getModelo().getRecordset(); |
||
126 | if (dataSource.getSelection().cardinality() != 0) { |
||
127 | refresh = true;
|
||
128 | } |
||
129 | dataSource.clearSelection(); |
||
130 | if (refresh) {
|
||
131 | table.refresh(); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | |||
137 | /**
|
||
138 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
139 | */
|
||
140 | public boolean isVisible() { |
||
141 | com.iver.andami.ui.mdiManager.View view = PluginServices.getMDIManager().getActiveView(); |
||
142 | |||
143 | if (view == null) { |
||
144 | return false; |
||
145 | } |
||
146 | if (view instanceof View) { |
||
147 | FMap mapa = ((View) view).getModel().getMapContext();
|
||
148 | return mapa.getLayers().getLayersCount() > 0; |
||
149 | } |
||
150 | if (view instanceof Table) { |
||
151 | return true; |
||
152 | } |
||
153 | |||
154 | return false; |
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
159 | */
|
||
160 | public boolean isEnabled() { |
||
161 | com.iver.andami.ui.mdiManager.View view = PluginServices.getMDIManager().getActiveView(); |
||
162 | if (view == null) { |
||
163 | return false; |
||
164 | } |
||
165 | if (view instanceof View){ |
||
166 | FLayer[] selected = ((View)view).getModel().getMapContext().getLayers().getActives(); |
||
167 | if (selected.length == 1 && selected[0] instanceof FLyrVect){ |
||
168 | 6778 | jmvivo | if (!selected[0].isAvailable()) return false; |
169 | 6599 | caballero | try {
|
170 | 6772 | fjp | SelectableDataSource rs = ((FLyrVect)selected[0]).getRecordset();
|
171 | if (rs != null) |
||
172 | return (rs.getSelection().cardinality()>0); |
||
173 | 6599 | caballero | } catch (DriverException e) {
|
174 | e.printStackTrace(); |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | if (view instanceof Table){ |
||
179 | return ((Table)view).getSelectedRowIndices().length>0; |
||
180 | } |
||
181 | return false; |
||
182 | } |
||
183 | |||
184 | /**
|
||
185 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
186 | */
|
||
187 | public void initialize() { |
||
188 | } |
||
189 | } |