01: package com.vividsolutions.jump.workbench.datasource;
02:
03: import java.util.Collection;
04:
05: import com.vividsolutions.jts.util.Assert;
06: import com.vividsolutions.jump.I18N;
07: import com.vividsolutions.jump.io.datasource.Connection;
08: import com.vividsolutions.jump.io.datasource.DataSourceQuery;
09: import com.vividsolutions.jump.task.TaskMonitor;
10: import com.vividsolutions.jump.workbench.WorkbenchContext;
11: import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
12: import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
13: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
14: import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
15: import com.vividsolutions.jump.workbench.ui.GUIUtil;
16: import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
17:
18: public abstract class AbstractSaveDatasetAsPlugIn extends
19: AbstractLoadSaveDatasetPlugIn {
20:
21: public void run(TaskMonitor monitor, PlugInContext context)
22: throws Exception {
23: Assert.isTrue(getDataSourceQueries().size() == 1);
24:
25: DataSourceQuery dataSourceQuery = (DataSourceQuery) getDataSourceQueries()
26: .iterator().next();
27: Assert.isTrue(dataSourceQuery.getDataSource().isWritable());
28: monitor.report(I18N
29: .get("datasource.SaveDatasetAsPlugIn.saving")
30: + " " + dataSourceQuery.toString() + "...");
31:
32: Connection connection = dataSourceQuery.getDataSource()
33: .getConnection();
34: try {
35: connection.executeUpdate(dataSourceQuery.getQuery(),
36: context.getSelectedLayer(0)
37: .getFeatureCollectionWrapper(), monitor);
38: } finally {
39: connection.close();
40: }
41: context.getSelectedLayer(0).setDataSourceQuery(dataSourceQuery)
42: .setFeatureCollectionModified(false);
43: }
44:
45: public static MultiEnableCheck createEnableCheck(
46: final WorkbenchContext workbenchContext) {
47: EnableCheckFactory checkFactory = new EnableCheckFactory(
48: workbenchContext);
49:
50: return new MultiEnableCheck()
51: .add(
52: checkFactory
53: .createWindowWithLayerNamePanelMustBeActiveCheck())
54: .add(
55: checkFactory
56: .createExactlyNLayersMustBeSelectedCheck(1));
57: }
58: }
|