Project

General

Profile

Download (6.45 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.Comparator;
13
import java.util.EnumSet;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17

    
18
import org.apache.commons.lang.StringUtils;
19
import org.eclipse.jface.viewers.CheckboxTableViewer;
20
import org.eclipse.jface.wizard.WizardPage;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Combo;
23

    
24
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
25
import eu.etaxonomy.cdm.api.service.description.AggregationSourceMode;
26
import eu.etaxonomy.cdm.api.service.description.DescriptionAggregationBase;
27
import eu.etaxonomy.cdm.api.service.description.DescriptionAggregationConfigurationBase;
28
import eu.etaxonomy.cdm.model.name.Rank;
29
import eu.etaxonomy.cdm.model.name.TaxonName;
30
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
31
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33

    
34
/**
35
 * @author k.luther
36
 * @since 13.12.2019
37
 */
38
public abstract class AggregationConfigurationWizardPage<T extends DescriptionAggregationBase> extends WizardPage {
39

    
40
    protected DescriptionAggregationConfigurationBase<T> configurator;
41

    
42
    protected Button checkUseSelectedTaxonNode;
43
    protected Button checkUseHigherLevel;
44
    protected Button checkUseSelectedSubtree;
45

    
46

    
47
    protected Combo comboHigherRank;
48
    protected Combo comboLowerRank;
49

    
50
    protected Combo comboSourceModeChildParent;
51
    protected Combo comboSourceModeWithinTaxon;
52

    
53
    protected CheckboxTableViewer aggregationModeViewer;
54
    protected TaxonNode subTreeNode;
55

    
56
    protected CheckboxTableViewer sourceTypeViewer;
57
    Map<String, OriginalSourceType> typeMap = new HashMap();
58

    
59

    
60
    Comparator comparator = new Comparator<Rank>(){
61

    
62
        @Override
63
        public int compare(Rank o1, Rank o2) {
64
            return o2.compareTo(o1);
65
        }
66

    
67
    };
68

    
69
    /**
70
     * @param pageName
71
     */
72
    protected AggregationConfigurationWizardPage(String pageName) {
73
        super(pageName);
74
        // TODO Auto-generated constructor stub
75
    }
76

    
77

    
78

    
79
    protected void updateHigherRankCombo() {
80
        comboHigherRank.removeAll();
81
        List<Rank> rankList = new ArrayList<>();
82
        TaxonName name = null;
83
        if (subTreeNode != null){
84
            if (subTreeNode.getTaxon() != null){
85
                name = subTreeNode.getTaxon().getName();
86
            }
87
        }
88
        comboHigherRank.add(""); //$NON-NLS-1$
89
        if (name != null){
90
            for (Rank rank: CdmStore.getTermManager().getPreferredTerms(Rank.class)){
91
                if (useHigherLevel() || (name != null && name.getRank().isHigher(rank) || name.getRank().equals(rank))){
92
                    rankList.add(rank);
93
                }
94
            }
95
        }else{
96
            for (Rank rank: CdmStore.getTermManager().getPreferredTerms(Rank.class)){
97
                rankList.add(rank);
98
            }
99
        }
100

    
101
        rankList.sort(comparator);
102
        for (Rank rank: rankList){
103
            comboHigherRank.add(rank.getLabel());
104
            comboHigherRank.setData(rank.getLabel(), rank);
105
        }
106

    
107

    
108
    }
109

    
110

    
111
   protected void updateLowerRankCombo() {
112
       comboLowerRank.removeAll();
113
       TaxonName name = null;
114
       List<Rank> rankList = new ArrayList<>();
115
       if (subTreeNode != null){
116
           if (subTreeNode.getTaxon() != null){
117
               name = subTreeNode.getTaxon().getName();
118
           }
119
       }
120
       comboLowerRank.add(""); //$NON-NLS-1$
121
       Rank higherRank = null;
122
       if (comboHigherRank.getText() != null && comboHigherRank.getData(comboHigherRank.getText()) != null){
123
           higherRank = (Rank)comboHigherRank.getData(comboHigherRank.getText());
124
       }
125
       for (Rank rank: CdmStore.getTermManager().getPreferredTerms(Rank.class)){
126
           if (higherRank != null){
127
               if (higherRank.isHigher(rank) || higherRank.equals(rank)){
128
                   rankList.add(rank);
129
               }
130
           } else if (name == null || (name.getRank().isHigher(rank) || name.getRank().equals(rank))) {
131
               rankList.add(rank);
132
           }
133
       }
134
       rankList.sort(comparator);
135
       for (Rank rank: rankList){
136
           comboLowerRank.add(rank.getLabel());
137
           comboLowerRank.setData(rank.getLabel(), rank);
138
       }
139

    
140
   }
141

    
142
   public Rank getHigherRank(){
143
       if (StringUtils.isNotBlank(comboHigherRank.getText())){
144
           return (Rank)comboHigherRank.getData(comboHigherRank.getText());
145
       }
146
       return null;
147
   }
148

    
149
   public Rank getLowerRank(){
150
       if (StringUtils.isNotBlank(comboLowerRank.getText())){
151
           return (Rank)comboLowerRank.getData(comboLowerRank.getText());
152
       }
153
       return null;
154
   }
155

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

    
160
   public boolean useSubtree(){
161
       return checkUseSelectedSubtree.getSelection();
162
   }
163

    
164
   public boolean useTaxonNode(){
165
       return checkUseSelectedTaxonNode.getSelection();
166
   }
167

    
168
   public AggregationSourceMode getSourceModeChildParent(){
169
       if (StringUtils.isNotBlank(comboSourceModeChildParent.getText())){
170
           return (AggregationSourceMode)comboSourceModeChildParent.getData(comboSourceModeChildParent.getText());
171
       }
172
       return null;
173
   }
174

    
175
   public AggregationSourceMode getSourceModeWithinTaxon(){
176
       if (StringUtils.isNotBlank(comboSourceModeWithinTaxon.getText())){
177
           return (AggregationSourceMode)comboSourceModeWithinTaxon.getData(comboSourceModeWithinTaxon.getText());
178

    
179
       }
180
       return null;
181
   }
182

    
183
   public EnumSet<OriginalSourceType> getSourceTypes(){
184
       List<OriginalSourceType> list = new ArrayList<>();
185
       for (Object o: sourceTypeViewer.getCheckedElements()){
186
           String string = null;
187
           if (o instanceof String){
188
               string = (String)o;
189
           }
190
           if (string != null){
191
               list.add(typeMap.get(string));
192
           }
193
       }
194

    
195
       return EnumSet.copyOf(list);
196
   }
197

    
198

    
199
   public List<AggregationMode> getAggregationMode(){
200

    
201
       List<AggregationMode> result = new ArrayList<>();
202
       for (Object o: aggregationModeViewer.getCheckedElements()){
203
           if (o instanceof AggregationMode){
204
               result.add((AggregationMode)o);
205
           }
206
       }
207
       return result;
208
   }
209

    
210
}
(1-1/10)