adapt export configurator for taxonnode filter (at first only for cdm light)
authorKatja Luther <k.luther@bgbm.org>
Fri, 8 Sep 2017 12:23:27 +0000 (14:23 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 8 Sep 2017 12:23:27 +0000 (14:23 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CdmLightExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java

index 8ad87f23ad491255060faccab85a0764615d7ea5..6d4e28c7df3469fa49103af82519e7f0c3decaac 100755 (executable)
@@ -15,14 +15,17 @@ import java.util.UUID;
 
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.progress.IProgressConstants;
 
+import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
 import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -43,7 +46,14 @@ public class CdmLightExportWizard extends
 
         @Override
         public void init(IWorkbench workbench, IStructuredSelection selection) {
-            configurator = new CdmLightExportConfigurator(null);
+               configurator = new CdmLightExportConfigurator(null);
+               if (selection instanceof TreeSelection && !selection.isEmpty()){
+                       TaxonNode node = (TaxonNode)selection.getFirstElement();
+                       configurator.setTaxonNodeFilter(TaxonNodeFilter.NewTaxonNodeInstance(node.getUuid()));
+                       
+               }
+               
+            
         }
 
 
@@ -71,9 +81,12 @@ public class CdmLightExportWizard extends
                     for(Classification c:listClassifications){
                         if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
                             set.add(c.getUuid());
+                            if (!page.getCheckUseSelectedTaxonNode()){
+                               configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(c.getUuid()));
+                            }
                         }
                     }
-                    configurator.setClassificationUuids(set);
+                    
 
                 }
             }
index 222f32c74c9f61eeee54a0ad8d38b568957db59e..052d2b2c9cb3f6cb91c089981db0f9b5158c25ec 100644 (file)
@@ -9,6 +9,7 @@
 
 package eu.etaxonomy.taxeditor.io.wizard;
 
+import java.awt.Checkbox;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Collections;
@@ -16,6 +17,7 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -28,6 +30,7 @@ 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.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Text;
@@ -109,8 +112,10 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
     private List<Classification> classifications;
 
     private Classification selectedClassification;
+    private Label classificationLabel;
     
     private ExportConfiguratorBase configurator;
+    private Button checkUseSelectedtaxonNode;
 
        /**
         * @param pageName
@@ -304,10 +309,27 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                if(csvExport || csvPrintExport || outputModelExport|| csvNameExport){
 //                 Label comboBoxLabel = new Label(composite, SWT.NONE);
 //                 comboBoxLabel.setText("Classification");
-
-                   createClassificationSelectionCombo(composite);
-                   classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
-                               true, false, 2, 1));
+                       
+                       if (outputModelExport && !((CdmLightExportConfigurator)configurator).getTaxonNodeFilter().getTaxonNodesFilter().isEmpty()){
+                                 checkUseSelectedtaxonNode= new Button(composite, SWT.CHECK);
+                                 checkUseSelectedtaxonNode.setText("Use selected Taxon Node (or whole Classification)");
+                                 checkUseSelectedtaxonNode.addListener(SWT.Selection, new Listener() {
+                              @Override
+                           public void handleEvent(Event e) {
+                                  Button b = (Button) e.widget;
+                                  GridData data = (GridData)  classificationSelectionCombo.getLayoutData();
+                                  data.exclude = b.getSelection();
+                                  classificationSelectionCombo.setVisible(!data.exclude);
+                                  classificationLabel.setVisible(!data.exclude);
+                                 
+                              }
+                       });
+                       }
+                       
+                       createClassificationSelectionCombo(composite);
+                       classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
+                                       true, false, 2, 1));
+                       
                }
                
 
@@ -421,17 +443,17 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
        private void createClassificationSelectionCombo(Composite parent){
 //             classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
 
-//             Composite classificationSelection = new Composite(parent, SWT.NULL);
-//             classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
+               Composite classificationSelection = new Composite(parent, SWT.NULL);
+               classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
 
-//             GridLayout layout = new GridLayout();
-//             classificationSelection.setLayout(layout);
+               GridLayout layout = new GridLayout();
+               classificationSelection.setLayout(layout);
 
-               Label label = new Label(parent, SWT.NULL);
+               classificationLabel = 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");
+               classificationLabel.setText("Select Classification");
                
-               classificationSelectionCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
+               classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
                classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 2,1));
 
                for(Classification tree : classifications){
@@ -469,6 +491,12 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
 
                return selectedClassification.getUuid();
        }
+
+       public boolean getCheckUseSelectedTaxonNode() {
+               return checkUseSelectedtaxonNode.getSelection();
+       }
+
+