Implemented some of the import/export functionality. Major refactoring of datasource...
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / io / AbstractImportWizard.java
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.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.core.runtime.jobs.Job;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.ILaunchConfiguration;
22 import org.eclipse.debug.core.ILaunchConfigurationType;
23 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24 import org.eclipse.debug.core.ILaunchManager;
25 import org.eclipse.jdt.core.IClasspathEntry;
26 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
27 import org.eclipse.jdt.launching.IVMInstall;
28 import org.eclipse.jdt.launching.IVMInstallType;
29 import org.eclipse.jdt.launching.JavaRuntime;
30 import org.eclipse.jface.wizard.Wizard;
31 import org.eclipse.ui.IImportWizard;
32
33 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
34 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
35 import eu.etaxonomy.cdm.io.common.IIoConfigurator;
36 import eu.etaxonomy.taxeditor.store.StoreUtil;
37
38 /**
39 * @author n.hoffmann
40 * @created 24.06.2009
41 * @version 1.0
42 */
43 public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard, IJavaLaunchConfigurationConstants{
44 private static final Logger logger = Logger
45 .getLogger(AbstractImportWizard.class);
46
47 protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
48
49 private GenericConfiguratorWizardPage pageConfiguration;
50
51 private CdmDefaultImport<IImportConfigurator> importer;
52
53 /**
54 * Performs an import into a new database. The application context has to be changed
55 * @param configurator
56 * @return
57 */
58 public boolean doImportExternal(IImportConfigurator configurator){
59
60
61 // try {
62 // ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
63 // ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
64 // ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
65 //
66 // // delete possible prior launch configurations
67 // for (ILaunchConfiguration configuration : configurations) {
68 // if (configuration.getName().equals("NewInstance")) {
69 // configuration.delete();
70 // break;
71 // }
72 // }
73 //
74 // ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "NewInstance");
75 //
76 // workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
77 //
78 //
79 // workingCopy.setAttribute(ATTR_VM_INSTALL_NAME, JavaRuntime.getDefaultVMInstall().getName());
80 // workingCopy.setAttribute(ATTR_VM_INSTALL_TYPE, JavaRuntime.getDefaultVMInstall().getVMInstallType().getId());
81 //
82 //
83 // workingCopy.launch(ILaunchManager.RUN_MODE, null);
84
85
86 // IVMInstall vm = JavaRuntime.getDefaultVMInstall();//VMInstall(proj);
87 // if (vm == null) vm = JavaRuntime.getDefaultVMInstall();
88 // IVMRunner vmr = vm.getVMRunner(ILaunchManager.RUN_MODE);
89 // String[] cp = JavaRuntime.computeDefaultRuntimeClassPath(proj);
90 // VMRunnerConfiguration config = new VMRunnerConfiguration(main, cp);
91 // ILaunch launch = new Launch(null,
92 // ILaunchManager.RUN_MODE, null);
93 // vmr.run(config, launch, null);
94
95 // IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
96 //
97 // IVMInstall install = null;
98 // for(IVMInstallType type : types){
99 // install = type.createVMInstall(type.getId());
100 // break;
101 // }
102 //
103 //
104 // IPath path = JavaRuntime.newJREContainerPath(install);
105 // String jrePath = path.toPortableString();
106
107
108 //
109 // ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
110 // ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
111 // ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "NewInstance");
112 // wc.setAttribute(ATTR_JRE_CONTAINER_PATH, jrePath);
113 // wc.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
114 // ILaunchConfiguration config = wc.doSave();
115 // config.launch(ILaunchManager.RUN_MODE, null);
116 //
117 //
118 // Process p = Runtime.getRuntime().exec(cmdarray);
119 //
120 //
121 // } catch (CoreException e) {
122 // logger.error("Error launching import", e);
123 // }
124
125 StoreUtil.notImplementedMessage();
126
127 return true;
128 }
129
130 /**
131 * Use when importing data into the current application context
132 *
133 * @param configurator
134 * @return
135 */
136 public boolean doImportInternal(final IImportConfigurator configurator){
137 importer = new CdmDefaultImport();
138
139 Job importJob = new Job("Import"){
140 @Override
141 protected IStatus run(IProgressMonitor monitor) {
142 return importer.invoke(configurator) ? Status.OK_STATUS : Status.CANCEL_STATUS;
143 }
144 };
145
146 importJob.schedule();
147
148 return true;
149 }
150
151 /* (non-Javadoc)
152 * @see org.eclipse.jface.wizard.Wizard#addPages()
153 */
154 @Override
155 public void addPages() {
156 super.addPages();
157
158 pageConfiguration = new GenericConfiguratorWizardPage(CONFIGURATION_PAGE, getConfigurator());
159 this.addPage(pageConfiguration);
160 }
161
162 public abstract CONFIG getConfigurator();
163 }