Project

General

Profile

Download (14.1 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.Arrays;
13
import java.util.List;
14
import java.util.UUID;
15

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

    
32
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
33
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
34
import eu.etaxonomy.cdm.api.service.description.AggregationSourceMode;
35
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregation;
36
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
37
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.taxeditor.l10n.Messages;
40
import eu.etaxonomy.taxeditor.ui.combo.OriginalSourceTypeComparator;
41

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

    
48
    protected CheckboxTableViewer subTreeSelectionViewer;
49

    
50

    
51
    /**
52
     * @param pageName
53
     */
54
    protected StructuredDescriptionAggregationConfigurationWizardPage(StructuredDescriptionAggregationConfiguration configurator) {
55
        super(Messages.DistributionAggregationWizardPage_TITLE);
56
        this.configurator = configurator;
57

    
58
        this.setDescription(Messages.DistributionAggregationWizardPage_DESCRIPTION);
59
    }
60

    
61

    
62

    
63

    
64
    @Override
65
    public void createControl(Composite parent) {
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));
71

    
72
        //select between taxonnode filter for the whole descriptive dataset or the selected taxonnode/subtree
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(Messages.AggregationWizardPage_SINGLE_TAXON);
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);
107
                }
108
            }
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();
126
                }
127
                return null;
128
            }
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
        });
152

    
153

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

    
167

    
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);
185

    
186
        Label aggregationModeLabel = new Label(control, SWT.NULL);
187
        aggregationModeLabel.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
188
        aggregationModeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_AGGR_MODE);
189
        aggregationModeViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
190
        aggregationModeViewer.setContentProvider(new ArrayContentProvider());
191
        aggregationModeViewer.setLabelProvider(new LabelProvider(){
192
            @Override
193
            public String getText(Object element){
194
                if (element instanceof AggregationMode){
195
                   return ((AggregationMode)element).getMessage();
196
                }
197
                return null;
198
            }
199

    
200
        });
201
        List<AggregationMode> aggregationModeList = new ArrayList<>();
202
        for (AggregationMode mode: AggregationMode.values()){
203
            aggregationModeList.add(mode);
204
        }
205

    
206
        aggregationModeViewer.setInput(aggregationModeList);
207

    
208
        aggregationModeViewer.addCheckStateListener(new ICheckStateListener(){
209
            @Override
210
            public void checkStateChanged(    CheckStateChangedEvent event){
211
                Object[] checked =aggregationModeViewer.getCheckedElements();
212
                boolean withinChecked = false;
213
                boolean toParentChecked = false;
214
                for (int i = 0; i<checked.length;i++){
215
                    if (checked[i] instanceof AggregationMode){
216
                        if (((AggregationMode)checked[i]).equals(AggregationMode.WithinTaxon)){
217
                            withinChecked = true;
218
                        }
219
                        if (((AggregationMode)checked[i]).equals(AggregationMode.ToParent)){
220
                            toParentChecked = true;
221
                        }
222
                    }
223
                }
224

    
225
                comboSourceModeChildParent.setEnabled(toParentChecked);
226
                comboSourceModeWithinTaxon.setEnabled(withinChecked);
227
//                AggregationSourceMode areaMode = (AggregationSourceMode)comboSourceModeSubAreaSuperArea.getData(comboSourceModeSubAreaSuperArea.getText());
228
                AggregationSourceMode taxonMode = (AggregationSourceMode)comboSourceModeChildParent.getData(comboSourceModeChildParent.getText());
229
//                getSourceTypeViewer().getTable().setEnabled(((areachecked && (areaMode.equals(AggregationSourceMode.ALL) || areaMode.equals(AggregationSourceMode.ALL_SAMEVALUE) ) )|| toParentChecked && (taxonMode.equals(AggregationSourceMode.ALL) || taxonMode.equals(AggregationSourceMode.ALL_SAMEVALUE) )) );
230
                getWizard().getContainer().updateButtons();
231
              }
232
        });
233

    
234
        Label sourceModeLabelWithin = new Label(control, SWT.NULL);
235

    
236
        sourceModeLabelWithin.setText(Messages.DistributionAggregationWizardPage_SOURCEMODE_WITHIN_TAXON);
237
        sourceModeLabelWithin.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_WITHIN_TAXON);
238
        comboSourceModeWithinTaxon = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
239
        comboSourceModeWithinTaxon.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
240

    
241
        for (AggregationSourceMode mode :AggregationSourceMode.values()){
242
            comboSourceModeWithinTaxon.add(mode.getMessage());
243
            comboSourceModeWithinTaxon.setData(mode.getMessage(), mode);
244

    
245
        }
246

    
247

    
248
        comboSourceModeWithinTaxon.setEnabled(false);
249
        comboSourceModeWithinTaxon.select(0);
250

    
251
        Label sourceModeLabel = new Label(control, SWT.NULL);
252

    
253
        sourceModeLabel.setText(Messages.DistributionAggregationWizardPage_SOURCEMODE_CHILD_PARENT);
254
        sourceModeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_CHILD_PARENT);
255
        comboSourceModeChildParent = new Combo(control,  SWT.BORDER| SWT.READ_ONLY);
256
        comboSourceModeChildParent.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
257

    
258
        for (AggregationSourceMode mode :AggregationSourceMode.values()){
259
            comboSourceModeChildParent.add(mode.getMessage());
260
            comboSourceModeChildParent.setData(mode.getMessage(), mode);
261

    
262
        }
263

    
264

    
265
        comboSourceModeChildParent.setEnabled(false);
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());
273

    
274

    
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);
294
    }
295

    
296
    @Override
297
    public void handleEvent(Event event) {
298
        if (event.widget.equals(comboHigherRank)){
299
            updateLowerRankCombo();
300
        }
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
    }
316

    
317
    public List<TaxonNode> getSelectedTaxonNodes(){
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
    }
327

    
328

    
329
}
(10-10/10)