+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.io;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.IVMInstallType;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IImportWizard;
+
+import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator;
+import eu.etaxonomy.cdm.io.common.IIoConfigurator;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+
+/**
+ * @author n.hoffmann
+ * @created 24.06.2009
+ * @version 1.0
+ */
+public abstract class AbstractImportWizard<CONFIG extends IIoConfigurator> extends Wizard implements IImportWizard, IJavaLaunchConfigurationConstants{
+ private static final Logger logger = Logger
+ .getLogger(AbstractImportWizard.class);
+
+ protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
+
+ private GenericConfiguratorWizardPage pageConfiguration;
+
+ private CdmDefaultImport<IImportConfigurator> importer;
+
+ /**
+ * Performs an import into a new database. The application context has to be changed
+ * @param configurator
+ * @return
+ */
+ public boolean doImportExternal(IImportConfigurator configurator){
+
+
+// try {
+// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
+// ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
+//
+// // delete possible prior launch configurations
+// for (ILaunchConfiguration configuration : configurations) {
+// if (configuration.getName().equals("NewInstance")) {
+// configuration.delete();
+// break;
+// }
+// }
+//
+// ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "NewInstance");
+//
+// workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
+//
+//
+// workingCopy.setAttribute(ATTR_VM_INSTALL_NAME, JavaRuntime.getDefaultVMInstall().getName());
+// workingCopy.setAttribute(ATTR_VM_INSTALL_TYPE, JavaRuntime.getDefaultVMInstall().getVMInstallType().getId());
+//
+//
+// workingCopy.launch(ILaunchManager.RUN_MODE, null);
+
+
+// IVMInstall vm = JavaRuntime.getDefaultVMInstall();//VMInstall(proj);
+// if (vm == null) vm = JavaRuntime.getDefaultVMInstall();
+// IVMRunner vmr = vm.getVMRunner(ILaunchManager.RUN_MODE);
+// String[] cp = JavaRuntime.computeDefaultRuntimeClassPath(proj);
+// VMRunnerConfiguration config = new VMRunnerConfiguration(main, cp);
+// ILaunch launch = new Launch(null,
+// ILaunchManager.RUN_MODE, null);
+// vmr.run(config, launch, null);
+
+// IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
+//
+// IVMInstall install = null;
+// for(IVMInstallType type : types){
+// install = type.createVMInstall(type.getId());
+// break;
+// }
+//
+//
+// IPath path = JavaRuntime.newJREContainerPath(install);
+// String jrePath = path.toPortableString();
+
+
+//
+// ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+// ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION);
+// ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "NewInstance");
+// wc.setAttribute(ATTR_JRE_CONTAINER_PATH, jrePath);
+// wc.setAttribute(ATTR_MAIN_TYPE_NAME, "eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin");
+// ILaunchConfiguration config = wc.doSave();
+// config.launch(ILaunchManager.RUN_MODE, null);
+//
+//
+// Process p = Runtime.getRuntime().exec(cmdarray);
+//
+//
+// } catch (CoreException e) {
+// logger.error("Error launching import", e);
+// }
+
+ StoreUtil.notImplementedMessage();
+
+ return true;
+ }
+
+ /**
+ * Use when importing data into the current application context
+ *
+ * @param configurator
+ * @return
+ */
+ public boolean doImportInternal(final IImportConfigurator configurator){
+ importer = new CdmDefaultImport();
+
+ Job importJob = new Job("Import"){
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ return importer.invoke(configurator) ? Status.OK_STATUS : Status.CANCEL_STATUS;
+ }
+ };
+
+ importJob.schedule();
+
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ @Override
+ public void addPages() {
+ super.addPages();
+
+ pageConfiguration = new GenericConfiguratorWizardPage(CONFIGURATION_PAGE, getConfigurator());
+ this.addPage(pageConfiguration);
+ }
+
+ public abstract CONFIG getConfigurator();
+}