Project

General

Profile

Download (19 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.dialog.configurator;
10

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

    
15
import org.eclipse.jface.layout.GridLayoutFactory;
16
import org.eclipse.jface.viewers.ArrayContentProvider;
17
import org.eclipse.jface.viewers.CheckStateChangedEvent;
18
import org.eclipse.jface.viewers.CheckboxTableViewer;
19
import org.eclipse.jface.viewers.ICheckStateListener;
20
import org.eclipse.jface.viewers.LabelProvider;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Combo;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Listener;
30

    
31
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
32
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
33
import eu.etaxonomy.cdm.api.service.description.AggregationSourceMode;
34
import eu.etaxonomy.cdm.api.service.description.AggregationType;
35
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregation;
36
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.cdm.persistence.dto.DescriptiveDataSetBaseDto;
40
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
41
import eu.etaxonomy.taxeditor.l10n.Messages;
42

    
43
/**
44
 * @author k.luther
45
 * @since 11.12.2019
46
 */
47
public class StructuredDescriptionAggregationConfigurationWizardPage
48
        extends AggregationConfigurationWizardPage<StructuredDescriptionAggregation,StructuredDescriptionAggregationConfiguration>
49
        implements Listener {
50

    
51
    protected CheckboxTableViewer subTreeSelectionViewer;
52
    private List<TaxonNodeDto> selectedNodes;
53

    
54
    protected Button checkIncludeDefaultDescriptions;
55
    protected Button checkIncludeLiteratureDescriptions;
56
    protected DescriptiveDataSetBaseDto ddsDTO;
57

    
58

    
59
    private Label selectSubtreeLabel;
60

    
61
    protected StructuredDescriptionAggregationConfigurationWizardPage(StructuredDescriptionAggregationConfiguration configurator, List<TaxonNodeDto> nodes) {
62
        super(Messages.DistributionAggregationWizardPage_TITLE);
63
        this.configurator = configurator;
64
        this.setDescription(Messages.DistributionAggregationWizardPage_DESCRIPTION);
65
        selectedNodes = nodes;
66
        ddsDTO = CdmApplicationState.getCurrentAppConfig().getDescriptiveDataSetService().getDescriptiveDataSetDtoByUuid(configurator.getDatasetUuid());
67

    
68
    }
69

    
70
    @Override
71
    public void createControl(Composite parent) {
72

    
73
        final Composite control = new Composite(parent, SWT.NULL);
74
        GridLayout gridLayoutControl = new GridLayout();
75
        gridLayoutControl.numColumns = 2;
76
        control.setLayout(gridLayoutControl);
77
        control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
78

    
79
        //taxon node filter
80
        GridData gridDataRadioComposite = new GridData();
81
        gridDataRadioComposite.horizontalSpan = 2;
82
        GridLayout gridLayoutRadioComposite = new GridLayout();
83
        gridLayoutRadioComposite.numColumns = 1;
84
        Composite radioComposite = new Composite(control, SWT.NULL);
85
        radioComposite.setLayoutData(gridDataRadioComposite);
86
        radioComposite.setLayout(gridLayoutRadioComposite);
87

    
88
        boolean hasTaxonFilter = !configurator.getTaxonNodeFilter().getSubtreeFilter().isEmpty();
89

    
90
        //   ... from descriptive data set
91
        checkUseHigherLevel = new Button(radioComposite,  SWT.RADIO);
92
        checkUseHigherLevel.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_ALL_SUBTREES);
93
        checkUseHigherLevel.addListener(SWT.Selection, new Listener() {
94
           @Override
95
           public void handleEvent(Event e) {
96
               subTreeSelectionViewer.getTable().setEnabled(!checkUseHigherLevel.getSelection());
97
               selectSubtreeLabel.setEnabled(!checkUseHigherLevel.getSelection());
98
               updateHigherRankCombo();
99
               if (checkUseHigherLevel.getSelection()){
100
                   setPageComplete(true);
101
               }
102
           }
103
        });
104

    
105

    
106
        //   ... from selected subtree
107
        checkUseSelectedSubtree= new Button(radioComposite, SWT.RADIO);
108
        checkUseSelectedSubtree.setText(Messages.AggregationWizardPage_SUBTREE);
109
        checkUseSelectedSubtree.addListener(SWT.Selection, new Listener() {
110
            @Override
111
            public void handleEvent(Event e) {
112
                subTreeSelectionViewer.getTable().setEnabled(!checkUseHigherLevel.getSelection());
113
                selectSubtreeLabel.setEnabled(checkUseSelectedSubtree.getSelection() || checkUseSelectedTaxonNode.getSelection());
114
                if (checkUseSelectedSubtree.getSelection() && subTreeSelectionViewer.getCheckedElements().length == 0){
115
                    setPageComplete(false);
116
                }else{
117
                    setPageComplete(true);
118
                }
119
           }
120
        });
121

    
122
        //    ... from selected taxon
123
        checkUseSelectedTaxonNode= new Button(radioComposite, SWT.RADIO);
124
        checkUseSelectedTaxonNode.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_SELECTED_TAXA_ONLY);
125
        checkUseSelectedTaxonNode.addListener(SWT.Selection, new Listener() {
126
            @Override
127
            public void handleEvent(Event e) {
128
                subTreeSelectionViewer.getTable().setEnabled(!checkUseHigherLevel.getSelection());
129
                selectSubtreeLabel.setEnabled(!checkUseHigherLevel.getSelection());
130
                if (checkUseSelectedTaxonNode.getSelection() && subTreeSelectionViewer.getCheckedElements().length == 0){
131
                    setPageComplete(false);
132
                }else{
133
                    setPageComplete(true);
134
                }
135
            }
136
        });
137
        checkUseSelectedSubtree.setSelection(hasTaxonFilter);
138

    
139
        //subtree selection
140
        selectSubtreeLabel = new Label(control, SWT.NULL);
141
        selectSubtreeLabel.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_SUBTREE);
142
        selectSubtreeLabel.setToolTipText(Messages.StructuredDescriptionAggregationWizardPage_TOOLTIP_SELECT_SUBTREE);
143

    
144
        GridData gridData = new GridData();
145
        gridData.horizontalIndent = 25;
146
        gridData.verticalAlignment = SWT.TOP;
147
        selectSubtreeLabel.setLayoutData(gridData);
148

    
149
        subTreeSelectionViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
150
        subTreeSelectionViewer.setContentProvider(new ArrayContentProvider());
151
        subTreeSelectionViewer.setLabelProvider(new LabelProvider(){
152
            @Override
153
            public String getText(Object element){
154
                if (element instanceof TaxonNodeDto){
155
                   return ((TaxonNodeDto)element).getNameTitleCache();
156
                }else if (element instanceof TaxonNode){
157
                    return ((TaxonNode)element).getTaxon().getName().getTitleCache();
158
                }
159
                return null;
160
            }
161
        });
162

    
163
        if (selectedNodes == null || selectedNodes.isEmpty()){
164
            List<TaxonNode> nodeList;
165
            List<UUID> uuidList = new ArrayList<>();
166
            configurator.getTaxonNodeFilter().getSubtreeFilter().stream().forEach(p ->uuidList.add(p.getUuid()));
167
            List<String> propertyPaths = new ArrayList<>();
168
            propertyPaths.add("taxon.name");
169
            nodeList = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(uuidList, propertyPaths);
170
            subTreeSelectionViewer.setInput(nodeList);
171
        }else{
172
            subTreeSelectionViewer.setInput(selectedNodes);
173
        }
174
        subTreeSelectionViewer.setAllChecked(true);
175
        subTreeSelectionViewer.addCheckStateListener(new ICheckStateListener(){
176
            @Override
177
            public void checkStateChanged(    CheckStateChangedEvent event){
178
                Object[] checked =subTreeSelectionViewer.getCheckedElements();
179
                if (checked.length == 0){
180
                   setPageComplete(false);
181
                }else{
182
                    setPageComplete(true);
183
                }
184
            }
185
        });
186

    
187
//        GridLayoutFactory.fillDefaults();
188

    
189
        //scope (published taxa, literature + default descriptions)
190
        Label scopeLabel = new Label(control, SWT.NULL);
191
        scopeLabel.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_DEFINE_SCOPE);
192

    
193
        Composite scopeComposite = new Composite(control, SWT.NULL);
194
        GridLayout gridDataScopeComposite = new GridLayout();
195
        gridDataScopeComposite.numColumns = 1;
196
        scopeComposite.setLayout(gridDataScopeComposite);
197

    
198
//        GridLayoutFactory.fillDefaults();
199

    
200
        checkIncludeUnpublishedTaxa = new Button(scopeComposite, SWT.CHECK);
201
        checkIncludeUnpublishedTaxa.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_UNPUBLISHED_TAXA);
202
        checkIncludeUnpublishedTaxa.setSelection(true);
203

    
204
        checkIncludeDefaultDescriptions = new Button(scopeComposite, SWT.CHECK);
205
        checkIncludeDefaultDescriptions.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_DEFAULT_DESCRIPTION);
206
        checkIncludeDefaultDescriptions.setEnabled(false);
207

    
208
        checkIncludeLiteratureDescriptions = new Button(scopeComposite, SWT.CHECK);
209
        checkIncludeLiteratureDescriptions.setText(Messages.StructuredDescriptionAggregationWizardPage_SELECT_LITERATURE_DESCRIPTION);
210
        checkIncludeLiteratureDescriptions.setSelection(configurator.isIncludeLiterature());
211
        GridLayoutFactory.fillDefaults();
212

    
213
        //ranks
214
        Label higherRankLabel = new Label(control, SWT.NULL);
215
        higherRankLabel.setText(Messages.DistributionAggregationWizardPage_HIGHEST_RANK);
216
        comboHigherRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY);
217
        updateHigherRankCombo();
218
        setConfigValueToRankCombo(comboHigherRank, ddsDTO.getMaxRank() != null? ddsDTO.getMaxRank().getUuid(): null);
219
        comboHigherRank.addListener(SWT.Selection, this);
220

    
221
        Label lowerRankLabel = new Label(control, SWT.NULL);
222
        lowerRankLabel.setText(Messages.DistributionAggregationWizardPage_LOWEST_RANK);
223
        comboLowerRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY);
224
        updateLowerRankCombo();
225
        setConfigValueToRankCombo(comboLowerRank, ddsDTO.getMinRank() != null? ddsDTO.getMinRank().getUuid(): null);
226
        comboLowerRank.addListener(SWT.Selection, this);
227

    
228
        //aggregation mode viewer
229
        Label aggregationModeLabel = new Label(control, SWT.NULL);
230
        aggregationModeLabel.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
231
        aggregationModeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_AGGR_MODE);
232

    
233
        aggregationModeViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
234
        aggregationModeViewer.setContentProvider(new ArrayContentProvider());
235
        aggregationModeViewer.setLabelProvider(new LabelProvider(){
236
            @Override
237
            public String getText(Object element){
238
                if (element instanceof AggregationMode){
239
                	if (((AggregationMode)element).getKey().equals("INTAX")){
240
                		return Messages.StructuredDescriptionAggregationWizardPage_SOURCEMODE_WITHIN_TAXON;
241
                	}else if (((AggregationMode)element).getKey().equals("TOPAR")){
242
                		return Messages.StructuredDescriptionAggregationWizardPage_SOURCEMODE_CHILD_PARENT;
243
                	}
244
                   return ((AggregationMode)element).getLabel();
245
                }
246
                return null;
247
            }
248
        });
249
        List<AggregationMode> aggregationModeList = AggregationMode.list(AggregationType.StructuredDescription);
250
        aggregationModeViewer.setInput(aggregationModeList);
251
        aggregationModeViewer.setCheckedElements(configurator.getAggregationModes().toArray());
252
        aggregationModeViewer.addCheckStateListener(new ICheckStateListener(){
253
            @Override
254
            public void checkStateChanged(    CheckStateChangedEvent event){
255
                Object[] checked =aggregationModeViewer.getCheckedElements();
256
                boolean withinChecked = false;
257
                boolean toParentChecked = false;
258
                for (int i = 0; i<checked.length;i++){
259
                    if (checked[i] instanceof AggregationMode){
260
                        if (((AggregationMode)checked[i]).equals(AggregationMode.WithinTaxon)){
261
                            withinChecked = true;
262
                        }
263
                        if (((AggregationMode)checked[i]).equals(AggregationMode.ToParent)){
264
                            toParentChecked = true;
265
                        }
266
                    }
267
                }
268

    
269
                comboSourceModeChildParent.setEnabled(toParentChecked);
270
                comboSourceModeWithinTaxon.setEnabled(withinChecked);
271
                getWizard().getContainer().updateButtons();
272
            }
273
        });
274

    
275
        //source mode within taxon
276
        Label sourceModeLabelWithin = new Label(control, SWT.NULL);
277
        sourceModeLabelWithin.setText(Messages.StructuredDescriptionAggregationWizardPage_SOURCEMODE_WITHIN_TAXON);
278
        sourceModeLabelWithin.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_WITHIN_TAXON);
279
        comboSourceModeWithinTaxon = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
280
        comboSourceModeWithinTaxon.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
281

    
282
        int index = 0;
283
        int defaultSelectionIndex = 0;
284
        for (AggregationSourceMode mode :AggregationSourceMode.list(AggregationMode.WithinTaxon, AggregationType.StructuredDescription) ){
285
            comboSourceModeWithinTaxon.add(mode.getLabel());
286
            comboSourceModeWithinTaxon.setData(mode.getLabel(), mode);
287
            if (configurator.getWithinTaxonSourceMode().equals(mode)){
288
                defaultSelectionIndex = index;
289
            }
290
            index++;
291
        }
292

    
293
        comboSourceModeWithinTaxon.setEnabled(configurator.getAggregationModes().contains(AggregationMode.WithinTaxon));
294
        comboSourceModeWithinTaxon.select(defaultSelectionIndex);
295
        comboSourceModeWithinTaxon.addListener(SWT.Selection, this);
296

    
297
        //source mode child parent
298
        Label sourceModeChildParentLabel = new Label(control, SWT.NULL);
299
        sourceModeChildParentLabel.setText(Messages.StructuredDescriptionAggregationWizardPage_SOURCEMODE_CHILD_PARENT);
300
        sourceModeChildParentLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_CHILD_PARENT);
301
        comboSourceModeChildParent = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
302
        comboSourceModeChildParent.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
303

    
304
        index = 0;
305
        defaultSelectionIndex = 0;
306
        for (AggregationSourceMode mode :AggregationSourceMode.list(AggregationMode.ToParent, AggregationType.StructuredDescription) ){
307
            comboSourceModeChildParent.add(mode.getLabel());
308
            comboSourceModeChildParent.setData(mode.getLabel(), mode);
309
            if (configurator.getToParentSourceMode().equals(mode)){
310
                defaultSelectionIndex = index;
311
            }
312
            index++;
313
        }
314

    
315
        comboSourceModeChildParent.setEnabled(configurator.getAggregationModes().contains(AggregationMode.ToParent));
316
        comboSourceModeChildParent.select(defaultSelectionIndex);
317
        comboSourceModeChildParent.addListener(SWT.Selection, this);
318
        GridLayoutFactory.fillDefaults();
319

    
320
        /*source type
321
        //TODO: distinguish within taxon and parent child source types (#9805)
322
        Label sourceTypeLabel = new Label(control, SWT.NULL);
323
        sourceTypeLabel.setText(Messages.DistributionAggregationWizardPage_SOURCE_TYPE);
324
        sourceTypeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCE_TYPE);
325
        sourceTypeViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
326
        sourceTypeViewer.setContentProvider(new ArrayContentProvider());
327

    
328
        sourceTypeViewer.addCheckStateListener(new ICheckStateListener(){
329
            @Override
330
            public void checkStateChanged(    CheckStateChangedEvent event){
331
//                checkedElements=sourceTypeViewer.getCheckedElements();
332
                getWizard().getContainer().updateButtons();
333
              }
334
        });
335

    
336
        List<String> typeStrings = new ArrayList<>();
337
        OriginalSourceType[] typeArray = OriginalSourceType.values();
338
        Arrays.sort(typeArray, new OriginalSourceTypeComparator(null));
339
        Arrays.stream(typeArray).forEach(p ->typeMap.put(p.getLabel(), p));
340
        Arrays.stream(typeArray).forEach(p ->typeStrings.add(p.getLabel()));
341
        sourceTypeViewer.setInput(typeStrings);
342
        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryMediaSource.getLabel(), true);
343
        sourceTypeViewer.setChecked(OriginalSourceType.PrimaryTaxonomicSource.getLabel(), true);
344
        sourceTypeViewer.getTable().setEnabled(false);
345
        */
346
        setControl(control);
347
    }
348

    
349
    @Override
350
    public void handleEvent(Event event) {
351
        if (event.widget.equals(comboHigherRank)){
352
            updateLowerRankCombo();
353
        }
354

    
355
        if (event.widget.equals(this.checkUseHigherLevel)){
356
            updateHigherRankCombo();
357
            updateLowerRankCombo();
358
        }
359
        if (event.widget.equals(this.checkUseSelectedSubtree)){
360
            updateHigherRankCombo();
361
            updateLowerRankCombo();
362
        }
363
        if (event.widget.equals(this.checkUseSelectedTaxonNode)){
364
            updateHigherRankCombo();
365
            updateLowerRankCombo();
366
        }
367

    
368
        if (event.widget.equals(this.comboSourceModeChildParent) || event.widget.equals(this.comboSourceModeWithinTaxon)){
369
//            if (getSourceModeChildParent().equals(AggregationSourceMode.NONE) && getSourceModeWithinTaxon().equals(AggregationSourceMode.NONE)){
370
//                sourceTypeViewer.getTable().setEnabled(false);
371
//            }else {
372
//                sourceTypeViewer.getTable().setEnabled(true);
373
//            }
374
        }
375
    }
376

    
377
    public List<TaxonNode> getSelectedTaxonNodes(){
378

    
379
        List<TaxonNode> result = new ArrayList<>();
380
        for (Object o: subTreeSelectionViewer.getCheckedElements()){
381
            if (o instanceof TaxonNode){
382
                result.add((TaxonNode)o);
383
            }
384
        }
385
        return result;
386
    }
387

    
388
    protected void setConfigValueToRankCombo(Combo rankCombo, UUID rankUuid) {
389
		int index = 0;
390

    
391
       if (rankUuid == null){
392
       		rankCombo.select(index);
393
       }else{
394
	        Rank rank = null;
395
	        for (String item: rankCombo.getItems()){
396
	        	if (rankCombo.getData(item) instanceof Rank){
397
	        		rank = (Rank) rankCombo.getData(item);
398
	        		if (rank.getUuid().equals(rankUuid)){
399
	        			rankCombo.select(index);
400
	        			break;
401
	        		}
402
	        	}
403
	        	index++;
404
	        }
405
       }
406
	}
407
}
(10-10/10)