Revision 44599
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/FLayers.java | ||
---|---|---|
45 | 45 |
import org.gvsig.fmap.dal.DataStore; |
46 | 46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 | 47 |
import org.gvsig.fmap.dal.exception.ReadException; |
48 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
49 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
48 | 50 |
import org.gvsig.fmap.geom.primitive.Envelope; |
49 | 51 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 | 52 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
... | ... | |
107 | 109 |
* Useful for debug the problems during the implementation. |
108 | 110 |
*/ |
109 | 111 |
private static final Logger LOGGER = LoggerFactory.getLogger(FLayers.class); |
112 |
|
|
113 |
public static final Predicate<FLayer> LAYER_ACTIVE = new Predicate<FLayer>() { |
|
114 |
@Override |
|
115 |
public boolean test(FLayer layer) { |
|
116 |
return layer.isActive(); |
|
117 |
} |
|
118 |
}; |
|
110 | 119 |
|
120 |
public static final Predicate<FLayer> LAYER_AVALAIBLE = new Predicate<FLayer>() { |
|
121 |
@Override |
|
122 |
public boolean test(FLayer layer) { |
|
123 |
return layer.isAvailable(); |
|
124 |
} |
|
125 |
}; |
|
126 |
|
|
127 |
public static Predicate<FLayer> LAYER_FLYRVECT = new Predicate<FLayer>() { |
|
128 |
@Override |
|
129 |
public boolean test(FLayer layer) { |
|
130 |
return layer instanceof FLyrVect; |
|
131 |
} |
|
132 |
}; |
|
133 |
public static Predicate<FLayer> LAYER_SELECTION_AVAILABLE = new Predicate<FLayer>() { |
|
134 |
@Override |
|
135 |
public boolean test(FLayer layer) { |
|
136 |
if (layer instanceof FLyrVect) { |
|
137 |
try { |
|
138 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
|
139 |
if (store.getFeatureSelection().isAvailable()) { |
|
140 |
return true; |
|
141 |
} |
|
142 |
} catch (Exception ex) { |
|
143 |
return false; |
|
144 |
} |
|
145 |
} |
|
146 |
return false; |
|
147 |
} |
|
148 |
}; |
|
149 |
|
|
150 |
public static Predicate<FLayer> LAYER_SELECTION_EMPTY = new Predicate<FLayer>() { |
|
151 |
@Override |
|
152 |
public boolean test(FLayer layer) { |
|
153 |
if (layer instanceof FLyrVect) { |
|
154 |
try { |
|
155 |
FeatureStore store = ((FLyrVect) layer).getFeatureStore(); |
|
156 |
FeatureSelection selection = store.getFeatureSelection(); |
|
157 |
if (!selection.isAvailable() || selection.isEmpty()) { |
|
158 |
return true; |
|
159 |
} |
|
160 |
return false; |
|
161 |
} catch (Exception ex) { |
|
162 |
return true; |
|
163 |
} |
|
164 |
} else { |
|
165 |
return true; |
|
166 |
} |
|
167 |
} |
|
168 |
}; |
|
169 |
|
|
111 | 170 |
public FLayers() { |
112 | 171 |
super(); |
113 | 172 |
layerCollectionListeners = new ArrayList(); |
... | ... | |
212 | 271 |
public void addLayer(int pos, FLayer layer) { |
213 | 272 |
try { |
214 | 273 |
if (layer instanceof FLayers) { |
215 |
FLayers layers = (FLayers) layer; |
|
274 |
FLayers layersToAdd = (FLayers) layer;
|
|
216 | 275 |
if( fmap != null ) { |
217 |
fmap.addAsCollectionListener(layers); |
|
276 |
fmap.addAsCollectionListener(layersToAdd);
|
|
218 | 277 |
} |
219 | 278 |
} |
220 | 279 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
... | ... | |
381 | 440 |
return null; |
382 | 441 |
} |
383 | 442 |
|
443 |
@Override |
|
384 | 444 |
public FLayer getLayer(final DataStore store) { |
385 | 445 |
List<FLayer> theLayers = this.getLayers(new Predicate<FLayer>() { |
386 | 446 |
@Override |
... | ... | |
405 | 465 |
private List<FLayer> toPlainList(FLayer layer, List<FLayer> result, Predicate<FLayer> filter) { |
406 | 466 |
if (layer instanceof FLayers) { |
407 | 467 |
FLayers layerGroup = (FLayers) layer; |
468 |
if (filter == null || filter.test(layer)) { |
|
469 |
result.add(layer); |
|
470 |
} |
|
408 | 471 |
for (int i = 0; i < layerGroup.getLayersCount(); i++) { |
409 | 472 |
toPlainList(layerGroup.getLayer(i), result, filter); |
410 | 473 |
} |
... | ... | |
777 | 840 |
} |
778 | 841 |
} |
779 | 842 |
|
843 |
@Override |
|
780 | 844 |
public List<FLayer> getLayers(Predicate<FLayer> filter) { |
781 | 845 |
List<FLayer> theLayers = this.toPlainList(this, filter); |
782 | 846 |
return theLayers; |
... | ... | |
792 | 856 |
}); |
793 | 857 |
return (FLayer[]) activeLayers.toArray(new FLayer[activeLayers.size()]); |
794 | 858 |
} |
795 |
|
|
859 |
|
|
796 | 860 |
@Override |
797 | 861 |
public double getMinScale() { |
798 | 862 |
return -1; // La visibilidad o no la controla cada capa |
... | ... | |
1076 | 1140 |
} |
1077 | 1141 |
|
1078 | 1142 |
public FLayer getFirstActiveLayer() { |
1079 |
List<FLayer> theLayers = this.getLayers(new Predicate<FLayer>() { |
|
1080 |
@Override |
|
1081 |
public boolean test(FLayer layer) { |
|
1082 |
return layer.isActive(); |
|
1083 |
} |
|
1084 |
}); |
|
1143 |
List<FLayer> theLayers = this.getLayers(LAYER_ACTIVE); |
|
1085 | 1144 |
if( theLayers.isEmpty() ) { |
1086 | 1145 |
return null; |
1087 | 1146 |
} |
... | ... | |
1089 | 1148 |
} |
1090 | 1149 |
|
1091 | 1150 |
public FLyrVect getFirstActiveVectorLayer() { |
1092 |
List<FLayer> theLayers = this.getLayers(new Predicate<FLayer>() { |
|
1093 |
@Override |
|
1094 |
public boolean test(FLayer layer) { |
|
1095 |
return layer.isActive() && layer instanceof FLyrVect; |
|
1096 |
} |
|
1097 |
}); |
|
1151 |
List<FLayer> theLayers = this.getLayers(LAYER_ACTIVE.and(LAYER_FLYRVECT)); |
|
1098 | 1152 |
if( theLayers.isEmpty() ) { |
1099 | 1153 |
return null; |
1100 | 1154 |
} |
Also available in: Unified diff