add selection of classification to csvPrintExport
authorKatja Luther <k.luther@bgbm.org>
Mon, 11 Jul 2016 11:58:13 +0000 (13:58 +0200)
committerKatja Luther <k.luther@bgbm.org>
Mon, 11 Jul 2016 11:58:13 +0000 (13:58 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvNameExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvPrintExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java

index bd6ac4a480e3e1e27e1af7ce4ae794325ec52ecc..3e13950c02f6b364613229352067dd4872bad297 100644 (file)
@@ -66,7 +66,7 @@ public class CsvNameExportWizard extends AbstractExportWizard<CsvNameExportConfi
                    + page.getExportFileName();\r
 \r
            final Combo combo = page.getCombo();\r
-\r
+           configurator.setClassificationUUID(page.getSelectedClassificationUUID());\r
            if(CdmStore.getCurrentSessionManager().isRemoting()) {\r
                // create job\r
                Job job = CdmStore.getExportManager().createIOServiceJob(configurator, new File(urlString));\r
index 61905f31f057bfb22947f96fbb3b96f045bbccce..870082e6d4ab1546d41ab64fca170637508672db 100644 (file)
@@ -60,27 +60,10 @@ public class CsvPrintExportWizard extends CsvNameExportWizard{
                                + page.getExportFileName();\r
 \r
                final Combo combo = page.getCombo();\r
-               final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);\r
-               if(combo != null){\r
-                   int selectionIndex = combo.getSelectionIndex();\r
-                   HashSet<UUID> set = new HashSet<UUID>();\r
-                   if(selectionIndex == -1){\r
-                       for(Classification c:listClassifications){\r
-                           set.add(c.getUuid());\r
-                       }\r
-                   }else{\r
-                       for(Classification c:listClassifications){\r
-                           if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){\r
-                               set.add(c.getUuid());\r
-                           }\r
-                       }\r
-\r
-                       configurator.setHasHeaderLines(true);\r
-\r
-                   }\r
-               } else{\r
-                       configurator.setClassificationUUID(listClassifications.get(0).getUuid());\r
-               }\r
+\r
+          \r
+           configurator.setClassificationUUID(page.getSelectedClassificationUUID());\r
+               \r
 \r
                if(CdmStore.getCurrentSessionManager().isRemoting()) {\r
                    // create job\r
index a35e64490f9a9f6d3c6879b9d90a08572fc013a8..e5c389f6688c62c04e2452f65c78bdc8a5f15525 100644 (file)
@@ -12,21 +12,27 @@ package eu.etaxonomy.taxeditor.io.wizard;
 
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
+import java.util.UUID;
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
 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.Control;
 import org.eclipse.swt.widgets.DirectoryDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
+import eu.etaxonomy.cdm.api.service.IClassificationService;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
@@ -41,7 +47,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 15.06.2009
  * @version 1.0
  */
-public class ExportToFileDestinationWizardPage extends WizardPage {
+public class ExportToFileDestinationWizardPage extends WizardPage implements SelectionListener {
 
        /** Constant <code>DATE_FORMAT_NOW="yyyyMMddHHmm"</code> */
        public static final String DATE_FORMAT_NOW = "yyyyMMddHHmm";
@@ -85,7 +91,11 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
 
        private final String extension;
 
-    private Combo comboBox;
+    private Combo classificationSelectionCombo;
+    
+    private List<Classification> classifications;
+    
+    private Classification selectedClassification;
 
        /**
         * @param pageName
@@ -225,13 +235,26 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                GridLayout gridLayout = new GridLayout();
                gridLayout.numColumns = 3;
                composite.setLayout(gridLayout);
+               if(classifications == null){
+                       classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
+                       Collections.sort(classifications, new Comparator<Classification>() {
+
+                @Override
+                public int compare(Classification o1, Classification o2) {
+                    return o1.getTitleCache().compareTo(o2.getTitleCache());
+                }
+            });
+                       
+                       selectedClassification = classifications.iterator().next();
+               }
 
 
-               if(csvExport){
+               if(csvExport || csvPrintExport){
                    Label comboBoxLabel = new Label(composite, SWT.NONE);
                    comboBoxLabel.setText("Classification");
-                   Combo comboBox = addComboBox(composite);
-                   comboBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
+                  
+                   createClassificationSelectionCombo(composite);
+                   classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
                                true, false, 2, 1));
                }
                
@@ -326,22 +349,55 @@ public class ExportToFileDestinationWizardPage extends WizardPage {
                return text_folder.getText();
        }
 
-       private Combo addComboBox(Composite composite){
+       private Control createClassificationSelectionCombo(Composite parent){
+//             classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
 
-           comboBox = new Combo(composite, SWT.DROP_DOWN);
-           comboBox.setText("Choose Classification");
+               Composite classificationSelection = new Composite(parent, SWT.NULL);
+               classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
 
-           final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
+               GridLayout layout = new GridLayout();
+               classificationSelection.setLayout(layout);
 
-           for(Classification c : listClassifications){
-               comboBox.add(c.getTitleCache());
-           }
+               Label label = new Label(classificationSelection, SWT.NULL);
+               // TODO not working is not really true but leave it here to remind everyone that this is under construction
+               label.setText("Select Classification");
+               classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
+               classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
+
+               for(Classification tree : classifications){
+                       classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
+
+               }
 
-           return comboBox;
+               classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
+
+               // TODO remember last selection
+               classificationSelectionCombo.addSelectionListener(this);
+
+
+
+               return classificationSelection;
        }
 
        public Combo getCombo(){
-           return comboBox;
+           return classificationSelectionCombo;
+       }
+
+       @Override
+       public void widgetSelected(SelectionEvent e) {
+               selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
+               
+       }
+
+       @Override
+       public void widgetDefaultSelected(SelectionEvent e) {
+               //not needed here
+               
+       }
+
+       public UUID getSelectedClassificationUUID() {
+               
+               return selectedClassification.getUuid();
        }
 
 }