Project

General

Profile

Download (8.02 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.lang3.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.filter.LogicFilter;
29
import eu.etaxonomy.cdm.model.name.Rank;
30
import eu.etaxonomy.cdm.model.name.TaxonName;
31
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

    
35
/**
36
 * @author k.luther
37
 * @since 13.12.2019
38
 */
39
public abstract class AggregationConfigurationWizardPage<T extends DescriptionAggregationBase<T,S>,
40
            S extends DescriptionAggregationConfigurationBase<T>>
41
            extends WizardPage {
42

    
43
    protected S configurator;
44

    
45
    protected Button checkUseSelectedTaxonNode;
46
    protected Button checkUseHigherLevel;
47
    protected Button checkUseSelectedSubtree;
48

    
49
    protected Combo comboHigherRank;
50
    protected Combo comboLowerRank;
51

    
52
    protected Combo comboSourceModeChildParent;
53
    protected Combo comboSourceModeWithinTaxon;
54

    
55
    protected CheckboxTableViewer aggregationModeViewer;
56
    protected TaxonNode subTreeNode;
57

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

    
61
    protected Button checkIncludeUnpublishedTaxa;
62

    
63
    private Comparator<Rank> comparator = new Comparator<Rank>(){
64
        @Override
65
        public int compare(Rank o1, Rank o2) {
66
            return o2.compareTo(o1);
67
        }
68
    };
69

    
70
    protected AggregationConfigurationWizardPage(String pageName) {
71
        super(pageName);
72
        // TODO Auto-generated constructor stub
73
    }
74

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

    
103
        rankList.sort(comparator);
104
        for (Rank rank: rankList){
105
            comboHigherRank.add(rank.getLabel());
106
            comboHigherRank.setData(rank.getLabel(), rank);
107
        }
108
        int i = 1;
109
        if (item != null){
110
        	for (String itemString: comboHigherRank.getItems()){
111
        		if (itemString.equals(item)){
112
        			comboHigherRank.select(i);
113
        			break;
114
        		}
115
        		i++;
116
        	}
117
        }
118
        
119
    }
120

    
121
   protected void updateLowerRankCombo() {
122
	   int index = comboLowerRank.getSelectionIndex();
123
	   String item = null;
124
	   if (index > 0){
125
		   item = comboLowerRank.getItem(index);
126
	   }
127
       comboLowerRank.removeAll();
128
       TaxonName name = null;
129
       List<Rank> rankList = new ArrayList<>();
130
       if (subTreeNode != null){
131
           if (subTreeNode.getTaxon() != null){
132
               name = subTreeNode.getTaxon().getName();
133
           }
134
       }
135
       comboLowerRank.add(""); //$NON-NLS-1$
136
       Rank higherRank = null;
137
       if (comboHigherRank.getText() != null && comboHigherRank.getData(comboHigherRank.getText()) != null){
138
           higherRank = (Rank)comboHigherRank.getData(comboHigherRank.getText());
139
       }
140
       for (Rank rank: CdmStore.getTermManager().getPreferredTerms(Rank.class)){
141
           if (higherRank != null){
142
               if (higherRank.isHigher(rank) || higherRank.equals(rank)){
143
                   rankList.add(rank);
144
               }
145
           } else if (name == null || (name.getRank().isHigher(rank) || name.getRank().equals(rank))) {
146
               rankList.add(rank);
147
           }
148
       }
149
       rankList.sort(comparator);
150
       for (Rank rank: rankList){
151
    	   comboLowerRank.add(rank.getLabel());
152
    	   comboLowerRank.setData(rank.getLabel(), rank);
153
       }
154
       int i = 0;
155
       if (item != null){
156
       	for (String itemString: comboLowerRank.getItems()){
157
       		if (itemString.equals(item)){
158
       			comboLowerRank.select(i);
159
       			break;
160
       		}
161
       		i++;
162
       	}
163
       }
164
   }
165

    
166
   public Rank getHigherRank(){
167
       if (StringUtils.isNotBlank(comboHigherRank.getText())){
168
           return (Rank)comboHigherRank.getData(comboHigherRank.getText());
169
       }
170
       return null;
171
   }
172

    
173
   public Rank getLowerRank(){
174
       if (StringUtils.isNotBlank(comboLowerRank.getText())){
175
           return (Rank)comboLowerRank.getData(comboLowerRank.getText());
176
       }
177
       return null;
178
   }
179

    
180
   public boolean useHigherLevel(){
181
       return checkUseHigherLevel.getSelection();
182
   }
183

    
184
   public boolean useSubtree(){
185
       return checkUseSelectedSubtree.getSelection();
186
   }
187

    
188
   public boolean useTaxonNode(){
189
       return checkUseSelectedTaxonNode.getSelection();
190
   }
191

    
192
   public AggregationSourceMode getSourceModeChildParent(){
193
       if (StringUtils.isNotBlank(comboSourceModeChildParent.getText())){
194
           return (AggregationSourceMode)comboSourceModeChildParent.getData(comboSourceModeChildParent.getText());
195
       }
196
       return null;
197
   }
198

    
199
   public AggregationSourceMode getSourceModeWithinTaxon(){
200
       if (StringUtils.isNotBlank(comboSourceModeWithinTaxon.getText())){
201
           return (AggregationSourceMode)comboSourceModeWithinTaxon.getData(comboSourceModeWithinTaxon.getText());
202

    
203
       }
204
       return null;
205
   }
206

    
207
   public EnumSet<OriginalSourceType> getSourceTypes(){
208
       List<OriginalSourceType> list = new ArrayList<>();
209
       if (sourceTypeViewer == null) return null;
210
       for (Object o: sourceTypeViewer.getCheckedElements()){
211
           String string = null;
212
           if (o instanceof String){
213
               string = (String)o;
214
           }
215
           if (string != null){
216
               list.add(typeMap.get(string));
217
           }
218
       }
219

    
220
       return EnumSet.copyOf(list);
221
   }
222

    
223

    
224
   public List<AggregationMode> getAggregationMode(){
225

    
226
       List<AggregationMode> result = new ArrayList<>();
227
       for (Object mode: aggregationModeViewer.getCheckedElements()){
228
           if (mode instanceof AggregationMode){
229
               result.add((AggregationMode)mode);
230
           }
231
       }
232
       return result;
233
   }
234
   
235
   protected void setConfigValueToRankCombo(Combo rankCombo) {
236
		int index = 0;
237
       if (configurator.getTaxonNodeFilter().getRankMax() == null){
238
       	rankCombo.select(index);
239
       }else{        
240
	        Rank rank = null;
241
	        for (String item: rankCombo.getItems()){
242
	        	if (rankCombo.getData(item) instanceof Rank){
243
	        		rank = (Rank) rankCombo.getData(item);
244
	        		if (rank.getUuid().equals(configurator.getTaxonNodeFilter().getRankMax().getUuid())){
245
	        			rankCombo.select(index);
246
	        			break;
247
	        		}
248
	        	}
249
	        	index++;
250
	        }
251
       }
252
	}
253

    
254
}
(1-1/10)