root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ViewInvertSelection.java @ 38608
History | View | Annotate | Download (6.4 KB)
1 | 26435 | vcaballero | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib��ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | *
|
||
44 | * $Id: ViewSelectionControls.java 26282 2009-01-29 09:58:42Z vcaballero $
|
||
45 | * $Log$
|
||
46 | * Revision 1.16 2007-03-06 16:34:02 caballero
|
||
47 | * Exceptions
|
||
48 | *
|
||
49 | * Revision 1.15 2007/01/04 07:24:32 caballero
|
||
50 | * isModified
|
||
51 | *
|
||
52 | * Revision 1.14 2006/12/27 11:08:56 fdiaz
|
||
53 | * Arreglado el metodo hasVectorLayers para que no se pare en los grupos de capas cuando estos no tienen capas vectoriales.
|
||
54 | *
|
||
55 | * Revision 1.13 2006/09/25 16:54:12 caballero
|
||
56 | * invert selection
|
||
57 | *
|
||
58 | * Revision 1.12 2006/09/20 13:17:40 jaume
|
||
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | * Revision 1.11 2006/09/20 10:56:56 sbayarri
|
||
62 | * Refactorizaci�n clases View y ProjectView
|
||
63 | *
|
||
64 | * Revision 1.10 2006/09/15 10:40:03 caballero
|
||
65 | * extensibilidad de documentos
|
||
66 | *
|
||
67 | * Revision 1.9 2006/09/11 16:14:15 fjp
|
||
68 | * Invertir seleccion. Falta subirlo al branch de la 1.0
|
||
69 | *
|
||
70 | * Revision 1.8 2006/09/11 06:53:13 fjp
|
||
71 | * Antes del parto
|
||
72 | *
|
||
73 | * Revision 1.7 2006/09/04 16:26:54 fjp
|
||
74 | * Seleccionar por pol�gono
|
||
75 | *
|
||
76 | * Revision 1.6 2006/08/29 07:56:27 cesar
|
||
77 | * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
||
78 | *
|
||
79 | * Revision 1.5 2006/08/29 07:21:08 cesar
|
||
80 | * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
||
81 | *
|
||
82 | * Revision 1.4 2006/08/29 07:13:53 cesar
|
||
83 | * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
||
84 | *
|
||
85 | * Revision 1.3 2006/08/18 08:40:04 jmvivo
|
||
86 | * Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
|
||
87 | *
|
||
88 | * Revision 1.2 2006/07/27 06:20:28 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.1 2006/07/26 09:53:05 jaume
|
||
92 | * separadas las herramientas de selecci�n del viewControls al ViewSelectionControls
|
||
93 | *
|
||
94 | *
|
||
95 | */
|
||
96 | 29596 | jpiera | package org.gvsig.app.extension; |
97 | 26435 | vcaballero | |
98 | 38564 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
99 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
100 | import org.gvsig.andami.messages.NotificationManager; |
||
101 | import org.gvsig.andami.plugins.Extension; |
||
102 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
103 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.AbstractDocument; |
104 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
105 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
106 | 26435 | vcaballero | import org.gvsig.fmap.dal.DataStore; |
107 | import org.gvsig.fmap.dal.exception.DataException; |
||
108 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
109 | import org.gvsig.fmap.mapcontext.MapContext; |
||
110 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
111 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
112 | import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
||
113 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
114 | 28033 | cordinyana | import org.slf4j.Logger; |
115 | import org.slf4j.LoggerFactory; |
||
116 | 26435 | vcaballero | |
117 | |||
118 | /**
|
||
119 | * Extension that handles the selection tools, selection tools have sense on
|
||
120 | * vectorial layers only.
|
||
121 | *
|
||
122 | * @author Vicente Caballero Navarro
|
||
123 | *
|
||
124 | */
|
||
125 | public class ViewInvertSelection extends Extension { |
||
126 | 28033 | cordinyana | private static final Logger logger = LoggerFactory |
127 | .getLogger(ViewInvertSelection.class); |
||
128 | 31496 | jjdelcerro | private DefaultViewPanel vista;
|
129 | 38564 | jjdelcerro | |
130 | 26435 | vcaballero | public void initialize() { |
131 | 38564 | jjdelcerro | IconThemeHelper.registerIcon("action", "selection-reverse", this); |
132 | 26435 | vcaballero | } |
133 | |||
134 | 38564 | jjdelcerro | public void postInitialize() { |
135 | } |
||
136 | |||
137 | 26435 | vcaballero | public void execute(String actionCommand) { |
138 | 31496 | jjdelcerro | ViewDocument model = vista.getModel(); |
139 | 26435 | vcaballero | MapContext mapa = model.getMapContext(); |
140 | logger.debug("Comand : " + actionCommand);
|
||
141 | 38564 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-reverse-view")) { |
142 | 26435 | vcaballero | FLayer[] actives = mapa.getLayers().getActives();
|
143 | for (int i = 0; i < actives.length; i++) { |
||
144 | FLayer lyr = actives[i]; |
||
145 | if (lyr.isAvailable() && lyr instanceof SingleLayer) { |
||
146 | SingleLayer lyrSingle = (SingleLayer) lyr; |
||
147 | DataStore ds = lyrSingle.getDataStore(); |
||
148 | if (ds instanceof FeatureStore) { |
||
149 | try {
|
||
150 | ((FeatureStore) ds).getFeatureSelection().reverse(); |
||
151 | 31496 | jjdelcerro | ((AbstractDocument) vista.getModel())
|
152 | 26435 | vcaballero | .setModified(true);
|
153 | } catch (DataException e) {
|
||
154 | e.printStackTrace(); |
||
155 | NotificationManager.addError(e); |
||
156 | } |
||
157 | } else {
|
||
158 | // TODO Not supported yet
|
||
159 | } |
||
160 | |||
161 | |||
162 | } |
||
163 | } |
||
164 | 31496 | jjdelcerro | ((AbstractDocument)vista.getModel()).setModified(true); |
165 | 26435 | vcaballero | } |
166 | } |
||
167 | |||
168 | public boolean isEnabled() { |
||
169 | 31496 | jjdelcerro | ViewDocument model = vista.getModel(); |
170 | 26435 | vcaballero | MapContext mapa = model.getMapContext(); |
171 | |||
172 | for (int i = 0; i < mapa.getLayers().getActives().length; i++) { |
||
173 | FLayer lyr = mapa.getLayers().getActives()[i]; |
||
174 | if (lyr.isAvailable() && lyr instanceof FLyrVect){// && !lyr.isEditing()) { |
||
175 | return true; |
||
176 | } |
||
177 | } |
||
178 | return false; |
||
179 | } |
||
180 | |||
181 | public boolean isVisible() { |
||
182 | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
||
183 | |||
184 | 31496 | jjdelcerro | if (f != null && f instanceof DefaultViewPanel) { |
185 | vista = (DefaultViewPanel) f; |
||
186 | ViewDocument model = vista.getModel(); |
||
187 | 26435 | vcaballero | MapContext mapa = model.getMapContext(); |
188 | |||
189 | return hasVectorLayers(mapa.getLayers());
|
||
190 | |||
191 | } |
||
192 | return false; |
||
193 | } |
||
194 | |||
195 | private boolean hasVectorLayers(FLayers layers) { |
||
196 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
197 | FLayer lyr =layers.getLayer(i); |
||
198 | if (lyr instanceof FLayers){ |
||
199 | if (hasVectorLayers((FLayers) lyr)){
|
||
200 | return true; |
||
201 | } |
||
202 | } else if (lyr instanceof FLyrVect) { |
||
203 | return true; |
||
204 | } |
||
205 | } |
||
206 | return false; |
||
207 | } |
||
208 | } |