Revision 47784 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/featuretype/FeatureAttributeTreeModel.java
FeatureAttributeTreeModel.java | ||
---|---|---|
4 | 4 |
import java.util.Collections; |
5 | 5 |
import java.util.HashSet; |
6 | 6 |
import java.util.List; |
7 |
import java.util.Locale; |
|
7 | 8 |
import java.util.Set; |
8 | 9 |
import java.util.function.Predicate; |
10 |
import java.util.function.Supplier; |
|
9 | 11 |
import javax.swing.event.TreeModelListener; |
10 | 12 |
import javax.swing.tree.TreeModel; |
11 | 13 |
import javax.swing.tree.TreePath; |
... | ... | |
30 | 32 |
import org.slf4j.Logger; |
31 | 33 |
import org.slf4j.LoggerFactory; |
32 | 34 |
import org.gvsig.expressionevaluator.Code.Callable; |
35 |
import org.gvsig.fmap.dal.StoresRepository; |
|
33 | 36 |
import org.gvsig.fmap.dal.feature.FeatureExtraColumns; |
34 | 37 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
38 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
|
35 | 39 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
36 | 40 |
import org.gvsig.tools.dispose.Disposable; |
37 | 41 |
import org.gvsig.tools.dispose.DisposeUtils; |
... | ... | |
64 | 68 |
implements Node { |
65 | 69 |
|
66 | 70 |
private List<Node> childs; |
67 |
private FeatureStore store;
|
|
71 |
private Supplier<FeatureStore> store;
|
|
68 | 72 |
private final int type; |
69 | 73 |
|
70 |
public DefaultNode(FeatureStore store, List<OrderedAttribute> attributes) {
|
|
71 |
super(store == null ? "" : store.getName(), null);
|
|
74 |
public DefaultNode(String name, Supplier<FeatureStore> store, List<OrderedAttribute> attributes) {
|
|
75 |
super(name, null);
|
|
72 | 76 |
DisposeUtils.bind(store); |
73 | 77 |
this.store = store; |
74 | 78 |
this.type = OrderedAttribute.TYPE_REGURAL; |
... | ... | |
78 | 82 |
} |
79 | 83 |
} |
80 | 84 |
|
81 |
private DefaultNode(FeatureStore store, FeatureAttributeDescriptor attribute, int type) {
|
|
85 |
private DefaultNode(Supplier<FeatureStore> store, FeatureAttributeDescriptor attribute, int type) {
|
|
82 | 86 |
super(attribute.getLocalizedLabel(), attribute); |
83 | 87 |
DisposeUtils.bind(store); |
84 | 88 |
// LOGGER.info("BIND "+store.hashCode()+", "+this.getLabel()+", "+this.hashCode()); |
... | ... | |
120 | 124 |
|
121 | 125 |
@Override |
122 | 126 |
public FeatureStore getFeatureStore() { |
123 |
return this.store; |
|
127 |
return this.store.get();
|
|
124 | 128 |
} |
125 | 129 |
|
126 | 130 |
@Override |
... | ... | |
142 | 146 |
ContextForeingKey context = foreingKey.createContext(); |
143 | 147 |
// Ojo, no liberamos el contexto para que no se destruya el store. |
144 | 148 |
try { |
145 |
FeatureStore theStore = foreingKey.getFeatureStore(context); |
|
146 |
if (theStore == null) { |
|
149 |
// FeatureStore theStore = foreingKey.getFeatureStore(context); |
|
150 |
StoresRepository storesRepository = foreingKey.getStoresRepository(context); |
|
151 |
String tableName = foreingKey.getTableName(); |
|
152 |
Supplier<FeatureStore> theStore = () -> (FeatureStore) storesRepository.getStore(tableName); |
|
153 |
FeatureType featureType = storesRepository.getFeatureType(tableName); |
|
154 |
OpenFeatureStoreParameters theStoreParams = (OpenFeatureStoreParameters) storesRepository.get(tableName); |
|
155 |
if (featureType == null || theStoreParams==null ) { |
|
147 | 156 |
this.childs = Collections.EMPTY_LIST; |
148 | 157 |
} else { |
149 |
FeatureType featureType = foreingKey.getFeatureType(context); |
|
150 |
String fullName = theStore.getFullName(); |
|
158 |
String fullName = theStoreParams.getSourceId(); |
|
151 | 159 |
if (stores.contains(fullName)) { |
152 | 160 |
// Si ya hemos a?adido el store al arbol no lo volvemos a a?adir. |
153 | 161 |
this.childs = Collections.EMPTY_LIST; |
... | ... | |
185 | 193 |
Codes parameters = caller.parameters(); |
186 | 194 |
String tableName = (String) ((Code.Identifier)(parameters.get(1))).name(); |
187 | 195 |
DataManager dataManager = DALLocator.getDataManager(); |
188 |
FeatureStore theStore = (FeatureStore) dataManager.getStoresRepository().getStore(tableName); |
|
189 |
if (theStore == null) { |
|
196 |
// FeatureStore theStore = (FeatureStore) dataManager.getStoresRepository().getStore(tableName); |
|
197 |
StoresRepository storesRepository = dataManager.getStoresRepository(); |
|
198 |
Supplier<FeatureStore> theStore = () -> (FeatureStore) storesRepository.getStore(tableName); |
|
199 |
OpenFeatureStoreParameters theStoreParams = (OpenFeatureStoreParameters) storesRepository.get(tableName); |
|
200 |
FeatureType featureType = storesRepository.getFeatureType(tableName); |
|
201 |
if (featureType == null || theStoreParams==null ) { |
|
190 | 202 |
this.childs = Collections.EMPTY_LIST; |
191 | 203 |
} else { |
192 |
FeatureType featureType = theStore.getDefaultFeatureType(); |
|
193 |
String fullName = theStore.getFullName();
|
|
204 |
// FeatureType featureType = theStore.getDefaultFeatureType();
|
|
205 |
String fullName = theStoreParams.getSourceId();
|
|
194 | 206 |
if (stores.contains(fullName)) { |
195 | 207 |
// Si ya hemos a?adido el store al arbol no lo volvemos a a?adir. |
196 | 208 |
this.childs = Collections.EMPTY_LIST; |
... | ... | |
208 | 220 |
this.childs.add(new DefaultNode(theStore, attribute.getDescriptor(), attribute.getType())); |
209 | 221 |
} |
210 | 222 |
stores.add(fullName); |
211 |
DisposeUtils.disposeQuietly(theStore); |
|
223 |
// DisposeUtils.disposeQuietly(theStore);
|
|
212 | 224 |
} |
213 | 225 |
} |
214 | 226 |
} |
... | ... | |
236 | 248 |
@Override |
237 | 249 |
public void dispose() { |
238 | 250 |
// LOGGER.info("DISPOSE "+store.hashCode()+", "+this.getLabel()+", "+this.hashCode()); |
239 |
DisposeUtils.disposeQuietly(this.store); |
|
251 |
// DisposeUtils.disposeQuietly(this.store);
|
|
240 | 252 |
this.store = null; |
241 | 253 |
if (this.childs!=null) { |
242 | 254 |
for (Node child : this.childs) { |
... | ... | |
286 | 298 |
-1, |
287 | 299 |
extra |
288 | 300 |
); |
289 |
this.root = new DefaultNode(store, attributes); |
|
301 |
this.root = new DefaultNode( |
|
302 |
store.getName(), |
|
303 |
() -> store, |
|
304 |
attributes |
|
305 |
); |
|
290 | 306 |
this.stores = new HashSet<>(); |
291 | 307 |
this.showRelations = showRelations; |
292 | 308 |
} |
Also available in: Unified diff