Revision 16 org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.swing/org.gvsig.lrs.swing.impl/src/main/java/org/gvsig/lrs/swing/impl/JLrsShowMeasuresParamsController.java
JLrsShowMeasuresParamsController.java | ||
---|---|---|
139 | 139 |
throw new LrsNeededParameterException("at_least_one_layer_needed", null); |
140 | 140 |
} |
141 | 141 |
|
142 |
if (!correctLayerFound(layer)){
|
|
142 |
if (!JLrsUtilsController.hasMLayersWithSelectedFeatures(layer)){
|
|
143 | 143 |
logger.error("Impossible to find the layer needed"); |
144 | 144 |
throw new LrsNeededParameterException("impossible_to_find_needed_layer",null); |
145 | 145 |
} |
... | ... | |
235 | 235 |
|
236 | 236 |
} |
237 | 237 |
|
238 |
//TODO Extract validations to a common class |
|
239 |
/** |
|
240 |
* Tries to find one curve M-layer with selected Features |
|
241 |
* |
|
242 |
* @param FLayer |
|
243 |
* @return |
|
244 |
* @throws ReadException |
|
245 |
*/ |
|
246 |
private static boolean correctLayerFound(FLayer layer) { |
|
247 |
// Validates is FLyrVect |
|
248 |
FLyrVect lyrVect = null; |
|
249 |
if (layer instanceof FLyrVect) { |
|
250 |
lyrVect = (FLyrVect) layer; |
|
251 |
} else |
|
252 |
return false; |
|
253 | 238 |
|
254 |
try { |
|
255 |
if (lyrVect != null && (lyrVect.getGeometryType() |
|
256 |
.isTypeOf(Geometry.TYPES.CURVE) |
|
257 |
|| lyrVect.getGeometryType().isTypeOf(Geometry.TYPES.MULTICURVE))) { |
|
258 |
//TODO M-geometry commented to test button |
|
259 |
// if (lyrVect.getGeometryType() |
|
260 |
// .isSubTypeOf(Geometry.SUBTYPES.GEOM2DM) || |
|
261 |
// lyrVect.getGeometryType() |
|
262 |
// .isSubTypeOf(Geometry.SUBTYPES.GEOM3DM)) { |
|
263 | 239 |
|
264 |
//At least a feature must be selected |
|
265 |
return hasSelectedFeatures(lyrVect); |
|
266 |
|
|
267 |
//} |
|
268 |
} |
|
269 |
} catch (Exception e) { |
|
270 |
logger.error("Can't get linear vector layers", e); |
|
271 |
} |
|
272 |
return false; |
|
273 |
} |
|
274 |
|
|
275 |
private static boolean hasSelectedFeatures(FLyrVect layer) { |
|
276 |
FeatureStore featureStore=layer.getFeatureStore(); |
|
277 |
if(featureStore!=null){ |
|
278 |
try { |
|
279 |
FeatureSelection selectedFeatures= featureStore.getFeatureSelection(); |
|
280 |
if ((selectedFeatures.getSize() >0)) { |
|
281 |
return true; |
|
282 |
} |
|
283 |
} catch (DataException e) { |
|
284 |
logger.warn("Can't get selected feature", e); |
|
285 |
} |
|
286 |
} |
|
287 |
return false; |
|
288 |
} |
|
289 |
|
|
290 | 240 |
} |
Also available in: Unified diff