2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
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
;
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
.AggregationType
;
36 import eu
.etaxonomy
.cdm
.api
.service
.description
.StructuredDescriptionAggregation
;
37 import eu
.etaxonomy
.cdm
.api
.service
.description
.StructuredDescriptionAggregationConfiguration
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceType
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
40 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
41 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
42 import eu
.etaxonomy
.taxeditor
.ui
.combo
.OriginalSourceTypeComparator
;
48 public class StructuredDescriptionAggregationConfigurationWizardPage
extends AggregationConfigurationWizardPage
<StructuredDescriptionAggregation
> implements Listener
{
50 protected CheckboxTableViewer subTreeSelectionViewer
;
51 private List
<TaxonNodeDto
> selectedNodes
;
58 protected StructuredDescriptionAggregationConfigurationWizardPage(StructuredDescriptionAggregationConfiguration configurator
, List
<TaxonNodeDto
> nodes
) {
59 super(Messages
.DistributionAggregationWizardPage_TITLE
);
60 this.configurator
= configurator
;
61 this.setDescription(Messages
.DistributionAggregationWizardPage_DESCRIPTION
);
62 selectedNodes
= nodes
;
69 public void createControl(Composite parent
) {
70 final Composite control
= new Composite(parent
, SWT
.NULL
);
71 GridLayout gridLayoutControl
= new GridLayout();
72 gridLayoutControl
.numColumns
= 2;
73 control
.setLayout(gridLayoutControl
);
74 control
.setLayoutData(new GridData(SWT
.FILL
, SWT
.LEFT
, true, true));
76 //select between taxonnode filter for the whole descriptive dataset or the selected taxonnode/subtree
77 GridData gridDataRadioComposite
= new GridData();
78 gridDataRadioComposite
.horizontalSpan
= 2;
79 GridLayout gridLayoutRadioComposite
= new GridLayout();
80 gridLayoutRadioComposite
.numColumns
= 1;
81 Composite radioComposite
= new Composite(control
, SWT
.NULL
);
82 radioComposite
.setLayoutData(gridDataRadioComposite
);
83 radioComposite
.setLayout(gridLayoutRadioComposite
);
85 checkUseSelectedSubtree
= new Button(radioComposite
, SWT
.RADIO
);
86 checkUseSelectedSubtree
.setText(Messages
.AggregationWizardPage_SUBTREE
);
87 checkUseSelectedSubtree
.addListener(SWT
.Selection
, new Listener() {
89 public void handleEvent(Event e
) {
90 subTreeSelectionViewer
.getTable().setEnabled(checkUseSelectedSubtree
.getSelection());
91 if (checkUseSelectedSubtree
.getSelection() && subTreeSelectionViewer
.getCheckedElements().length
== 0){
92 setPageComplete(false);
94 setPageComplete(true);
99 checkUseSelectedTaxonNode
= new Button(radioComposite
, SWT
.RADIO
);
100 checkUseSelectedTaxonNode
.setText(Messages
.StructuredDescriptionAggregationWizardPage_SELECT_SELECTED_TAXA_ONLY
);
101 checkUseSelectedTaxonNode
.addListener(SWT
.Selection
, new Listener() {
103 public void handleEvent(Event e
) {
104 subTreeSelectionViewer
.getTable().setEnabled(checkUseSelectedTaxonNode
.getSelection());
105 if (checkUseSelectedTaxonNode
.getSelection() && subTreeSelectionViewer
.getCheckedElements().length
== 0){
106 setPageComplete(false);
108 setPageComplete(true);
115 // configurator.getTaxonNodeFilter().getSubtreeFilter().stream().forEach(p ->uuidList.add(p.getUuid()));
116 // List<String> propertyPaths = new ArrayList<>();
117 // propertyPaths.add("taxon.name");
118 // List<TaxonNode> nodeList = CdmApplicationState.getCurrentAppConfig().getTaxonNodeService().load(uuidList, propertyPaths);
120 Label selectSubtreeLabel
= new Label(control
, SWT
.NULL
);
121 selectSubtreeLabel
.setText(Messages
.StructuredDescriptionAggregationWizardPage_SELECT_SUBTREE
);
122 selectSubtreeLabel
.setToolTipText(Messages
.StructuredDescriptionAggregationWizardPage_TOOLTIP_SELECT_SUBTREE
);
123 subTreeSelectionViewer
= CheckboxTableViewer
.newCheckList(control
, SWT
.BORDER
| SWT
.SINGLE
);
125 subTreeSelectionViewer
.setContentProvider(new ArrayContentProvider());
128 subTreeSelectionViewer
.setLabelProvider(new LabelProvider(){
130 public String
getText(Object element
){
131 if (element
instanceof TaxonNodeDto
){
132 return ((TaxonNodeDto
)element
).getNameTitleCache();
133 }else if (element
instanceof TaxonNode
){
134 return ((TaxonNode
)element
).getTaxon().getName().getTitleCache();
144 if (selectedNodes
== null || selectedNodes
.isEmpty()){
145 List
<TaxonNode
> nodeList
;
146 List
<UUID
> uuidList
= new ArrayList
<>();
147 configurator
.getTaxonNodeFilter().getSubtreeFilter().stream().forEach(p
->uuidList
.add(p
.getUuid()));
148 List
<String
> propertyPaths
= new ArrayList
<>();
149 propertyPaths
.add("taxon.name");
150 nodeList
= CdmApplicationState
.getCurrentAppConfig().getTaxonNodeService().load(uuidList
, propertyPaths
);
152 subTreeSelectionViewer
.setInput(nodeList
);
155 subTreeSelectionViewer
.setInput(selectedNodes
);
157 subTreeSelectionViewer
.setAllChecked(true);
158 subTreeSelectionViewer
.addCheckStateListener(new ICheckStateListener(){
160 public void checkStateChanged( CheckStateChangedEvent event
){
161 Object
[] checked
=subTreeSelectionViewer
.getCheckedElements();
162 if (checked
.length
== 0){
163 setPageComplete(false);
165 setPageComplete(true);
171 //use taxonnode filter of the descriptive data set
172 checkUseHigherLevel
= new Button(radioComposite
, SWT
.RADIO
);
173 checkUseHigherLevel
.setText(Messages
.StructuredDescriptionAggregationWizardPage_SELECT_ALL_SUBTREES
);
174 checkUseHigherLevel
.addListener(SWT
.Selection
, new Listener() {
176 public void handleEvent(Event e
) {
177 subTreeSelectionViewer
.getTable().setEnabled(!checkUseHigherLevel
.getSelection());
178 updateHigherRankCombo();
179 if (checkUseHigherLevel
.getSelection()){
180 setPageComplete(true);
188 GridLayoutFactory
.fillDefaults();
190 Label higherRankLabel
= new Label(control
, SWT
.NULL
);
191 higherRankLabel
.setText(Messages
.DistributionAggregationWizardPage_HIGHEST_RANK
);
193 comboHigherRank
= new Combo(control
, SWT
.BORDER
| SWT
.READ_ONLY
);
194 updateHigherRankCombo();
195 comboHigherRank
.addListener(SWT
.Selection
, this);
198 Label lowerRankLabel
= new Label(control
, SWT
.NULL
);
199 lowerRankLabel
.setText(Messages
.DistributionAggregationWizardPage_LOWEST_RANK
);
200 comboLowerRank
= new Combo(control
, SWT
.BORDER
| SWT
.READ_ONLY
);
201 updateLowerRankCombo();
202 comboLowerRank
.addListener(SWT
.Selection
, this);
204 Label aggregationModeLabel
= new Label(control
, SWT
.NULL
);
205 aggregationModeLabel
.setText(Messages
.DistributionAggregationWizardPage_AGGREGATION_MODE
);
206 aggregationModeLabel
.setToolTipText(Messages
.DistributionAggregationWizardPage_TOOLTIP_AGGR_MODE
);
207 aggregationModeViewer
= CheckboxTableViewer
.newCheckList(control
, SWT
.BORDER
| SWT
.SINGLE
);
208 aggregationModeViewer
.setContentProvider(new ArrayContentProvider());
209 aggregationModeViewer
.setLabelProvider(new LabelProvider(){
211 public String
getText(Object element
){
212 if (element
instanceof AggregationMode
){
213 return ((AggregationMode
)element
).getLabel();
219 List
<AggregationMode
> aggregationModeList
= new ArrayList
<>();
220 for (AggregationMode mode
: AggregationMode
.values()){
221 aggregationModeList
.add(mode
);
224 aggregationModeViewer
.setInput(aggregationModeList
);
226 aggregationModeViewer
.addCheckStateListener(new ICheckStateListener(){
228 public void checkStateChanged( CheckStateChangedEvent event
){
229 Object
[] checked
=aggregationModeViewer
.getCheckedElements();
230 boolean withinChecked
= false;
231 boolean toParentChecked
= false;
232 for (int i
= 0; i
<checked
.length
;i
++){
233 if (checked
[i
] instanceof AggregationMode
){
234 if (((AggregationMode
)checked
[i
]).equals(AggregationMode
.WithinTaxon
)){
235 withinChecked
= true;
237 if (((AggregationMode
)checked
[i
]).equals(AggregationMode
.ToParent
)){
238 toParentChecked
= true;
243 comboSourceModeChildParent
.setEnabled(toParentChecked
);
244 comboSourceModeWithinTaxon
.setEnabled(withinChecked
);
245 // AggregationSourceMode areaMode = (AggregationSourceMode)comboSourceModeSubAreaSuperArea.getData(comboSourceModeSubAreaSuperArea.getText());
246 AggregationSourceMode taxonMode
= (AggregationSourceMode
)comboSourceModeChildParent
.getData(comboSourceModeChildParent
.getText());
247 // getSourceTypeViewer().getTable().setEnabled(((areachecked && (areaMode.equals(AggregationSourceMode.ALL) || areaMode.equals(AggregationSourceMode.ALL_SAMEVALUE) ) )|| toParentChecked && (taxonMode.equals(AggregationSourceMode.ALL) || taxonMode.equals(AggregationSourceMode.ALL_SAMEVALUE) )) );
248 getWizard().getContainer().updateButtons();
252 Label sourceModeLabelWithin
= new Label(control
, SWT
.NULL
);
254 sourceModeLabelWithin
.setText(Messages
.DistributionAggregationWizardPage_SOURCEMODE_WITHIN_TAXON
);
255 sourceModeLabelWithin
.setToolTipText(Messages
.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_WITHIN_TAXON
);
256 comboSourceModeWithinTaxon
= new Combo(control
, SWT
.BORDER
| SWT
.READ_ONLY
);
257 comboSourceModeWithinTaxon
.setText(Messages
.DistributionAggregationWizardPage_AGGREGATION_MODE
);
259 for (AggregationSourceMode mode
:AggregationSourceMode
.list(AggregationMode
.WithinTaxon
, AggregationType
.StructuredDescription
) ){
260 comboSourceModeWithinTaxon
.add(mode
.getLabel());
261 comboSourceModeWithinTaxon
.setData(mode
.getLabel(), mode
);
266 comboSourceModeWithinTaxon
.setEnabled(false);
267 comboSourceModeWithinTaxon
.select(0);
268 comboSourceModeWithinTaxon
.addListener(SWT
.Selection
, this);
269 Label sourceModeLabel
= new Label(control
, SWT
.NULL
);
271 sourceModeLabel
.setText(Messages
.DistributionAggregationWizardPage_SOURCEMODE_CHILD_PARENT
);
272 sourceModeLabel
.setToolTipText(Messages
.DistributionAggregationWizardPage_TOOLTIP_SOURCEMODE_CHILD_PARENT
);
273 comboSourceModeChildParent
= new Combo(control
, SWT
.BORDER
| SWT
.READ_ONLY
);
274 comboSourceModeChildParent
.setText(Messages
.DistributionAggregationWizardPage_AGGREGATION_MODE
);
276 for (AggregationSourceMode mode
:AggregationSourceMode
.list(AggregationMode
.ToParent
, AggregationType
.StructuredDescription
) ){
277 comboSourceModeChildParent
.add(mode
.getLabel());
278 comboSourceModeChildParent
.setData(mode
.getLabel(), mode
);
283 comboSourceModeChildParent
.setEnabled(false);
284 comboSourceModeChildParent
.select(0);
285 comboSourceModeChildParent
.addListener(SWT
.Selection
, this);
286 GridLayoutFactory
.fillDefaults();
287 Label sourceTypeLabel
= new Label(control
, SWT
.NULL
);
288 sourceTypeLabel
.setText(Messages
.DistributionAggregationWizardPage_SOURCE_TYPE
);
289 sourceTypeLabel
.setToolTipText(Messages
.DistributionAggregationWizardPage_TOOLTIP_SOURCE_TYPE
);
290 sourceTypeViewer
= CheckboxTableViewer
.newCheckList(control
, SWT
.BORDER
| SWT
.SINGLE
);
291 sourceTypeViewer
.setContentProvider(new ArrayContentProvider());
294 sourceTypeViewer
.addCheckStateListener(new ICheckStateListener(){
296 public void checkStateChanged( CheckStateChangedEvent event
){
297 // checkedElements=sourceTypeViewer.getCheckedElements();
298 getWizard().getContainer().updateButtons();
302 List
<String
> typeStrings
= new ArrayList
<>();
303 OriginalSourceType
[] typeArray
= OriginalSourceType
.values();
304 Arrays
.sort(typeArray
, new OriginalSourceTypeComparator(null));
305 Arrays
.stream(typeArray
).forEach(p
->typeMap
.put(p
.getLabel(), p
));
306 Arrays
.stream(typeArray
).forEach(p
->typeStrings
.add(p
.getLabel()));
307 typeStrings
.remove(OriginalSourceType
.NomenclaturalReference
.getLabel());
308 sourceTypeViewer
.setInput(typeStrings
);
309 sourceTypeViewer
.setChecked(OriginalSourceType
.PrimaryMediaSource
.getLabel(), true);
310 sourceTypeViewer
.setChecked(OriginalSourceType
.PrimaryTaxonomicSource
.getLabel(), true);
311 sourceTypeViewer
.getTable().setEnabled(false);
316 public void handleEvent(Event event
) {
317 if (event
.widget
.equals(comboHigherRank
)){
318 updateLowerRankCombo();
321 if (event
.widget
.equals(this.checkUseHigherLevel
)){
322 updateHigherRankCombo();
323 updateLowerRankCombo();
325 if (event
.widget
.equals(this.checkUseSelectedSubtree
)){
326 updateHigherRankCombo();
327 updateLowerRankCombo();
329 if (event
.widget
.equals(this.checkUseSelectedTaxonNode
)){
330 updateHigherRankCombo();
331 updateLowerRankCombo();
334 if (event
.widget
.equals(this.comboSourceModeChildParent
) || event
.widget
.equals(this.comboSourceModeWithinTaxon
)){
335 if (getSourceModeChildParent().equals(AggregationSourceMode
.NONE
) && getSourceModeWithinTaxon().equals(AggregationSourceMode
.NONE
)){
336 sourceTypeViewer
.getTable().setEnabled(false);
338 sourceTypeViewer
.getTable().setEnabled(true);
344 public List
<TaxonNode
> getSelectedTaxonNodes(){
346 List
<TaxonNode
> result
= new ArrayList
<>();
347 for (Object o
: subTreeSelectionViewer
.getCheckedElements()){
348 if (o
instanceof TaxonNode
){
349 result
.add((TaxonNode
)o
);