+/**
+* Copyright (C) 2017 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.wizard;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.progress.IProgressConstants;
+
+import eu.etaxonomy.cdm.io.outputmodel.OutputModelConfigurator;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 21.03.2017
+ *
+ */
+public class OutputModelExportWizard extends
+ AbstractExportWizard<OutputModelConfigurator> {
+
+ private OutputModelConfigurator configurator;
+ private ExportToFileDestinationWizardPage page;
+
+ private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ configurator = new OutputModelConfigurator(null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#getConfigurator()
+ */
+ @Override
+ public OutputModelConfigurator getConfigurator() {
+ return configurator;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ String urlString = page.getFolderText() + File.separator;
+ //+ page.getExportFileName();
+
+ final Combo combo = page.getCombo();
+ final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
+ if(combo != null){
+ int selectionIndex = combo.getSelectionIndex();
+ HashSet<UUID> set = new HashSet<UUID>();
+ if(selectionIndex == -1){
+ for(Classification c:listClassifications){
+ set.add(c.getUuid());
+ }
+ }else{
+ for(Classification c:listClassifications){
+ if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
+ set.add(c.getUuid());
+ }
+ }
+ configurator.setClassificationUuids(set);
+
+ }
+ }
+
+ // create job
+ Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
+ // configure the job
+ job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+ job.setUser(true);
+ // schedule job
+ job.schedule();
+
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#addPages()
+ */
+ @Override
+ public void addPages() {
+ //TODO create page with drop down menu for export for single classification.
+// super.addPages();
+
+
+ //standard page
+ page = ExportToFileDestinationWizardPage.OutputModel();
+
+ addPage(page);
+ }
+
+
+}