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
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
16
|
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
17
|
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
18
|
import org.eclipse.jface.viewers.ICheckStateListener;
|
19
|
import org.eclipse.jface.viewers.LabelProvider;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.layout.GridData;
|
22
|
import org.eclipse.swt.layout.GridLayout;
|
23
|
import org.eclipse.swt.widgets.Button;
|
24
|
import org.eclipse.swt.widgets.Combo;
|
25
|
import org.eclipse.swt.widgets.Composite;
|
26
|
import org.eclipse.swt.widgets.Event;
|
27
|
import org.eclipse.swt.widgets.Label;
|
28
|
import org.eclipse.swt.widgets.Listener;
|
29
|
|
30
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
31
|
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
|
32
|
import eu.etaxonomy.cdm.api.service.description.AggregationSourceMode;
|
33
|
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregation;
|
34
|
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
|
35
|
import eu.etaxonomy.cdm.filter.LogicFilter;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
37
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
38
|
|
39
|
/**
|
40
|
* @author k.luther
|
41
|
* @since 11.12.2019
|
42
|
*/
|
43
|
public class StructuredDescriptionAggregationConfigurationWizardPage extends AggregationConfigurationWizardPage<StructuredDescriptionAggregation> {
|
44
|
|
45
|
|
46
|
/**
|
47
|
* @param pageName
|
48
|
*/
|
49
|
protected StructuredDescriptionAggregationConfigurationWizardPage(StructuredDescriptionAggregationConfiguration configurator) {
|
50
|
super(Messages.DistributionAggregationWizardPage_TITLE);
|
51
|
this.configurator = configurator;
|
52
|
|
53
|
this.setDescription(Messages.DistributionAggregationWizardPage_DESCRIPTION);
|
54
|
}
|
55
|
|
56
|
|
57
|
|
58
|
|
59
|
@Override
|
60
|
public void createControl(Composite parent) {
|
61
|
final Composite composite = new Composite(parent, SWT.NULL);
|
62
|
|
63
|
//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$
|
74
|
}
|
75
|
}
|
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();
|
93
|
}
|
94
|
|
95
|
|
96
|
});
|
97
|
}
|
98
|
|
99
|
//use taxonnode filter of the descriptive data set
|
100
|
checkUseHigherLevel = new Button(composite, SWT.RADIO);
|
101
|
checkUseHigherLevel.setText(Messages.DistributionAggregationWizardPage_CLASSIFICATION);
|
102
|
checkUseHigherLevel.addListener(SWT.Selection, new Listener() {
|
103
|
@Override
|
104
|
public void handleEvent(Event e) {
|
105
|
updateHigherRankCombo();
|
106
|
}
|
107
|
});
|
108
|
|
109
|
|
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));
|
115
|
|
116
|
Label aggregationModeLabel = new Label(control, SWT.NULL);
|
117
|
aggregationModeLabel.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
|
118
|
aggregationModeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_AGGR_MODE);
|
119
|
aggregationModeViewer = CheckboxTableViewer.newCheckList(control, SWT.BORDER | SWT.SINGLE);
|
120
|
aggregationModeViewer.setContentProvider(new ArrayContentProvider());
|
121
|
aggregationModeViewer.setLabelProvider(new LabelProvider(){
|
122
|
@Override
|
123
|
public String getText(Object element){
|
124
|
if (element instanceof AggregationMode){
|
125
|
return ((AggregationMode)element).getMessage();
|
126
|
}
|
127
|
return null;
|
128
|
}
|
129
|
|
130
|
});
|
131
|
List<AggregationMode> aggregationModeList = new ArrayList<>();
|
132
|
for (AggregationMode mode: AggregationMode.values()){
|
133
|
aggregationModeList.add(mode);
|
134
|
}
|
135
|
|
136
|
aggregationModeViewer.setInput(aggregationModeList);
|
137
|
|
138
|
aggregationModeViewer.addCheckStateListener(new ICheckStateListener(){
|
139
|
@Override
|
140
|
public void checkStateChanged( CheckStateChangedEvent event){
|
141
|
Object[] checked =aggregationModeViewer.getCheckedElements();
|
142
|
boolean withinChecked = false;
|
143
|
boolean toParentChecked = false;
|
144
|
for (int i = 0; i<checked.length;i++){
|
145
|
if (checked[i] instanceof AggregationMode){
|
146
|
if (((AggregationMode)checked[i]).equals(AggregationMode.WithinTaxon)){
|
147
|
withinChecked = true;
|
148
|
}
|
149
|
if (((AggregationMode)checked[i]).equals(AggregationMode.ToParent)){
|
150
|
toParentChecked = true;
|
151
|
}
|
152
|
}
|
153
|
}
|
154
|
|
155
|
comboSourceModeChildParent.setEnabled(toParentChecked);
|
156
|
comboSourceModeWithinTaxon.setEnabled(withinChecked);
|
157
|
// AggregationSourceMode areaMode = (AggregationSourceMode)comboSourceModeSubAreaSuperArea.getData(comboSourceModeSubAreaSuperArea.getText());
|
158
|
AggregationSourceMode taxonMode = (AggregationSourceMode)comboSourceModeChildParent.getData(comboSourceModeChildParent.getText());
|
159
|
// getSourceTypeViewer().getTable().setEnabled(((areachecked && (areaMode.equals(AggregationSourceMode.ALL) || areaMode.equals(AggregationSourceMode.ALL_SAMEVALUE) ) )|| toParentChecked && (taxonMode.equals(AggregationSourceMode.ALL) || taxonMode.equals(AggregationSourceMode.ALL_SAMEVALUE) )) );
|
160
|
getWizard().getContainer().updateButtons();
|
161
|
}
|
162
|
});
|
163
|
|
164
|
Label sourceModeLabelWithin = new Label(control, SWT.NULL);
|
165
|
|
166
|
sourceModeLabelWithin.setText(Messages.DistributionAggregationWizardPage_SOURCEMODE_WITHIN_TAXON);
|
167
|
sourceModeLabelWithin.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_WITHIN_TAXON);
|
168
|
comboSourceModeWithinTaxon = new Combo(control, SWT.BORDER| SWT.READ_ONLY);
|
169
|
comboSourceModeWithinTaxon.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
|
170
|
|
171
|
for (AggregationSourceMode mode :AggregationSourceMode.values()){
|
172
|
comboSourceModeWithinTaxon.add(mode.getMessage());
|
173
|
comboSourceModeWithinTaxon.setData(mode.getMessage(), mode);
|
174
|
|
175
|
}
|
176
|
|
177
|
|
178
|
comboSourceModeWithinTaxon.setEnabled(false);
|
179
|
comboSourceModeWithinTaxon.select(0);
|
180
|
|
181
|
Label sourceModeLabel = new Label(control, SWT.NULL);
|
182
|
|
183
|
sourceModeLabel.setText(Messages.DistributionAggregationWizardPage_SOURCEMODE_CHILD_PARENT);
|
184
|
sourceModeLabel.setToolTipText(Messages.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_CHILD_PARENT);
|
185
|
comboSourceModeChildParent = new Combo(control, SWT.BORDER| SWT.READ_ONLY);
|
186
|
comboSourceModeChildParent.setText(Messages.DistributionAggregationWizardPage_AGGREGATION_MODE);
|
187
|
|
188
|
for (AggregationSourceMode mode :AggregationSourceMode.values()){
|
189
|
comboSourceModeChildParent.add(mode.getMessage());
|
190
|
comboSourceModeChildParent.setData(mode.getMessage(), mode);
|
191
|
|
192
|
}
|
193
|
|
194
|
|
195
|
comboSourceModeChildParent.setEnabled(false);
|
196
|
comboSourceModeChildParent.select(0);
|
197
|
|
198
|
|
199
|
setControl(composite);
|
200
|
}
|
201
|
|
202
|
|
203
|
|
204
|
|
205
|
|
206
|
|
207
|
}
|