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