01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library 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 GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.project.internal.property;
16:
17: import java.net.URL;
18: import java.util.Set;
19: import java.util.concurrent.CopyOnWriteArraySet;
20: import java.util.concurrent.atomic.AtomicBoolean;
21:
22: import net.refractions.udig.catalog.CatalogPlugin;
23: import net.refractions.udig.catalog.IGeoResource;
24: import net.refractions.udig.catalog.objectproperty.ObjectPropertyCatalogListener;
25: import net.refractions.udig.project.BlackboardEvent;
26: import net.refractions.udig.project.IBlackboard;
27: import net.refractions.udig.project.IBlackboardListener;
28: import net.refractions.udig.project.ILayer;
29: import net.refractions.udig.project.ProjectBlackboardConstants;
30: import net.refractions.udig.ui.ProgressManager;
31: import net.refractions.udig.ui.operations.AbstractPropertyValue;
32: import net.refractions.udig.ui.operations.PropertyValue;
33:
34: import org.geotools.data.FeatureStore;
35:
36: /**
37: * returns true if the layer has a FeatureStore as a resource.
38: *
39: * @author Jesse
40: * @since 1.1.0
41: */
42: public class FeatureStoreResourceProperty extends
43: AbstractPropertyValue<ILayer> implements PropertyValue<ILayer> {
44:
45: private volatile AtomicBoolean isEvaluating = new AtomicBoolean(
46: false);
47: private Set<URL> ids = new CopyOnWriteArraySet<URL>();
48:
49: public boolean canCacheResult() {
50: return true;
51: }
52:
53: public boolean isBlocking() {
54: return true;
55: }
56:
57: public boolean isTrue(final ILayer object, String value) {
58: isEvaluating.set(true);
59: try {
60: final FeatureStore store = object.getResource(
61: FeatureStore.class, ProgressManager.instance()
62: .get());
63: object.getBlackboard().addListener(
64: new IBlackboardListener() {
65:
66: public void blackBoardChanged(
67: BlackboardEvent event) {
68: if (event
69: .getKey()
70: .equals(
71: ProjectBlackboardConstants.LAYER__DATA_QUERY)) {
72: notifyListeners(object);
73: }
74: }
75:
76: public void blackBoardCleared(IBlackboard source) {
77: notifyListeners(object);
78: }
79:
80: });
81:
82: final IGeoResource resource = object
83: .findGeoResource(FeatureStore.class);
84: if (resource != null && ids.add(resource.getIdentifier())) {
85: CatalogPlugin.getDefault().getLocalCatalog()
86: .addCatalogListener(
87: new ObjectPropertyCatalogListener(
88: object, resource, isEvaluating,
89: this ));
90: }
91: return store != null;
92: } catch (Exception e) {
93: return false;
94: } finally {
95: isEvaluating.set(false);
96: }
97: }
98:
99: }
|