Added simple CSV Export to Taxonomic Editor
authorAlexander Oppermann <a.oppermann@bgbm.org>
Fri, 14 Nov 2014 16:29:20 +0000 (16:29 +0000)
committerAlexander Oppermann <a.oppermann@bgbm.org>
Fri, 14 Nov 2014 16:29:20 +0000 (16:29 +0000)
.gitattributes
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java

index 7955a88cd84bc5e97af2e4ead816ffb273b0a174..a3206c38d166eaa755b9a6e7d6baa79989009a9c 100644 (file)
@@ -1228,6 +1228,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/Abst
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractExcelImportWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractExportWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/AbstractImportWizard.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/DarwinCoreArchiveExportWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/EndnoteImportWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java -text
index 18331fd65c4b45520fbb3c083dd4614bb8485acf..58b9538aeb7ba543ae85a84732bc993395c09394 100644 (file)
             id="eu.etaxonomy.taxeditor.io.export.dwca"
             name="%wizard.name.9">
       </wizard>
+      <wizard
+            category="eu.etaxonomy.taxeditor.export.category.cdm"
+            class="eu.etaxonomy.taxeditor.io.wizard.CsvExportWizard"
+            id="eu.etaxonomy.taxeditor.io.export.csv"
+            name="CSV">
+      </wizard>
    </extension>
    <extension
          point="org.eclipse.ui.newWizards">
index c7b7acc9cf0dc737a853c706c0daa85d3af1e075..e3fbfe9ab2862d0159f4d3fd7577bf3a40b31c06 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * 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.
  */
@@ -18,7 +18,6 @@ import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IWorkbenchPart;
 
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
@@ -34,7 +33,7 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  * <p>
  * ExportHandler class.
  * </p>
- * 
+ *
  * @author n.hoffmann
  * @created Sep 11, 2009
  * @version 1.0
@@ -42,7 +41,7 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
 public class ExportManager extends AbstractIOManager<IExportConfigurator> {
 
        /**
-        * 
+        *
         * @param applicationConfiguration
         */
        private ExportManager(ICdmApplicationConfiguration applicationConfiguration) {
@@ -53,7 +52,7 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
         * <p>
         * NewInstance
         * </p>
-        * 
+        *
         * @param applicationConfiguration
         *            a
         *            {@link eu.etaxonomy.cdm.api.application.CdmApplicationController}
@@ -69,7 +68,7 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
         * <p>
         * createIOJob
         * </p>
-        * 
+        *
         * @param configurator
         *            a {@link eu.etaxonomy.cdm.io.common.IExportConfigurator}
         *            object.
@@ -89,23 +88,25 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
                                                "Exporting database. This will take some time.", 100);
                                monitor.worked(10);
 
-                               display.asyncExec(new Runnable() {
-
-                                       @Override
-                                       public void run() {
-                                               // terminate any open transactions
-                                               IConversationEnabled activePart = (IConversationEnabled) StoreUtil
-                                                               .getActivePage().getActivePart();
-                                               activePart.getConversationHolder().commit(false);
-                                       }
-                               });
-
-                               monitor.worked(10);
+                           /** see ticket # 4456 and */
+//                             display.asyncExec(new Runnable() {
+//
+//                                     @Override
+//                                     public void run() {
+//
+//                                         // terminate any open transactions
+//                                             IConversationEnabled activePart = (IConversationEnabled) StoreUtil
+//                                                             .getActivePage().getActivePart();
+//                                             activePart.getConversationHolder().commit(false);
+//                                     }
+//                             });
+
+//                             monitor.worked(10);
 
                                CdmDefaultExport<IExportConfigurator> exporter = new CdmDefaultExport<IExportConfigurator>();
                                configurator.setProgressMonitor(CdmProgressMonitorAdapter
                                                .CreateSubMonitor(monitor, 80));
-                               exporter.setCdmAppController((ICdmApplicationConfiguration) applicationConfiguration);
+                               exporter.setCdmAppController(applicationConfiguration);
                                monitor.worked(10);
 
                                try {
@@ -133,11 +134,11 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
                                                        // trigger
                                                        // change listener
                                                        // TODO verify correct behaviour
-                                                       
+
                                                        try{
                                                                conversationEnabled.getConversationHolder()
                                                                        .startTransaction();
-                                                       
+
                                                                conversationEnabled.getConversationHolder()
                                                                        .commit();
                                                        }catch(RuntimeException e){
@@ -178,7 +179,7 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
         * <p>
         * JaxbConfigurator
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator} object.
         */
        public final JaxbExportConfigurator JaxbConfigurator() {
@@ -189,7 +190,7 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
         * <p>
         * SddConfigurator
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator}
         *         object.
         */
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java
new file mode 100644 (file)
index 0000000..744876e
--- /dev/null
@@ -0,0 +1,117 @@
+// $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.wizard;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author a.oppermann
+ * @created Nov. 11, 2014
+ * @version 1.0
+ */
+public class CsvExportWizard extends AbstractExportWizard<CsvDemoExportConfigurator> {
+
+       private CsvDemoExportConfigurator 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 = CsvDemoExportConfigurator.NewInstance(null, null);
+       }
+
+       /*
+        * (non-Javadoc)
+        *
+        * @see
+        * eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#getConfigurator()
+        */
+       @Override
+       public CsvDemoExportConfigurator 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);
+                       configurator.setDoTaxa(true);
+                       configurator.setHasHeaderLines(true);
+                       configurator.setClassification(true);
+                       configurator.setTaxonName(true);
+                       configurator.setAuthor(true);
+                       configurator.setRank(true);
+                       configurator.setLastChange(true);
+                   }
+               }
+               configurator.setDestination(new File(urlString));
+
+               CdmStore.getExportManager().run(configurator);
+
+               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.Csv();
+
+               addPage(page);
+       }
+}
index 5fed8fbafab4d931f03460e22119f0342acb4843..580bf1f0dc7bb3dfc572d244f70cce2dfeefe7c4 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * 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.
  */
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.io.wizard;
 
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.List;
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -20,19 +21,22 @@ import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.DirectoryDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
+import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.remote.CdmRemoteSourceException;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * <p>
  * ExportToFileDestinationWizardPage class.
  * </p>
- * 
+ *
  * @author n.hoffmann
  * @created 15.06.2009
  * @version 1.0
@@ -53,10 +57,16 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
 
        public static final String DWCA_EXPORT = "DWCA_EXPORT";
 
+       public static final String CSV_EXPORT = "CSV_EXPORT";
+
        public static final String XML = "xml";
 
+       public static final String CSV = "csv";
+
        public static final String ZIP = "zip";
 
+    private static boolean csvExport = false;
+
        private DirectoryDialog folderDialog;
        private Text text_exportFileName;
 
@@ -66,11 +76,13 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
 
        private final String extension;
 
+    private Combo comboBox;
+
        /**
         * @param pageName
         * @param selection
         */
-       private ExportToFileDestinationWizardPage(String pageName, String type,
+       protected ExportToFileDestinationWizardPage(String pageName, String type,
                        String title, String description, String extension) {
                super(pageName);
 
@@ -84,7 +96,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
         * <p>
         * Jaxb
         * </p>
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
@@ -102,7 +114,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
         * <p>
         * Tcs
         * </p>
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
@@ -120,7 +132,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
         * <p>
         * Sdd
         * </p>
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
@@ -146,15 +158,31 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                                ZIP);
        }
 
+
+
+    /**
+     * @return
+     */
+    public static ExportToFileDestinationWizardPage Csv() {
+        csvExport = true;
+        return new ExportToFileDestinationWizardPage(
+                CSV_EXPORT,
+                "csv",
+                "CSV Export",
+                "Export the contents of the currently selected database into Comma Separated Value format.",
+                CSV);
+    }
+
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
         * .Composite)
         */
        /** {@inheritDoc} */
-       public void createControl(Composite parent) {
+       @Override
+    public void createControl(Composite parent) {
 
                setPageComplete(false);
 
@@ -163,6 +191,15 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                gridLayout.numColumns = 3;
                composite.setLayout(gridLayout);
 
+
+               if(csvExport){
+                   Label comboBoxLabel = new Label(composite, SWT.NONE);
+                   comboBoxLabel.setText("Classification");
+                   Combo comboBox = addComboBox(composite);
+                   comboBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
+                               true, false, 2, 1));
+               }
+
                Label fileLabel = new Label(composite, SWT.NONE);
                fileLabel.setText("File");
 
@@ -187,7 +224,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                button.addSelectionListener(new SelectionAdapter() {
                        /*
                         * (non-Javadoc)
-                        * 
+                        *
                         * @see
                         * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
                         * .swt.events.SelectionEvent)
@@ -207,7 +244,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                setControl(composite);
        }
 
-       private String generateFilename() {
+       protected String generateFilename() {
                StringBuffer buffer = new StringBuffer();
 
                Calendar cal = Calendar.getInstance();
@@ -233,7 +270,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
         * <p>
         * getExportFileName
         * </p>
-        * 
+        *
         * @return the exportFileName
         */
        public String getExportFileName() {
@@ -244,11 +281,29 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
         * <p>
         * getFolderText
         * </p>
-        * 
+        *
         * @return the folderText
         */
        public String getFolderText() {
                return text_folder.getText();
        }
 
+       private Combo addComboBox(Composite composite){
+
+           comboBox = new Combo(composite, SWT.DROP_DOWN);
+           comboBox.setText("Choose Classification");
+
+           final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
+
+           for(Classification c : listClassifications){
+               comboBox.add(c.getTitleCache());
+           }
+
+           return comboBox;
+       }
+
+       public Combo getCombo(){
+           return comboBox;
+       }
+
 }