ref #8677: layout issues in aggregation dialog
authorKatja Luther <k.luther@bgbm.org>
Wed, 27 Nov 2019 13:24:56 +0000 (14:24 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 27 Nov 2019 13:24:56 +0000 (14:24 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java

index 7e0395d1bc2d08f5f449cfe12d4584c65ff6adbd..5ba87fdd1a6485f13e371a67d369be3ab5bec53e 100755 (executable)
@@ -23,6 +23,7 @@ import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
 import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -70,9 +71,10 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
 
     private Combo comboSourceMode;
 
-    private Combo comboAggregationMode;
+    private CheckboxTableViewer aggregationModeViewer;
 
     private Button btnSelectSuperAreas;
+    private Button buttonSuperArea;
     private Combo comboStatusOrder;
 
 
@@ -110,17 +112,8 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
     @Override
     public void createControl(Composite parent) {
         final Composite composite = new Composite(parent, SWT.NULL);
-        checkExportUnpublished = new Button(composite,  SWT.CHECK);
-        checkExportUnpublished.setText("Export unpublished taxa");
-        GridData gridDataCheckUnpublished = new GridData(GridData.FILL_HORIZONTAL);
-        gridDataCheckUnpublished.horizontalSpan = 2;
 
 
-        Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
-        GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
-        gridData.horizontalSpan = 2;
-        gridData.verticalIndent = 5;
-        separator.setLayoutData(gridData);
 
         String taxonStr = "";
         int count = configurator.getTaxonNodeFilter().getSubtreeFilter().size();
@@ -225,12 +218,14 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
             }else{
                 checkUseSelectedClassification.setSelection(true);
             }
-            separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
-            gridData = new GridData(GridData.FILL_HORIZONTAL);
+            Label separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+            GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
             gridData.horizontalSpan = 2;
             gridData.verticalIndent = 5;
             separator.setLayoutData(gridData);
 
+
+
 /*
  *
 
@@ -269,6 +264,84 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
         updateLowerRankCombo();
         comboLowerRank.addListener(SWT.Selection, this);
 
+
+
+        separator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+        gridData = new GridData(GridData.FILL_HORIZONTAL);
+        gridData.horizontalSpan = 2;
+        gridData.verticalIndent = 5;
+        separator.setLayoutData(gridData);
+
+        Label aggregationModeLabel = new Label(control, SWT.NULL);
+        aggregationModeLabel.setText("Aggregation mode");
+        aggregationModeLabel.setToolTipText("Selecting none would delete all existing aggregated distributions");
+        aggregationModeViewer =  CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
+        aggregationModeViewer.setContentProvider(new ArrayContentProvider());
+        aggregationModeViewer.setLabelProvider(new LabelProvider(){
+            @Override
+            public String getText(Object element){
+                if (element instanceof AggregationMode){
+                    if (((AggregationMode)element).equals(AggregationMode.ToParent)){
+                        return "from child to parent";
+                    }
+                    if (((AggregationMode)element).equals(AggregationMode.WithinTaxon)){
+                        return "from sub area to super area";
+                    }
+                }
+                return null;
+            }
+
+        });
+        List<AggregationMode> aggregationModeList = new ArrayList<>();
+        for (AggregationMode mode: AggregationMode.values()){
+            aggregationModeList.add(mode);
+        }
+
+        aggregationModeViewer.setInput(aggregationModeList);
+
+        aggregationModeViewer.addCheckStateListener(new ICheckStateListener(){
+            @Override
+            public void checkStateChanged(    CheckStateChangedEvent event){
+                Object[] checked =aggregationModeViewer.getCheckedElements();
+                boolean areachecked = false;
+                for (int i = 0; i<checked.length;i++){
+                    if (checked[i] instanceof AggregationMode){
+                        if (((AggregationMode)checked[i]).equals(AggregationMode.WithinTaxon)){
+                            areachecked = true;
+                        }
+                    }
+                }
+                buttonSuperArea.setEnabled(areachecked);
+                getWizard().getContainer().updateButtons();
+              }
+        });
+
+
+        buttonSuperArea = new Button(control, SWT.PUSH );
+        GridData gridData2 = new GridData();
+        gridData2.horizontalSpan = 2;
+        gridData2.horizontalAlignment = SWT.LEFT;
+
+        buttonSuperArea.setLayoutData(gridData2);
+
+        buttonSuperArea.setEnabled(false);
+        buttonSuperArea.setText("Select Super Areas");
+//        buttonSuperArea.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
+        buttonSuperArea.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent event) {
+                SuperAreaSelectionWizard availableDistributionWizard = new SuperAreaSelectionWizard(configurator);
+                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
+                        availableDistributionWizard);
+
+                int open = dialog.open();
+
+            }
+        });
+
+
+
+
         Label sourceModeLabel = new Label(control, SWT.NULL);
         sourceModeLabel.setText("Source mode");
         comboSourceMode = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
@@ -280,26 +353,6 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
 
         comboSourceMode.addSelectionListener(this);
 
-        Label aggregationModeLabel = new Label(control, SWT.NULL);
-        aggregationModeLabel.setText("Aggregation mode");
-        comboAggregationMode = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
-        comboAggregationMode.setText(Messages.DistributionAggregationConfiguration_AggregationMode);
-//        for (AggregationMode mode: AggregationMode.values()){
-//            comboAggregationMode.add(mode.toString());
-//            comboAggregationMode.setData(mode.toString(), mode);
-//        }
-        comboAggregationMode.add("ranks");
-        comboAggregationMode.setData("ranks", AggregationMode.byRanks());
-
-        comboAggregationMode.add("areas and ranks");
-        comboAggregationMode.setData("areas and ranks", AggregationMode.byAreasAndRanks());
-
-        comboAggregationMode.add("areas");
-        comboAggregationMode.setData("areas", AggregationMode.byAreas());
-
-
-        comboAggregationMode.addSelectionListener(this);
-
         Label sourceTypeLabel = new Label(control, SWT.NULL);
         sourceTypeLabel.setText("Source type");
 
@@ -329,35 +382,18 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
         Label selectStatusLabel = new Label(control, SWT.NULL);
         selectStatusLabel.setText("Status order");
         comboStatusOrder = new Combo(control, SWT.PUSH );
-
+        comboStatusOrder.add("Default - by vocabulary");
+        comboStatusOrder.setData("Default - by vocabulary", null);
         for (TermTree tree: CdmStore.getService(ITermTreeService.class).list(TermType.PresenceAbsenceTerm, null, 0, null,null)){
             comboStatusOrder.add(tree.getTitleCache());
             comboStatusOrder.setData(tree.getTitleCache(), tree);
         }
-        comboStatusOrder.setText(Messages.DistributionAggregationConfiguration_StatusOrder);
-        comboStatusOrder.addSelectionListener(this);
 
-        Button buttonSuperArea = new Button(control, SWT.PUSH );
-        GridData gridData2 = new GridData();
-        gridData2.horizontalSpan = 1;
-        gridData2.horizontalAlignment = SWT.RIGHT;
-
-        buttonSuperArea.setLayoutData(gridData2);
-
-
-        buttonSuperArea.setText("Select Super Areas");
-//        buttonSuperArea.setToolTipText(Messages.ChecklistEditor_DIST_STATUS_TOOLTIP);
-        buttonSuperArea.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent event) {
-                SuperAreaSelectionWizard availableDistributionWizard = new SuperAreaSelectionWizard(configurator);
-                WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
-                        availableDistributionWizard);
+        comboStatusOrder.addSelectionListener(this);
 
-                int open = dialog.open();
 
-            }
-        });
+        checkExportUnpublished = new Button(composite,  SWT.CHECK);
+        checkExportUnpublished.setText("Export unpublished taxa");
 
         GridLayoutFactory.fillDefaults();
 
@@ -531,7 +567,14 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis
    }
 
    public List<AggregationMode> getAggregationMode(){
-       return (List<AggregationMode>) comboAggregationMode.getData(comboAggregationMode.getText());
+
+       List<AggregationMode> result = new ArrayList<>();
+       for (Object o: aggregationModeViewer.getCheckedElements()){
+           if (o instanceof AggregationMode){
+               result.add((AggregationMode)o);
+           }
+       }
+       return result;
    }