-// $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.jface.wizard.Wizard;
-import org.eclipse.ui.IImportWizard;
-
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-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 {
- private static final Logger logger = Logger
- .getLogger(AbstractImportWizard.class);
-
- protected final String CONFIGURATION_PAGE = "CONFIGURATION_PAGE";
-
- private GenericConfiguratorWizardPage pageConfiguration;
- private NomenclaturalCodeWizardPage pageNomenclaturalCode;
-
- 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){
-
- if(configurator == null){
- throw new IllegalArgumentException("Configuration may not be null");
- }
-
- // terminate any open transactions
- IConversationEnabled activePart = (IConversationEnabled) StoreUtil.getActivePage().getActivePart();
- activePart.getConversationHolder().commit(false);
-
-
-
-// ConversationHolder conversation = CdmStore.NewTransactionalConversation();
-
- 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();
-
- importer.setCdmAppController(configurator.getCdmAppController());
-
- boolean result = importer.invoke(configurator);
-
- // restarting transaction and committing it to trigger change listener
- // TODO verify correct behaviour
- activePart.getConversationHolder().startTransaction();
- activePart.getConversationHolder().commit();
-
-
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.wizard.Wizard#addPages()
- */
- @Override
- public void addPages() {
- super.addPages();
-
- pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator());
- this.addPage(pageConfiguration);
-
- pageNomenclaturalCode = new NomenclaturalCodeWizardPage((IImportConfigurator)getConfigurator());
- this.addPage(pageNomenclaturalCode);
- }
-
- public abstract CONFIG getConfigurator();
-}