1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.io;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.eclipse.jface.wizard.Wizard;
|
15
|
import org.eclipse.ui.IImportWizard;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
18
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
19
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
20
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
21
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
22
|
|
23
|
/**
|
24
|
* @author n.hoffmann
|
25
|
* @created 24.06.2009
|
26
|
* @version 1.0
|
27
|
*/
|
28
|
public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard {
|
29
|
private static final Logger logger = Logger
|
30
|
.getLogger(AbstractImportWizard.class);
|
31
|
|
32
|
protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
|
33
|
|
34
|
private GenericConfiguratorWizardPage pageConfiguration;
|
35
|
private NomenclaturalCodeWizardPage pageNomenclaturalCode;
|
36
|
|
37
|
private CdmDefaultImport<IImportConfigurator> importer;
|
38
|
|
39
|
/**
|
40
|
* Performs an import into a new database. The application context has to be changed
|
41
|
* @param configurator
|
42
|
* @return
|
43
|
*/
|
44
|
public boolean doImportExternal(IImportConfigurator configurator){
|
45
|
|
46
|
|
47
|
// try {
|
48
|
// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
|
49
|
// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
|
50
|
// ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
|
51
|
//
|
52
|
// // delete possible prior launch configurations
|
53
|
// for (ILaunchConfiguration configuration : configurations) {
|
54
|
// if (configuration.getName().equals("NewInstance")) {
|
55
|
// configuration.delete();
|
56
|
// break;
|
57
|
// }
|
58
|
// }
|
59
|
//
|
60
|
// ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "NewInstance");
|
61
|
//
|
62
|
// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
|
63
|
//
|
64
|
//
|
65
|
// workingCopy.setAttribute(ATTR_VM_INSTALL_NAME, JavaRuntime.getDefaultVMInstall().getName());
|
66
|
// workingCopy.setAttribute(ATTR_VM_INSTALL_TYPE, JavaRuntime.getDefaultVMInstall().getVMInstallType().getId());
|
67
|
//
|
68
|
//
|
69
|
// workingCopy.launch(ILaunchManager.RUN_MODE, null);
|
70
|
|
71
|
|
72
|
// IVMInstall vm = JavaRuntime.getDefaultVMInstall();//VMInstall(proj);
|
73
|
// if (vm == null) vm = JavaRuntime.getDefaultVMInstall();
|
74
|
// IVMRunner vmr = vm.getVMRunner(ILaunchManager.RUN_MODE);
|
75
|
// String[] cp = JavaRuntime.computeDefaultRuntimeClassPath(proj);
|
76
|
// VMRunnerConfiguration config = new VMRunnerConfiguration(main, cp);
|
77
|
// ILaunch launch = new Launch(null,
|
78
|
// ILaunchManager.RUN_MODE, null);
|
79
|
// vmr.run(config, launch, null);
|
80
|
|
81
|
// IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
|
82
|
//
|
83
|
// IVMInstall install = null;
|
84
|
// for(IVMInstallType type : types){
|
85
|
// install = type.createVMInstall(type.getId());
|
86
|
// break;
|
87
|
// }
|
88
|
//
|
89
|
//
|
90
|
// IPath path = JavaRuntime.newJREContainerPath(install);
|
91
|
// String jrePath = path.toPortableString();
|
92
|
|
93
|
|
94
|
//
|
95
|
// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
|
96
|
// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
|
97
|
// ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "NewInstance");
|
98
|
// wc.setAttribute(ATTR_JRE_CONTAINER_PATH, jrePath);
|
99
|
// wc.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
|
100
|
// ILaunchConfiguration config = wc.doSave();
|
101
|
// config.launch(ILaunchManager.RUN_MODE, null);
|
102
|
//
|
103
|
//
|
104
|
// Process p = Runtime.getRuntime().exec(cmdarray);
|
105
|
//
|
106
|
//
|
107
|
// } catch (CoreException e) {
|
108
|
// logger.error("Error launching import", e);
|
109
|
// }
|
110
|
|
111
|
StoreUtil.notImplementedMessage();
|
112
|
|
113
|
return true;
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Use when importing data into the current application context
|
118
|
*
|
119
|
* @param configurator
|
120
|
* @return
|
121
|
*/
|
122
|
public boolean doImportInternal(final IImportConfigurator configurator){
|
123
|
|
124
|
if(configurator == null){
|
125
|
throw new IllegalArgumentException("Configuration may not be null");
|
126
|
}
|
127
|
|
128
|
// terminate any open transactions
|
129
|
IConversationEnabled activePart = (IConversationEnabled) StoreUtil.getActivePage().getActivePart();
|
130
|
activePart.getConversationHolder().commit(false);
|
131
|
|
132
|
|
133
|
|
134
|
// ConversationHolder conversation = CdmStore.NewTransactionalConversation();
|
135
|
|
136
|
importer = new CdmDefaultImport();
|
137
|
//
|
138
|
// Job importJob = new Job("Import"){
|
139
|
// @Override
|
140
|
// protected IStatus run(IProgressMonitor monitor) {
|
141
|
// return importer.invoke(configurator) ? Status.OK_STATUS : Status.CANCEL_STATUS;
|
142
|
// }
|
143
|
// };
|
144
|
//
|
145
|
// importJob.schedule();
|
146
|
|
147
|
importer.setCdmAppController(configurator.getCdmAppController());
|
148
|
|
149
|
boolean result = importer.invoke(configurator);
|
150
|
|
151
|
// restarting transaction and committing it to trigger change listener
|
152
|
// TODO verify correct behaviour
|
153
|
activePart.getConversationHolder().startTransaction();
|
154
|
activePart.getConversationHolder().commit();
|
155
|
|
156
|
|
157
|
return result;
|
158
|
}
|
159
|
|
160
|
/* (non-Javadoc)
|
161
|
* @see org.eclipse.jface.wizard.Wizard#addPages()
|
162
|
*/
|
163
|
@Override
|
164
|
public void addPages() {
|
165
|
super.addPages();
|
166
|
|
167
|
pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
|
168
|
this.addPage(pageConfiguration);
|
169
|
|
170
|
pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
|
171
|
this.addPage(pageNomenclaturalCode);
|
172
|
}
|
173
|
|
174
|
public abstract CONFIG getConfigurator();
|
175
|
}
|