01: package com.vividsolutions.jump.workbench.datasource;
02:
03: import java.awt.event.WindowAdapter;
04: import java.awt.event.WindowEvent;
05: import java.util.Collection;
06:
07: import com.vividsolutions.jump.workbench.WorkbenchContext;
08: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
09: import com.vividsolutions.jump.workbench.plugin.ThreadedBasePlugIn;
10: import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
11:
12: public abstract class AbstractLoadSaveDatasetPlugIn extends
13: ThreadedBasePlugIn {
14: private WorkbenchContext context;
15:
16: protected String getLastFormatKey() {
17: return getClass().getName() + " - LAST FORMAT";
18: }
19:
20: protected String getLastDirectoryKey() {
21: return getClass().getName() + " - LAST DIRECTORY";
22: }
23:
24: public void initialize(final PlugInContext context)
25: throws Exception {
26: this .context = context.getWorkbenchContext();
27: //Give other plug-ins a chance to add DataSourceQueryChoosers
28: //before the dialog is realized. [Jon Aquino]
29: context.getWorkbenchFrame().addWindowListener(
30: new WindowAdapter() {
31: public void windowOpened(WindowEvent e) {
32: String format = (String) PersistentBlackboardPlugIn
33: .get(context.getWorkbenchContext())
34: .get(getLastFormatKey());
35: if (format != null) {
36: setSelectedFormat(format);
37: }
38: }
39: });
40: }
41:
42: protected abstract void setSelectedFormat(String format);
43:
44: protected abstract String getSelectedFormat();
45:
46: protected WorkbenchContext getContext() {
47: return context;
48: }
49:
50: private Collection dataSourceQueries;
51:
52: public boolean execute(PlugInContext context) throws Exception {
53: dataSourceQueries = showDialog(context.getWorkbenchContext());
54: if (dataSourceQueries != null) {
55: PersistentBlackboardPlugIn.get(
56: context.getWorkbenchContext()).put(
57: getLastFormatKey(), getSelectedFormat());
58: }
59: return dataSourceQueries != null;
60: }
61:
62: protected abstract Collection showDialog(WorkbenchContext context);
63:
64: protected Collection getDataSourceQueries() {
65: return dataSourceQueries;
66: }
67: }
|