Revision 26435

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/gui/selectionByTheme/MySelectionByThemeListener.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.selectionByTheme;
42 42

  
43
import java.util.Iterator;
44

  
45
import org.cresques.cts.IProjection;
46
import org.gvsig.fmap.dal.exception.DataException;
47
import org.gvsig.fmap.dal.exception.ReadException;
48
import org.gvsig.fmap.dal.feature.Feature;
49
import org.gvsig.fmap.dal.feature.FeatureQuery;
50
import org.gvsig.fmap.dal.feature.FeatureSelection;
51
import org.gvsig.fmap.dal.feature.FeatureSet;
52
import org.gvsig.fmap.dal.feature.FeatureStore;
53
import org.gvsig.fmap.dal.feature.FeatureType;
54
import org.gvsig.fmap.geom.Geometry;
43 55
import org.gvsig.fmap.mapcontext.layers.FLayer;
56
import org.gvsig.fmap.mapcontext.layers.vectorial.ContainsGeometryEvaluator;
57
import org.gvsig.fmap.mapcontext.layers.vectorial.CrossesGeometryEvaluator;
58
import org.gvsig.fmap.mapcontext.layers.vectorial.DisjointGeometryEvaluator;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.EqualsGeometryEvaluator;
44 60
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
61
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsGeometryEvaluator;
62
import org.gvsig.fmap.mapcontext.layers.vectorial.OverlapsGeometryEvaluator;
63
import org.gvsig.fmap.mapcontext.layers.vectorial.TouchesGeometryEvaluator;
64
import org.gvsig.fmap.mapcontext.layers.vectorial.WithinGeometryEvaluator;
65
import org.gvsig.tools.evaluator.Evaluator;
66
import org.gvsig.tools.evaluator.EvaluatorData;
67
import org.gvsig.tools.evaluator.EvaluatorException;
68
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
69
import org.opengis.filter.spatial.Contains;
45 70

  
71
import com.iver.andami.messages.NotificationManager;
72

  
46 73
/**
47 74
 * DOCUMENT ME!
48 75
 *
......
56 83
	 */
57 84
	public void newSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
58 85
		long t1 = System.currentTimeMillis();
86

  
59 87
		if (selectionLayer instanceof FLyrVect) {
60
//			try {
61
//				FeatureStore fs = ((FLyrVect) selectionLayer).getFeatureStore();
62
//				for (int i = 0; i < toSelect.length; i++) {
63
//					if (toSelect[i] instanceof FLyrVect) {
64
//						FeatureStore capa = ((FLyrVect) toSelect[i]).getFeatureStore();
65
//						QueryByThemeVisitor visitor = new QueryByThemeVisitor(
66
//								toSelect[i], selectionLayer, action);
67
//						capa.clearSelection();
68
//
69
//						((VectorialData) selectionLayer).process(visitor,
70
//								fs.getSelection());
71
//						capa.setSelection(visitor.getBitset());
72
//					}
73
//				}
74
//			} catch (ProcessVisitorException e) {
75
//				NotificationManager.addError("Error leyendo las capas", e);
76
//			} catch (ReadDriverException e) {
77
//				NotificationManager.addError("Error leyendo las capas", e);
78
//			} catch (VisitorException e) {
79
//				NotificationManager.addError("Error leyendo las capas", e);
80
//			}
88
			try {
89
				FeatureSelection selection=(FeatureSelection)((FLyrVect)selectionLayer).getFeatureStore().getSelection();
90
				SelectByTheme filter=new SelectByTheme(selection,selectionLayer.getMapContext().getProjection(),selection.getDefaultFeatureType().getDefaultGeometryAttributeName(), action);
81 91

  
92
				for (int i = 0; i < toSelect.length; i++) {
93
					if (toSelect[i] instanceof FLyrVect) {
94
//						if (!selectionLayer.getFullEnvelope().intersects(toSelect[i].getFullEnvelope())){
95
//							continue;
96
//						}
97
						FeatureStore featureToQuery = ((FLyrVect) toSelect[i]).getFeatureStore();
98
						FeatureQuery fQuery=new FeatureQuery();
99
						filter.setData(featureToQuery.getDefaultFeatureType(),featureToQuery.getDefaultFeatureType().getDefaultGeometryAttributeName(),null);
100

  
101
						fQuery.setFilter(filter);
102
						FeatureSet featureSet=featureToQuery.getFeatureSet(fQuery);
103
						((FeatureSelection)featureToQuery.getSelection()).deselectAll();
104
						featureToQuery.setSelection(featureSet);
105
//						((FeatureSelection)featureToQuery.getSelection()).deselectAll();
106
//						((FeatureSelection)featureToQuery.getSelection()).select(featureSet);
107
					}
108
				}
109
			} catch (ReadException e) {
110
				NotificationManager.addError("error_selection_by_theme", e);
111
			} catch (DataException e) {
112
				NotificationManager.addError("error_selection_by_theme", e);
113
			}
114

  
82 115
		}
83 116
		long t2 = System.currentTimeMillis();
84 117
		System.out
......
91 124
	 *      int, int)
92 125
	 */
93 126
	public void addToSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
127
		long t1 = System.currentTimeMillis();
128

  
94 129
		if (selectionLayer instanceof FLyrVect) {
95
//			try {
96
//				FeatureStore fs = ((FLyrVect) selectionLayer).getFeatureStore();
97
//				for (int i = 0; i < toSelect.length; i++) {
98
//					if (toSelect[i] instanceof FLyrVect) {
99
//						FeatureStore capa = ((FLyrVect) toSelect[i]).getFeatureStore();
100
//						QueryByThemeVisitor visitor = new QueryByThemeVisitor(
101
//								toSelect[i], selectionLayer, action);
102
//						FBitSet selection = capa.getSelection();
103
//						((VectorialData) selectionLayer).process(visitor,
104
//								selected.getSelection());
105
//						selection.or(visitor.getBitset());
106
//						capa.setSelection(selection);
107
//					}
108
//				}
109
//			} catch (ReadDriverException e) {
110
//				NotificationManager.addError("Error leyendo las capas", e);
111
//			} catch (ProcessVisitorException e) {
112
//				NotificationManager.addError("Error leyendo las capas", e);
113
//			} catch (VisitorException e) {
114
//				NotificationManager.addError("Error leyendo las capas", e);
115
//			}
130
			try {
131
				FeatureSelection selection=(FeatureSelection)((FLyrVect)selectionLayer).getFeatureStore().getSelection();
132
				SelectByTheme filter=new SelectByTheme(selection,selectionLayer.getMapContext().getProjection(),selection.getDefaultFeatureType().getDefaultGeometryAttributeName(), action);
133

  
134
				for (int i = 0; i < toSelect.length; i++) {
135
					if (toSelect[i] instanceof FLyrVect) {
136
						if (!selectionLayer.getFullEnvelope().intersects(toSelect[i].getFullEnvelope())){
137
							continue;
138
						}
139
						FeatureStore featureToQuery = ((FLyrVect) toSelect[i]).getFeatureStore();
140
						FeatureQuery fQuery=new FeatureQuery();
141
						filter.setData(featureToQuery.getDefaultFeatureType(),featureToQuery.getDefaultFeatureType().getDefaultGeometryAttributeName(),null);
142

  
143
						fQuery.setFilter(filter);
144
						FeatureSet featureSet=featureToQuery.getFeatureSet(fQuery);
145
						featureToQuery.setSelection(featureSet);
146
					}
147
				}
148
			} catch (ReadException e) {
149
				NotificationManager.addError("error_selection_by_theme", e);
150
			} catch (DataException e) {
151
				NotificationManager.addError("error_selection_by_theme", e);
152
			}
153

  
116 154
		}
155
		long t2 = System.currentTimeMillis();
156
		System.out
157
				.println("Tiempo de consulta: " + (t2 - t1) + " milisegundos");
117 158
	}
118 159

  
119 160
	/**
......
121 162
	 *      int, int)
122 163
	 */
123 164
	public void fromSet(FLayer[] toSelect, FLayer selectionLayer, int action) {
165
		long t1 = System.currentTimeMillis();
124 166
		if (selectionLayer instanceof FLyrVect) {
125
//			try {
126
//				FeatureStore selected = ((FLyrVect) selectionLayer).getFeatureStore();
127
//				for (int i = 0; i < toSelect.length; i++) {
128
//					if (toSelect[i] instanceof FLyrVect) {
129
//						Selectable capa = ((FLyrVect) toSelect[i]).getFeatureStore();
130
//
131
//						QueryByThemeVisitor visitor = new QueryByThemeVisitor(
132
//								toSelect[i], selectionLayer, action);
133
//						FBitSet selection = capa.getSelection();
134
//						((VectorialData) selectionLayer).process(visitor,
135
//								selected.getSelection());
136
//						selection.and(visitor.getBitset());
137
//						capa.setSelection(selection);
138
//					}
139
//				}
140
//			} catch (ReadDriverException e) {
141
//				NotificationManager.addError("Error leyendo las capas", e);
142
//			} catch (ProcessVisitorException e) {
143
//				NotificationManager.addError("Error leyendo las capas", e);
144
//			} catch (VisitorException e) {
145
//				NotificationManager.addError("Error leyendo las capas", e);
146
//			}
167
			try {
168
				FeatureSelection selection=(FeatureSelection)((FLyrVect)selectionLayer).getFeatureStore().getSelection();
169
				SelectByTheme filter=new SelectByTheme(selection,selectionLayer.getMapContext().getProjection(),selection.getDefaultFeatureType().getDefaultGeometryAttributeName(), action);
147 170

  
171
				for (int i = 0; i < toSelect.length; i++) {
172
					if (toSelect[i] instanceof FLyrVect) {
173
						if (!selectionLayer.getFullEnvelope().intersects(toSelect[i].getFullEnvelope())){
174
							continue;
175
						}
176
						FeatureStore featureToQuery = ((FLyrVect) toSelect[i]).getFeatureStore();
177
						FeatureQuery fQuery=new FeatureQuery();
178
						filter.setData(featureToQuery.getDefaultFeatureType(),featureToQuery.getDefaultFeatureType().getDefaultGeometryAttributeName(),(FeatureSelection)featureToQuery.getSelection());
179

  
180
						fQuery.setFilter(filter);
181
						FeatureSet featureSet=featureToQuery.getFeatureSet(fQuery);
182
						((FeatureSelection)featureToQuery.getSelection()).deselectAll();
183
						featureToQuery.setSelection(featureSet);
184
					}
185
				}
186
			} catch (ReadException e) {
187
				NotificationManager.addError("error_selection_by_theme", e);
188
			} catch (DataException e) {
189
				NotificationManager.addError("error_selection_by_theme", e);
190
			}
191

  
148 192
		}
193
		long t2 = System.currentTimeMillis();
194
		System.out
195
				.println("Tiempo de consulta: " + (t2 - t1) + " milisegundos");
149 196
	}
197
	class SelectByTheme implements Evaluator{
198
		private FeatureSelection selection=null;
199
		private IProjection projection;
200
		private FeatureType featureType;
201
		private String geomName;
202
		private EvaluatorFieldsInfo info;
203
		private String nameSelectedGeom;
204
		private FeatureSelection featureSelection;
205
		private int action;
206
		private int index;
207
		private Iterator<Feature> features=null;
208

  
209
		public SelectByTheme(FeatureSelection selection, IProjection projection,String nameSelectedGeom, int action){
210
			this.selection=selection;
211

  
212
			this.projection=projection;
213
			this.nameSelectedGeom=nameSelectedGeom;
214
			this.action=action;
215
			this.index=selection.getDefaultFeatureType().getIndex(nameSelectedGeom);
216
		}
217
		public void setData(FeatureType featureType, String geomName, FeatureSelection featureSelection){
218
			this.featureType=featureType;
219
			this.geomName=geomName;
220
			this.featureSelection=featureSelection;
221
			this.info=new EvaluatorFieldsInfo();
222
			this.info.addFieldValue(geomName);
223
		}
224

  
225
		public Object evaluate(EvaluatorData data) throws EvaluatorException {
226
			if (featureSelection!=null && !featureSelection.isSelected(((Feature)data.getContextValue("feature")))){
227
				return new Boolean(false);
228
			}
229
			try {
230
				features = selection.iterator();
231
			} catch (DataException e) {
232
				NotificationManager.addError("error_selection_by_theme", e);
233
			}
234

  
235
			while (features.hasNext()) {
236
				Feature feature = (Feature) features.next();
237
				Geometry geometry=feature.getGeometry(index);
238
				Evaluator eval=null;
239
				switch (action) {
240
				case SelectionByTheme.INTERSECTS:
241
					eval=new IntersectsGeometryEvaluator(geometry, projection, featureType, geomName);
242
					break;
243
				case SelectionByTheme.CONTAINS:
244
					eval=new ContainsGeometryEvaluator(geometry, projection, featureType, geomName);
245
					break;
246
				case SelectionByTheme.CROSSES:
247
					eval=new CrossesGeometryEvaluator(geometry, projection, featureType, geomName);
248
					break;
249
				case SelectionByTheme.DISJOINT:
250
					eval=new DisjointGeometryEvaluator(geometry, projection, featureType, geomName);
251
					break;
252
				case SelectionByTheme.EQUALS:
253
					eval=new EqualsGeometryEvaluator(geometry, projection, featureType, geomName);
254
					break;
255
				case SelectionByTheme.OVERLAPS:
256
					eval=new OverlapsGeometryEvaluator(geometry, projection, featureType, geomName);
257
					break;
258
				case SelectionByTheme.TOUCHES:
259
					eval=new TouchesGeometryEvaluator(geometry, projection, featureType, geomName);
260
					break;
261
				case SelectionByTheme.WITHIN:
262
					eval=new WithinGeometryEvaluator(geometry, projection, featureType, geomName);
263
					break;
264

  
265
				default:
266
					eval=new IntersectsGeometryEvaluator(geometry, projection, featureType, geomName);
267
					break;
268
				}
269

  
270
				Boolean evaluate=(Boolean)eval.evaluate(data);
271
				if(((Boolean)evaluate).booleanValue()){
272
					return evaluate;
273
				}
274
			}
275
			return new Boolean(false);
276
		}
277

  
278
		public String getName() {
279
			return "select by theme";
280
		}
281
		public String getCQL() {
282
			// TODO Auto-generated method stub
283
			return null;
284
		}
285
		public String getDescription() {
286
			return getName();
287
		}
288
		public EvaluatorFieldsInfo getFieldsInfo() {
289
			return info;
290
		}
291
	}
150 292
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/ViewSelectionControls.java
96 96
package com.iver.cit.gvsig;
97 97

  
98 98
import org.apache.log4j.Logger;
99
import org.gvsig.fmap.dal.DataStore;
100
import org.gvsig.fmap.dal.exception.DataException;
101
import org.gvsig.fmap.dal.feature.FeatureStore;
102 99
import org.gvsig.fmap.mapcontext.MapContext;
103 100
import org.gvsig.fmap.mapcontext.layers.FLayer;
104 101
import org.gvsig.fmap.mapcontext.layers.FLayers;
105
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
106 102
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
107 103
import org.gvsig.fmap.mapcontrol.MapControl;
108 104

  
109 105
import com.iver.andami.PluginServices;
110
import com.iver.andami.messages.NotificationManager;
111 106
import com.iver.andami.plugins.Extension;
112 107
import com.iver.andami.ui.mdiManager.IWindow;
113
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel;
114
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener;
115
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme;
116 108
import com.iver.cit.gvsig.project.documents.ProjectDocument;
117 109
import com.iver.cit.gvsig.project.documents.view.IProjectView;
118 110
import com.iver.cit.gvsig.project.documents.view.gui.View;
......
157 149
	}
158 150

  
159 151
	public void execute(String actionCommand) {
160
		IProjectView model = vista.getModel();
161
		MapContext mapa = model.getMapContext();
162 152
		MapControl mapCtrl = vista.getMapControl();
163 153
		logger.debug("Comand : " + actionCommand);
164 154
		if (actionCommand.equals("SELRECT")) {
......
170 160
		} else if (actionCommand.equals("SELPOL")) {
171 161
			mapCtrl.setTool("polSelection");
172 162
			((ProjectDocument)vista.getModel()).setModified(true);
173
		} else if (actionCommand.equals("SELECTIONBYSHAPE")) {
174
			SelectionByTheme dlg = new SelectionByTheme();
175
			// FLayer[] layers = mapa.getLayers().getActives();
176
			// int count = 0;
177
			dlg.setModel(new DefaultSelectionByThemeModel());
178
			dlg.addSelectionListener(new MySelectionByThemeListener());
179
			PluginServices.getMDIManager().addWindow(dlg);
180
			((ProjectDocument)vista.getModel()).setModified(true);
181
		} else if (actionCommand.equals("INVERT_SELECTION")) {
182
			FLayer[] actives = mapa.getLayers().getActives();
183
			for (int i = 0; i < actives.length; i++) {
184
				FLayer lyr = actives[i];
185
				if (lyr.isAvailable() && lyr instanceof SingleLayer) {
186
					SingleLayer lyrSingle = (SingleLayer) lyr;
187
					DataStore ds = lyrSingle.getDataStore();
188
					if (ds instanceof FeatureStore) {
189
						try {
190
							((FeatureStore) ds).getFeatureSelection().reverse();
191
							((ProjectDocument) vista.getModel())
192
									.setModified(true);
193
						} catch (DataException e) {
194
							e.printStackTrace();
195
							NotificationManager.addError(e);
196
						}
197
					} else {
198
						// TODO Not supported yet
199
					}
200

  
201

  
202
				}
203
			}
204
			((ProjectDocument)vista.getModel()).setModified(true);
205 163
		}
206 164
	}
207 165

  
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/ViewSelectionByTheme.java
1
/* 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
package com.iver.cit.gvsig;
97

  
98
import org.apache.log4j.Logger;
99
import org.gvsig.fmap.mapcontext.MapContext;
100
import org.gvsig.fmap.mapcontext.layers.FLayer;
101
import org.gvsig.fmap.mapcontext.layers.FLayers;
102
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
103

  
104
import com.iver.andami.PluginServices;
105
import com.iver.andami.plugins.Extension;
106
import com.iver.andami.ui.mdiManager.IWindow;
107
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel;
108
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener;
109
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme;
110
import com.iver.cit.gvsig.project.documents.ProjectDocument;
111
import com.iver.cit.gvsig.project.documents.view.IProjectView;
112
import com.iver.cit.gvsig.project.documents.view.gui.View;
113

  
114
/**
115
 * Extension that handles the selection tools, selection tools have sense on
116
 * vectorial layers only.
117
 *
118
 * @author Vicente Caballero Navarro
119
 *
120
 */
121
public class ViewSelectionByTheme extends Extension {
122
	private static Logger logger = Logger.getLogger(ViewControls.class
123
			.getName());
124
	private View vista;
125
	public void initialize() {
126
	}
127

  
128
	public void execute(String actionCommand) {
129
		logger.debug("Comand : " + actionCommand);
130
		if (actionCommand.equals("SELECTIONBYSHAPE")) {
131
			SelectionByTheme dlg = new SelectionByTheme();
132
			dlg.setModel(new DefaultSelectionByThemeModel());
133
			dlg.addSelectionListener(new MySelectionByThemeListener());
134
			PluginServices.getMDIManager().addWindow(dlg);
135
			((ProjectDocument)vista.getModel()).setModified(true);
136
		}
137
	}
138

  
139
	public boolean isEnabled() {
140
		IProjectView model = vista.getModel();
141
		MapContext mapa = model.getMapContext();
142

  
143
		for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
144
			FLayer lyr = mapa.getLayers().getActives()[i];
145
			if (lyr.isAvailable() && lyr instanceof FLyrVect){// && !lyr.isEditing()) {
146
				return true;
147
			}
148
		}
149
		return false;
150
	}
151

  
152
	public boolean isVisible() {
153
		IWindow f = PluginServices.getMDIManager().getActiveWindow();
154

  
155
		if (f != null && f instanceof View) {
156
			vista = (View) f;
157
			IProjectView model = vista.getModel();
158
			MapContext mapa = model.getMapContext();
159

  
160
			return hasVectorLayers(mapa.getLayers());
161

  
162
		}
163
		return false;
164
	}
165

  
166
	private boolean hasVectorLayers(FLayers layers) {
167
		for (int i = 0; i < layers.getLayersCount(); i++) {
168
			FLayer lyr =layers.getLayer(i);
169
			if (lyr instanceof FLayers){
170
				if (hasVectorLayers((FLayers) lyr)){
171
					return true;
172
				}
173
			} else if (lyr instanceof FLyrVect) {
174
				return true;
175
			}
176
		}
177
		return false;
178
	}
179
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/ViewInvertSelection.java
1
/* 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
package com.iver.cit.gvsig;
97

  
98
import org.apache.log4j.Logger;
99
import org.gvsig.fmap.dal.DataStore;
100
import org.gvsig.fmap.dal.exception.DataException;
101
import org.gvsig.fmap.dal.feature.FeatureStore;
102
import org.gvsig.fmap.mapcontext.MapContext;
103
import org.gvsig.fmap.mapcontext.layers.FLayer;
104
import org.gvsig.fmap.mapcontext.layers.FLayers;
105
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
106
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
107

  
108
import com.iver.andami.PluginServices;
109
import com.iver.andami.messages.NotificationManager;
110
import com.iver.andami.plugins.Extension;
111
import com.iver.andami.ui.mdiManager.IWindow;
112
import com.iver.cit.gvsig.project.documents.ProjectDocument;
113
import com.iver.cit.gvsig.project.documents.view.IProjectView;
114
import com.iver.cit.gvsig.project.documents.view.gui.View;
115

  
116
/**
117
 * Extension that handles the selection tools, selection tools have sense on
118
 * vectorial layers only.
119
 *
120
 * @author Vicente Caballero Navarro
121
 *
122
 */
123
public class ViewInvertSelection extends Extension {
124
	private static Logger logger = Logger.getLogger(ViewControls.class
125
			.getName());
126
	private View vista;
127
	public void initialize() {
128
	}
129

  
130
	public void execute(String actionCommand) {
131
		IProjectView model = vista.getModel();
132
		MapContext mapa = model.getMapContext();
133
		logger.debug("Comand : " + actionCommand);
134
		if (actionCommand.equals("INVERT_SELECTION")) {
135
			FLayer[] actives = mapa.getLayers().getActives();
136
			for (int i = 0; i < actives.length; i++) {
137
				FLayer lyr = actives[i];
138
				if (lyr.isAvailable() && lyr instanceof SingleLayer) {
139
					SingleLayer lyrSingle = (SingleLayer) lyr;
140
					DataStore ds = lyrSingle.getDataStore();
141
					if (ds instanceof FeatureStore) {
142
						try {
143
							((FeatureStore) ds).getFeatureSelection().reverse();
144
							((ProjectDocument) vista.getModel())
145
									.setModified(true);
146
						} catch (DataException e) {
147
							e.printStackTrace();
148
							NotificationManager.addError(e);
149
						}
150
					} else {
151
						// TODO Not supported yet
152
					}
153

  
154

  
155
				}
156
			}
157
			((ProjectDocument)vista.getModel()).setModified(true);
158
		}
159
	}
160

  
161
	public boolean isEnabled() {
162
		IProjectView model = vista.getModel();
163
		MapContext mapa = model.getMapContext();
164

  
165
		for (int i = 0; i < mapa.getLayers().getActives().length; i++) {
166
			FLayer lyr = mapa.getLayers().getActives()[i];
167
			if (lyr.isAvailable() && lyr instanceof FLyrVect){// && !lyr.isEditing()) {
168
				return true;
169
			}
170
		}
171
		return false;
172
	}
173

  
174
	public boolean isVisible() {
175
		IWindow f = PluginServices.getMDIManager().getActiveWindow();
176

  
177
		if (f != null && f instanceof View) {
178
			vista = (View) f;
179
			IProjectView model = vista.getModel();
180
			MapContext mapa = model.getMapContext();
181

  
182
			return hasVectorLayers(mapa.getLayers());
183

  
184
		}
185
		return false;
186
	}
187

  
188
	private boolean hasVectorLayers(FLayers layers) {
189
		for (int i = 0; i < layers.getLayersCount(); i++) {
190
			FLayer lyr =layers.getLayer(i);
191
			if (lyr instanceof FLayers){
192
				if (hasVectorLayers((FLayers) lyr)){
193
					return true;
194
				}
195
			} else if (lyr instanceof FLyrVect) {
196
				return true;
197
			}
198
		}
199
		return false;
200
	}
201
}
branches/v2_0_0_prep/applications/appgvSIG/config/config.xml
175 175
			<menu text="Vista/seleccion/seleccionar_por_punto" action-command="SELPOINT" icon="view-select-geometry"/>
176 176
			<menu text="Vista/seleccion/seleccionar_por_rectangulo" action-command="SELRECT" icon="view-select-by-rectangle"/>
177 177
			<menu text="Vista/seleccion/seleccionar_por_poligono" action-command="SELPOL" icon="view-select-by-polygon"/>
178
			<menu text="Vista/seleccion/Seleccion_por_capa" action-command="SELECTIONBYSHAPE"/>
179 178
			<menu text="Vista/seleccion/separator" action-command="separator" is_separator="true"/>
180
			<menu text="Vista/seleccion/invert_selection" action-command="INVERT_SELECTION" icon="view-select-invert"/>
181 179
			<tool-bar name="Tools_Select" position="6">
182 180
				<selectable-tool icon="view-select-geometry" action-command="SELPOINT"  tooltip="seleccionar_por_punto" position="1"/>
183 181
				<selectable-tool icon="view-select-by-rectangle" action-command="SELRECT"  tooltip="seleccionar_por_rectangulo" position="2"/>
184 182
				<selectable-tool icon="view-select-by-polygon" action-command="SELPOL"  tooltip="seleccionar_por_poligono" position="3"/>
185
				<action-tool icon="view-select-invert" action-command="INVERT_SELECTION"  tooltip="invert_selection" position="4"/>
186 183
			</tool-bar>
187 184
		</extension>
188

  
185
		<extension class-name="com.iver.cit.gvsig.ViewSelectionByTheme"
186
            description="Extensi?n encargada de la selecci?n por tema."
187
            active="true"
188
            priority="30">
189
            <menu text="Vista/seleccion/Seleccion_por_capa" action-command="SELECTIONBYSHAPE"/>
190
        </extension>
191
        <extension class-name="com.iver.cit.gvsig.ViewInvertSelection"
192
            description="Extensi?n encargada de hacer la selecci?n inversa."
193
            active="true"
194
            priority="30">
195
            <menu text="Vista/seleccion/separator" action-command="separator" is_separator="true"/>
196
            <menu text="Vista/seleccion/invert_selection" action-command="INVERT_SELECTION" icon="view-select-invert"/>
197
            <tool-bar name="Tools_Select" position="6">
198
                <action-tool icon="view-select-invert" action-command="INVERT_SELECTION"  tooltip="invert_selection" position="4"/>
199
            </tool-bar>
200
        </extension>
189 201
		<extension class-name="com.iver.cit.gvsig.ViewPropertiesExtension"
190 202
			description="Extensi?n encargada de gestionar el di?logo de propiedades de la vista."
191 203
			active="true">

Also available in: Unified diff