01: package com.vividsolutions.jump.workbench.ui.plugin.datastore;
02:
03: import javax.swing.JComponent;
04:
05: import com.vividsolutions.jump.I18N;
06: import com.vividsolutions.jump.feature.FeatureCollection;
07: import com.vividsolutions.jump.feature.FeatureCollectionWrapper;
08: import com.vividsolutions.jump.io.datasource.DataSourceQuery;
09: import com.vividsolutions.jump.workbench.WorkbenchContext;
10: import com.vividsolutions.jump.workbench.model.Layer;
11: import com.vividsolutions.jump.workbench.model.LayerEventType;
12: import com.vividsolutions.jump.workbench.model.cache.CachingFeatureCollection;
13: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
14: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
15: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
16: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
17: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
18:
19: public class RefreshDataStoreLayerPlugin extends AbstractPlugIn {
20:
21: public RefreshDataStoreLayerPlugin() {
22: super (
23: I18N
24: .get("ui.plugin.datastore.RefreshDataStoreLayerPlugin.Refresh-Layer"));
25: }
26:
27: public static EnableCheck createEnableCheck(
28: final WorkbenchContext context) {
29: MultiEnableCheck mec = new MultiEnableCheck();
30:
31: mec.add(new EnableCheckFactory(context)
32: .createExactlyNLayersMustBeSelectedCheck(1));
33: mec.add(new EnableCheck() {
34: public String check(JComponent component) {
35: DataSourceQuery dsq = context.getLayerNamePanel()
36: .getSelectedLayers()[0].getDataSourceQuery();
37: if (dsq != null) {
38: return dsq.getDataSource() == null ? I18N
39: .get("ui.plugin.datastore.RefreshDataStoreLayerPlugin.Layer-must-have-a-Data-Source")
40: : dsq.getDataSource() instanceof DataStoreDataSource ? null
41: : I18N
42: .get("ui.plugin.datastore.RefreshDataStoreLayerPlugin.Layer-must-be-a-DataStore");
43: } else {
44: return I18N
45: .get("ui.plugin.datastore.RefreshDataStoreLayerPlugin.Layer-must-have-a-Data-Source");
46: }
47: }
48: });
49: return mec;
50: }
51:
52: public boolean execute(PlugInContext context) throws Exception {
53: Layer layer = context.getLayerNamePanel().getSelectedLayers()[0];
54: FeatureCollectionWrapper fcw = layer
55: .getFeatureCollectionWrapper();
56:
57: while (fcw != null
58: && !(fcw instanceof CachingFeatureCollection)) {
59: FeatureCollection fc = fcw.getWrappee();
60: fcw = null;
61: if (fc instanceof FeatureCollectionWrapper)
62: fcw = (FeatureCollectionWrapper) fc;
63: }
64:
65: if (fcw != null) {
66: // must be a cache
67: CachingFeatureCollection cfc = (CachingFeatureCollection) fcw;
68: cfc.emptyCache();
69:
70: context.getLayerManager().fireLayerChanged(layer,
71: LayerEventType.APPEARANCE_CHANGED);
72: }
73:
74: return false;
75: }
76: }
|