Project

General

Profile

Revision 70e39ea8

ID70e39ea8fa4cd9580d9b3263aad33dec3b9d607c
Parent d29f2403
Child bb7eab5c

Added by Katja Luther 11 months ago

ref #7981: implement aggregation configuration wizard

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/AggregationConfigurationWizardPage.java
88 88
        comboHigherRank.add(""); //$NON-NLS-1$
89 89
        if (name != null){
90 90
            for (Rank rank: CdmStore.getTermManager().getPreferredTerms(Rank.class)){
91
                if (useClassification() || (name != null && name.getRank().isHigher(rank) || name.getRank().equals(rank))){
91
                if (useHigherLevel() || (name != null && name.getRank().isHigher(rank) || name.getRank().equals(rank))){
92 92
                    rankList.add(rank);
93 93
                }
94 94
            }
......
153 153
       return null;
154 154
   }
155 155

  
156
   public boolean useClassification(){
156
   public boolean useHigherLevel(){
157 157
       return checkUseHigherLevel.getSelection();
158 158
   }
159 159

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationConfiguratorWizard.java
47 47
        configurator.setStatusOrder(page.getStatusOrder());
48 48
        if (page.useSubtree()){
49 49
            configurator.setTaxonNodeFilter(TaxonNodeFilter.NewSubtreeInstance(page.getSubTreeNode()));
50
        } else if (page.useClassification()){
50
        } else if (page.useHigherLevel()){
51 51
            configurator.setTaxonNodeFilter(TaxonNodeFilter.NewClassificationInstance(page.getSelectedClassification()));
52 52
        } else if (page.useTaxonNode()){
53 53
            configurator.setTaxonNodeFilter(TaxonNodeFilter.NewTaxonNodeInstance(page.getSubTreeNode()));
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/StructuredAggregationConfigurationWizard.java
17 17
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
18 18
import eu.etaxonomy.cdm.api.service.longrunningService.ILongRunningTasksService;
19 19
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
20
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
21
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
22
import eu.etaxonomy.cdm.model.location.NamedArea;
23
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20 24
import eu.etaxonomy.taxeditor.l10n.Messages;
21 25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
22 26
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
......
30 34
    private final StructuredDescriptionAggregationConfiguration configurator;
31 35
    private StructuredDescriptionAggregationConfigurationWizardPage page;
32 36
    private ILongRunningTasksService longRunningTaskService;
37
    private DescriptiveDataSet dataSet;
33 38

  
34
    public StructuredAggregationConfigurationWizard(StructuredDescriptionAggregationConfiguration config) {
39
    public StructuredAggregationConfigurationWizard(StructuredDescriptionAggregationConfiguration config, DescriptiveDataSet dataSet) {
35 40
        super();
36 41
        this.configurator = config;
42
        this.dataSet = dataSet;
37 43
        setNeedsProgressMonitor(true);
38 44
        this.setWindowTitle(Messages.SetAggregationConfiguration_Title);
39 45
        longRunningTaskService = CdmApplicationState.getLongRunningTasksService();
......
53 59
        configurator.setAggregationMode(page.getAggregationMode());
54 60
        configurator.setToParentSourceMode(page.getSourceModeChildParent());
55 61

  
62

  
63

  
64
//        for (TaxonNode taxonNode : matrix.getDescriptiveDataSet().getTaxonSubtreeFilter()) {
65
//            filter = filter.orSubtree(taxonNode);
66
//        }
67
        TaxonNodeFilter filter = configurator.getTaxonNodeFilter();
68
        if (!page.useHigherLevel()) {
69
            filter = TaxonNodeFilter.NewRankInstance(dataSet.getMinRank(),
70
                    dataSet.getMaxRank());
71
            for (NamedArea namedArea : dataSet.getGeoFilter()) {
72
                filter = filter.orArea(namedArea.getUuid());
73
            }
74
            for (TaxonNode node: page.getSelectedTaxonNodes()) {
75
                if (page.useSubtree()){
76
                    filter = filter.orSubtree(node);
77
                }else{
78
                    filter = filter.orTaxon(node.getTaxon());
79
                }
80
            }
81
            configurator.setTaxonNodeFilter(filter);
82
        }
83

  
84

  
56 85
        UUID uuid = longRunningTaskService.invoke(configurator);
57 86

  
58 87
        Display.getDefault().asyncExec(new Runnable() {
59 88
            @Override
60 89
            public void run() {
61
                AbstractUtility.executeMoniteredOperation("Aggregate Descriptions",
90
                AbstractUtility.executeMoniteredOperation("Aggregate Structured Descriptions",
62 91
                        uuid,
63 92
                        1000,
64 93
                        false,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/StructuredDescriptionAggregationConfigurationWizardPage.java
9 9
package eu.etaxonomy.taxeditor.ui.dialog.configurator;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Arrays;
12 13
import java.util.List;
14
import java.util.UUID;
13 15

  
14
import org.apache.commons.lang.StringUtils;
16
import org.eclipse.jface.layout.GridLayoutFactory;
15 17
import org.eclipse.jface.viewers.ArrayContentProvider;
16 18
import org.eclipse.jface.viewers.CheckStateChangedEvent;
17 19
import org.eclipse.jface.viewers.CheckboxTableViewer;
......
32 34
import eu.etaxonomy.cdm.api.service.description.AggregationSourceMode;
33 35
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregation;
34 36
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
35
import eu.etaxonomy.cdm.filter.LogicFilter;
37
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
36 38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
37 39
import eu.etaxonomy.taxeditor.l10n.Messages;
40
import eu.etaxonomy.taxeditor.ui.combo.OriginalSourceTypeComparator;
38 41

  
39 42
/**
40 43
 * @author k.luther
41 44
 * @since 11.12.2019
42 45
 */
43
public class StructuredDescriptionAggregationConfigurationWizardPage extends AggregationConfigurationWizardPage<StructuredDescriptionAggregation> {
46
public class StructuredDescriptionAggregationConfigurationWizardPage extends AggregationConfigurationWizardPage<StructuredDescriptionAggregation> implements Listener {
47

  
48
    protected CheckboxTableViewer subTreeSelectionViewer;
44 49

  
45 50

  
46 51
    /**
......
58 63

  
59 64
    @Override
60 65
    public void createControl(Composite parent) {
61
        final Composite composite = new Composite(parent, SWT.NULL);
66
        final Composite control = new Composite(parent, SWT.NULL);
67
        GridLayout gridLayoutControl = new GridLayout();
68
        gridLayoutControl.numColumns = 2;
69
        control.setLayout(gridLayoutControl);
70
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
62 71

  
63 72
        //select between taxonnode filter for the whole descriptive dataset or the selected taxonnode/subtree
64
        TaxonNode subTreeNode;
65
        int count = configurator.getTaxonNodeFilter().getSubtreeFilter().size();
66
        String taxonStr = "";
67
        for (LogicFilter<TaxonNode> filter: configurator.getTaxonNodeFilter().getSubtreeFilter()){
68
            subTreeNode = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(filter.getUuid());
69
            count--;
70
            if (subTreeNode.hasTaxon()){
71
                taxonStr += subTreeNode.getTaxon().getName().getTitleCache();
72
                if (count>0){
73
                    taxonStr += ", "; //$NON-NLS-1$
73

  
74

  
75
        GridData gridDataRadioComposite = new GridData();
76
        gridDataRadioComposite.horizontalSpan = 2;
77
        GridLayout gridLayoutRadioComposite = new GridLayout();
78
        gridLayoutRadioComposite.numColumns = 1;
79
        Composite radioComposite = new Composite(control, SWT.NULL);
80
        radioComposite.setLayoutData(gridDataRadioComposite);
81
        radioComposite.setLayout(gridLayoutRadioComposite);
82

  
83
        checkUseSelectedSubtree= new Button(radioComposite,  SWT.RADIO);
84
        checkUseSelectedSubtree.setText(Messages.AggregationWizardPage_SUBTREE);
85
        checkUseSelectedSubtree.addListener(SWT.Selection, new Listener() {
86
            @Override
87
            public void handleEvent(Event e) {
88
                subTreeSelectionViewer.getTable().setEnabled(checkUseSelectedSubtree.getSelection());
89
                if (checkUseSelectedSubtree.getSelection() && subTreeSelectionViewer.getCheckedElements().length == 0){
90
                    setPageComplete(false);
91
                }else{
92
                    setPageComplete(true);
93
                }
94
           }
95
        });
96

  
97
        checkUseSelectedTaxonNode= new Button(radioComposite,  SWT.RADIO);
98
        checkUseSelectedTaxonNode.setText("Aggregation only for selected taxon/taxa");
99
        checkUseSelectedTaxonNode.addListener(SWT.Selection, new Listener() {
100
            @Override
101
            public void handleEvent(Event e) {
102
                subTreeSelectionViewer.getTable().setEnabled(checkUseSelectedTaxonNode.getSelection());
103
                if (checkUseSelectedTaxonNode.getSelection() && subTreeSelectionViewer.getCheckedElements().length == 0){
104
                    setPageComplete(false);
105
                }else{
106
                    setPageComplete(true);
74 107
                }
75 108
            }
76
        }
77
        if (StringUtils.isNotBlank(taxonStr)){
78
            checkUseSelectedSubtree= new Button(composite,  SWT.RADIO);
79
            checkUseSelectedSubtree.setText(Messages.AggregationWizardPage_SUBTREE +  taxonStr);
80
            checkUseSelectedSubtree.addListener(SWT.Selection, new Listener() {
81
                @Override
82
                public void handleEvent(Event e) {
83
                    updateHigherRankCombo();
84
               }
85
            });
86

  
87
            checkUseSelectedTaxonNode= new Button(composite,  SWT.RADIO);
88
            checkUseSelectedTaxonNode.setText(Messages.AggregationWizardPage_SINGLE_TAXON +  taxonStr);
89
            checkUseSelectedTaxonNode.addListener(SWT.Selection, new Listener() {
90
                @Override
91
                public void handleEvent(Event e) {
92
                    updateHigherRankCombo();
109

  
110

  
111
        });
112

  
113
        Label selectSubtreeLabel = new Label(control, SWT.NULL);
114
        selectSubtreeLabel.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_SUBTREE);
115
        selectSubtreeLabel.setToolTipText(Messages.StructuredDescriptionAggregationWizardPage_TOOLTIP_SELECT_SUBTREE);
116
        subTreeSelectionViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
117

  
118
        subTreeSelectionViewer.setContentProvider(new ArrayContentProvider());
119

  
120

  
121
        subTreeSelectionViewer.setLabelProvider(new LabelProvider(){
122
            @Override
123
            public String getText(Object element){
124
                if (element instanceof TaxonNode){
125
                   return ((TaxonNode)element).getTaxon().getName().getTitleCache();
93 126
                }
127
                return null;
128
            }
94 129

  
130
        });
131

  
132
        List<TaxonNode> nodeList;
133
        List<UUID> uuidList = new ArrayList<>();
134
        configurator.getTaxonNodeFilter().getSubtreeFilter().stream().forEach(p ->uuidList.add(p.getUuid()));
135
        List<String> propertyPaths = new ArrayList<>();
136
        propertyPaths.add("taxon.name");
137
        nodeList = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(uuidList, propertyPaths);
138

  
139
        subTreeSelectionViewer.setInput(nodeList);
140
        subTreeSelectionViewer.setAllChecked(true);
141
        subTreeSelectionViewer.addCheckStateListener(new ICheckStateListener(){
142
            @Override
143
            public void checkStateChanged(    CheckStateChangedEvent event){
144
                Object[] checked =subTreeSelectionViewer.getCheckedElements();
145
                if (checked.length == 0){
146
                   setPageComplete(false);
147
                }else{
148
                    setPageComplete(true);
149
                }
150
            }
151
        });
95 152

  
96
            });
97
        }
98 153

  
99 154
        //use taxonnode filter of the descriptive data set
100
        checkUseHigherLevel = new Button(composite,  SWT.RADIO);
101
        checkUseHigherLevel.setText(Messages.DistributionAggregationWizardPage_CLASSIFICATION);
155
        checkUseHigherLevel = new Button(radioComposite,  SWT.RADIO);
156
        checkUseHigherLevel.setText("Use all subtrees included in descriptive data set");
102 157
        checkUseHigherLevel.addListener(SWT.Selection, new Listener() {
103 158
           @Override
104 159
           public void handleEvent(Event e) {
105 160
               updateHigherRankCombo();
161
               if (checkUseHigherLevel.getSelection()){
162
                   setPageComplete(true);
163
               }
106 164
           }
107 165
        });
108 166

  
109 167

  
110
        final Composite control = new Composite(composite, SWT.NULL);
111
        GridLayout gridLayoutControl = new GridLayout();
112
        gridLayoutControl.numColumns = 2;
113
        control.setLayout(gridLayoutControl);
114
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
168

  
169

  
170
        GridLayoutFactory.fillDefaults();
171

  
172
        Label higherRankLabel = new Label(control, SWT.NULL);
173
        higherRankLabel.setText(Messages.DistributionAggregationWizardPage_HIGHEST_RANK);
174

  
175
        comboHigherRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY);
176
        updateHigherRankCombo();
177
        comboHigherRank.addListener(SWT.Selection, this);
178

  
179

  
180
        Label lowerRankLabel = new Label(control, SWT.NULL);
181
        lowerRankLabel.setText(Messages.DistributionAggregationWizardPage_LOWEST_RANK);
182
        comboLowerRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY);
183
        updateLowerRankCombo();
184
        comboLowerRank.addListener(SWT.Selection, this);
115 185

  
116 186
        Label aggregationModeLabel = new Label(control, SWT.NULL);
117 187
        aggregationModeLabel.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
......
194 264

  
195 265
        comboSourceModeChildParent.setEnabled(false);
196 266
        comboSourceModeChildParent.select(0);
267
        GridLayoutFactory.fillDefaults();
268
        Label sourceTypeLabel = new Label(control, SWT.NULL);
269
        sourceTypeLabel.setText(Messages.DistributionAggregationWizardPage_SOURCE_TYPE);
270
        sourceTypeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCE_TYPE);
271
        sourceTypeViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
272
        sourceTypeViewer.setContentProvider(new ArrayContentProvider());
197 273

  
198 274

  
199
        setControl(composite);
275
        sourceTypeViewer.addCheckStateListener(new ICheckStateListener(){
276
            @Override
277
            public void checkStateChanged(    CheckStateChangedEvent event){
278
//                checkedElements=sourceTypeViewer.getCheckedElements();
279
                getWizard().getContainer().updateButtons();
280
              }
281
        });
282

  
283
        List<String> typeStrings = new ArrayList<>();
284
        OriginalSourceType[] typeArray = OriginalSourceType.values();
285
        Arrays.sort(typeArray, new OriginalSourceTypeComparator(null));
286
        Arrays.stream(typeArray).forEach(p ->typeMap.put(p.getMessage(), p));
287
        Arrays.stream(typeArray).forEach(p ->typeStrings.add(p.getMessage()));
288
        typeStrings.remove(OriginalSourceType.NomenclaturalReference.getMessage());
289
        sourceTypeViewer.setInput(typeStrings);
290
        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryMediaSource.getMessage(), true);
291
        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryTaxonomicSource.getMessage(), true);
292
        sourceTypeViewer.getTable().setEnabled(false);
293
        setControl(control);
200 294
    }
201 295

  
296
    @Override
297
    public void handleEvent(Event event) {
298
        if (event.widget.equals(comboHigherRank)){
299
            updateLowerRankCombo();
300
        }
202 301

  
302
        if (event.widget.equals(this.checkUseHigherLevel)){
303
            updateHigherRankCombo();
304
            updateLowerRankCombo();
305
        }
306
        if (event.widget.equals(this.checkUseSelectedSubtree)){
307
            updateHigherRankCombo();
308
            updateLowerRankCombo();
309
        }
310
        if (event.widget.equals(this.checkUseSelectedTaxonNode)){
311
            updateHigherRankCombo();
312
            updateLowerRankCombo();
313
        }
314

  
315
    }
203 316

  
317
    public List<TaxonNode> getSelectedTaxonNodes(){
204 318

  
319
        List<TaxonNode> result = new ArrayList<>();
320
        for (Object o: subTreeSelectionViewer.getCheckedElements()){
321
            if (o instanceof TaxonNode){
322
                result.add((TaxonNode)o);
323
            }
324
        }
325
        return result;
326
    }
205 327

  
206 328

  
207 329
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)