set default sel in wizard to values in configurator
authorKatja Luther <k.luther@bgbm.org>
Fri, 8 Oct 2021 11:06:21 +0000 (13:06 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 8 Oct 2021 11:06:21 +0000 (13:06 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java

index 750f9c7eb0993d9c46d19d5c58d1518192e92035..93beeb697aed969c7b14ca4326e528b87abd3aca 100755 (executable)
@@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.IClassificationService;
@@ -72,7 +73,7 @@ public class DistributionAggregationWizardPage
     private List<Classification> classifications;
     private Classification selectedClassification;
 
-    private Button checkIncludeUnpublished;
+    
 
     private Object[] checkedElements;
 
@@ -89,7 +90,8 @@ public class DistributionAggregationWizardPage
 
         String taxonStr = ""; //$NON-NLS-1$
         int count = configurator.getTaxonNodeFilter().getSubtreeFilter().size();
-
+        boolean areaChecked = configurator.getAggregationModes().contains(AggregationMode.WithinTaxon);
+        boolean toParentChecked = configurator.getAggregationModes().contains(AggregationMode.ToParent);
         for (LogicFilter<TaxonNode> filter: configurator.getTaxonNodeFilter().getSubtreeFilter()){
             subTreeNode = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(filter.getUuid());
             count--;
@@ -244,6 +246,13 @@ public class DistributionAggregationWizardPage
         }
 
         aggregationModeViewer.setInput(aggregationModeList);
+        
+        for (AggregationMode mode: configurator.getAggregationModes()){
+            if (mode instanceof AggregationMode){
+               aggregationModeViewer.setChecked(mode, true);
+            }
+        }
+        
 
         aggregationModeViewer.addCheckStateListener(new ICheckStateListener(){
             @Override
@@ -281,14 +290,16 @@ public class DistributionAggregationWizardPage
             comboAreaLevel.setData(level.getLabel(), level);
         }
         comboAreaLevel.addSelectionListener(this);
-        comboAreaLevel.setEnabled(false);
+        comboAreaLevel.setEnabled(areaChecked);
+        
+        
         GridData gridData2 = new GridData();
         gridData2.horizontalSpan = 2;
         gridData2.horizontalAlignment = SWT.LEFT;
 
         buttonSuperArea = new Button(control, SWT.PUSH );
         buttonSuperArea.setLayoutData(gridData2);
-        buttonSuperArea.setEnabled(false);
+        buttonSuperArea.setEnabled(configurator.getAggregationModes().contains(AggregationMode.WithinTaxon));
         buttonSuperArea.setText(Messages.DistributionAggregationWizardPage_SELECT_AREA);
         buttonSuperArea.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_AREA_SELECTION);
         buttonSuperArea.addSelectionListener(new SelectionAdapter() {
@@ -314,8 +325,18 @@ public class DistributionAggregationWizardPage
         }
 
         comboSourceModeChildParent.addSelectionListener(this);
-        comboSourceModeChildParent.setEnabled(false);
-        comboSourceModeChildParent.select(0);
+        comboSourceModeChildParent.setEnabled(toParentChecked);
+        int index = 0;
+        if (configurator.getToParentSourceMode() == null ){
+               comboSourceModeChildParent.select(index);
+        }else{
+               for (String text:comboSourceModeChildParent.getItems()){
+                       if (comboSourceModeChildParent.getData(text).equals(configurator.getToParentSourceMode())){
+                               comboSourceModeChildParent.select(index);
+                       }
+                       index++;
+               }
+        }
 
         Label sourceModeLabelSuperArea = new Label(control, SWT.NULL);
         sourceModeLabelSuperArea.setText(Messages.DistributionAggregationWizardPage_SOURCE_MODE_AREA);
@@ -329,8 +350,21 @@ public class DistributionAggregationWizardPage
         }
 
         comboSourceModeWithinTaxon.addSelectionListener(this);
-        comboSourceModeWithinTaxon.setEnabled(false);
-        comboSourceModeWithinTaxon.select(0);
+        comboSourceModeWithinTaxon.setEnabled(configurator.getAggregationModes().contains(AggregationMode.WithinTaxon));
+        
+        index = 0;
+        if (configurator.getWithinTaxonSourceMode() == null ){
+               comboSourceModeWithinTaxon.select(index);
+        }else{
+               for (String text:comboSourceModeWithinTaxon.getItems()){
+                       if (comboSourceModeWithinTaxon.getData(text).equals(configurator.getWithinTaxonSourceMode())){
+                               comboSourceModeWithinTaxon.select(index);
+                       }
+                       index++;
+               }
+        }
+
+        
 
         Label sourceTypeLabel = new Label(control, SWT.NULL);
         sourceTypeLabel.setText(Messages.DistributionAggregationWizardPage_SOURCE_TYPE);
@@ -352,9 +386,14 @@ public class DistributionAggregationWizardPage
         Arrays.stream(typeArray).forEach(p ->typeMap.put(p.getLabel(), p));
         Arrays.stream(typeArray).forEach(p ->typeStrings.add(p.getLabel()));
         sourceTypeViewer.setInput(typeStrings);
-        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryMediaSource.getLabel(), true);
-        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryTaxonomicSource.getLabel(), true);
-        sourceTypeViewer.getTable().setEnabled(false);
+        for (OriginalSourceType sourceType: configurator.getAggregatingSourceTypes()){
+               sourceTypeViewer.setChecked(sourceType.getLabel(), true);
+        }
+//        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryTaxonomicSource.getLabel(), true);
+//        sourceTypeViewer.getTable().setEnabled(false);
+        AggregationSourceMode taxonMode = configurator.getToParentSourceMode();
+        AggregationSourceMode areaMode = configurator.getWithinTaxonSourceMode();
+        sourceTypeViewer.getTable().setEnabled(((areaChecked && (areaMode.equals(AggregationSourceMode.ALL) || areaMode.equals(AggregationSourceMode.ALL_SAMEVALUE) ) )|| toParentChecked && (taxonMode.equals(AggregationSourceMode.ALL) || taxonMode.equals(AggregationSourceMode.ALL_SAMEVALUE) )) );
 
         //aggregation mode
 
@@ -369,10 +408,21 @@ public class DistributionAggregationWizardPage
         }
 
         comboStatusOrder.addSelectionListener(this);
-        comboStatusOrder.select(0);
+        index = 0;
+        if (configurator.getStatusOrder() == null ){
+               comboStatusOrder.select(index);
+        }else{
+               for (String text:comboStatusOrder.getItems()){
+                       if (text.equals(configurator.getStatusOrder().getTitleCache())){
+                               comboStatusOrder.select(index);
+                       }
+                       index++;
+               }
+        }
 
-        checkIncludeUnpublished = new Button(composite,  SWT.CHECK);
-        checkIncludeUnpublished.setText(Messages.DistributionAggregationWizardPage_EXPORT_UNPUBLISHED);
+        checkIncludeUnpublishedTaxa = new Button(composite,  SWT.CHECK);
+        checkIncludeUnpublishedTaxa.setText(Messages.DistributionAggregationWizardPage_EXPORT_UNPUBLISHED);
+        checkIncludeUnpublishedTaxa.setSelection(true);
 
         GridLayoutFactory.fillDefaults();
 
@@ -434,7 +484,7 @@ public class DistributionAggregationWizardPage
    }
 
    public boolean useUnpublishedData(){
-       return checkIncludeUnpublished.getSelection();
+       return checkIncludeUnpublishedTaxa.getSelection();
    }
 
     public Classification getSelectedClassification() {