1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.ui.dialog.selection;
|
5
|
|
6
|
import java.util.Collections;
|
7
|
import java.util.Comparator;
|
8
|
import java.util.List;
|
9
|
import java.util.Set;
|
10
|
import java.util.UUID;
|
11
|
|
12
|
import org.eclipse.jface.viewers.ILabelProvider;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.events.SelectionAdapter;
|
15
|
import org.eclipse.swt.events.SelectionEvent;
|
16
|
import org.eclipse.swt.events.SelectionListener;
|
17
|
import org.eclipse.swt.layout.GridData;
|
18
|
import org.eclipse.swt.layout.GridLayout;
|
19
|
import org.eclipse.swt.widgets.Combo;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
import org.eclipse.swt.widgets.Control;
|
22
|
import org.eclipse.swt.widgets.Label;
|
23
|
import org.eclipse.swt.widgets.Shell;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
26
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
29
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
30
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* @author p.ciardelli
|
36
|
* @version $Id: $
|
37
|
*/
|
38
|
public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{
|
39
|
|
40
|
public static TaxonNode select(Shell shell, //ConversationHolder conversation,
|
41
|
String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID, boolean allowSelectClassification) {
|
42
|
TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
|
43
|
//conversation,
|
44
|
title,
|
45
|
excludeTaxa,
|
46
|
false,
|
47
|
node,
|
48
|
classificationUUID, allowSelectClassification);
|
49
|
return getSelectionFromDialog(dialog);
|
50
|
}
|
51
|
public static TaxonNode select(Shell shell, //ConversationHolder conversation,
|
52
|
String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
|
53
|
TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
|
54
|
//conversation,
|
55
|
title,
|
56
|
excludeTaxa,
|
57
|
false,
|
58
|
node,
|
59
|
classificationUUID);
|
60
|
return getSelectionFromDialog(dialog);
|
61
|
}
|
62
|
|
63
|
public static UuidAndTitleCache<TaxonNode> selectUuidAndTitleCache(Shell shell, //ConversationHolder conversation,
|
64
|
String title, Set<UUID> excludeTaxa, TaxonNode node, UUID classificationUUID) {
|
65
|
TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
|
66
|
//conversation,
|
67
|
title,
|
68
|
excludeTaxa,
|
69
|
false,
|
70
|
node,
|
71
|
classificationUUID, false);
|
72
|
return getUuidAndTitleCacheSelectionFromDialog(dialog);
|
73
|
}
|
74
|
|
75
|
private Combo classificationSelectionCombo;
|
76
|
|
77
|
private List<Classification> classifications;
|
78
|
|
79
|
private Classification selectedClassification;
|
80
|
private UUID selectedUuid;
|
81
|
// private final Set<UUID> excludeTaxa;
|
82
|
private boolean allowClassificationSelection = false;
|
83
|
|
84
|
protected TaxonNodeSelectionDialog(Shell shell, //ConversationHolder conversation,
|
85
|
String title, Set<UUID> excludeTaxa, boolean multi, TaxonNode node, UUID classificationUUID, boolean allowSelectClassification) {
|
86
|
super(shell, //conversation,
|
87
|
title, multi, TaxonNodeSelectionDialog.class.getCanonicalName(), node);
|
88
|
|
89
|
ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
|
90
|
|
91
|
setListLabelProvider(labelProvider);
|
92
|
// setDetailsLabelProvider(labelProvider);
|
93
|
this.cdmBaseToBeFiltered = excludeTaxa;
|
94
|
if(classificationUUID != null){
|
95
|
selectedUuid = classificationUUID;
|
96
|
}
|
97
|
|
98
|
fillClassifications();
|
99
|
this.allowClassificationSelection = allowSelectClassification;
|
100
|
|
101
|
//createClassificationSelectionCombo(shell);
|
102
|
}
|
103
|
protected TaxonNodeSelectionDialog(Shell shell, //ConversationHolder conversation,
|
104
|
String title, Set<UUID> excludeTaxa, boolean multi, TaxonNode node, UUID classificationUUID) {
|
105
|
this(shell, title, excludeTaxa, multi, node, classificationUUID, false);
|
106
|
}
|
107
|
|
108
|
/** {@inheritDoc} */
|
109
|
@Override
|
110
|
protected Control createDialogArea(Composite parent) {
|
111
|
Composite container = (Composite) super.createDialogArea(parent);
|
112
|
return createClassificationSelectionCombo(container);
|
113
|
}
|
114
|
|
115
|
/*
|
116
|
* currently disabled tree selection composite
|
117
|
*/
|
118
|
private Control createClassificationSelectionCombo(Composite parent){
|
119
|
// classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
|
120
|
|
121
|
Composite classificationSelection = new Composite(parent, SWT.NULL);
|
122
|
classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
|
123
|
|
124
|
GridLayout layout = new GridLayout();
|
125
|
classificationSelection.setLayout(layout);
|
126
|
|
127
|
Label label = new Label(classificationSelection, SWT.NULL);
|
128
|
// TODO not working is not really true but leave it here to remind everyone that this is under construction
|
129
|
label.setText("Select Classification");
|
130
|
classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
|
131
|
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
|
132
|
|
133
|
for(Classification tree : classifications){
|
134
|
classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
|
135
|
if (tree.getUuid().equals(selectedUuid)){
|
136
|
selectedClassification = tree;
|
137
|
}
|
138
|
|
139
|
}
|
140
|
|
141
|
classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
|
142
|
|
143
|
// TODO remember last selection
|
144
|
classificationSelectionCombo.addSelectionListener(this);
|
145
|
|
146
|
|
147
|
|
148
|
return classificationSelection;
|
149
|
}
|
150
|
|
151
|
/** {@inheritDoc} */
|
152
|
@Override
|
153
|
protected String getTitle(TaxonNode taxonNode) {
|
154
|
if(taxonNode != null && taxonNode.getTaxon() != null){
|
155
|
return taxonNode.getTaxon().getTitleCache();
|
156
|
}
|
157
|
|
158
|
return "";
|
159
|
}
|
160
|
|
161
|
@Override
|
162
|
protected SelectionListener getNewWizardButtonSelectionListener(){
|
163
|
return new SelectionAdapter() {
|
164
|
|
165
|
@Override
|
166
|
public void widgetSelected(SelectionEvent e) {
|
167
|
Classification tree = selectedClassification;
|
168
|
setPattern(tree.getRootNode());
|
169
|
|
170
|
}
|
171
|
};
|
172
|
}
|
173
|
|
174
|
|
175
|
/** {@inheritDoc} */
|
176
|
@Override
|
177
|
protected TaxonNode getPersistentObject(UUID uuid) {
|
178
|
return CdmStore.getService(ITaxonNodeService.class).find(uuid);
|
179
|
}
|
180
|
|
181
|
/** {@inheritDoc} */
|
182
|
@Override
|
183
|
protected void callService(String pattern) {
|
184
|
model = CdmStore.getService(IClassificationService.class)
|
185
|
.getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(
|
186
|
selectedClassification.getUuid(), limitOfInitialElements, pattern, allowClassificationSelection);
|
187
|
}
|
188
|
|
189
|
@Override
|
190
|
protected void sort() {
|
191
|
if(!PreferencesUtil.isSortTaxaByRankAndName()){
|
192
|
Collections.sort(model, getItemsComparator());
|
193
|
}
|
194
|
// otherwise result is already sorted
|
195
|
}
|
196
|
|
197
|
private void fillClassifications() {
|
198
|
if(classifications == null){
|
199
|
classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
|
200
|
Collections.sort(classifications, new Comparator<Classification>() {
|
201
|
|
202
|
@Override
|
203
|
public int compare(Classification o1, Classification o2) {
|
204
|
if (o1.equals(o2)){
|
205
|
return 0;
|
206
|
}
|
207
|
int result = o1.getTitleCache().compareTo(o2.getTitleCache());
|
208
|
if (result == 0){
|
209
|
return o1.getUuid().compareTo(o2.getUuid());
|
210
|
}
|
211
|
return result;
|
212
|
}
|
213
|
});
|
214
|
if (selectedClassification == null){
|
215
|
// if (this.cdmBaseToBeFiltered.isEmpty()){
|
216
|
selectedClassification = classifications.iterator().next();
|
217
|
|
218
|
// } else {
|
219
|
// selectedClassification = this.cdmBaseToBeFiltered.getClassification();
|
220
|
// }
|
221
|
}
|
222
|
}
|
223
|
}
|
224
|
|
225
|
/** {@inheritDoc} */
|
226
|
@Override
|
227
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
228
|
return null;
|
229
|
}
|
230
|
|
231
|
/** {@inheritDoc} */
|
232
|
@Override
|
233
|
protected String[] getNewWizardText() {
|
234
|
return null;
|
235
|
}
|
236
|
|
237
|
/** {@inheritDoc} */
|
238
|
@Override
|
239
|
public void widgetSelected(SelectionEvent e) {
|
240
|
selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
|
241
|
|
242
|
// refresh();
|
243
|
if (getSearchField().getText() != null){
|
244
|
search();
|
245
|
}
|
246
|
}
|
247
|
|
248
|
/** {@inheritDoc} */
|
249
|
@Override
|
250
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
251
|
|
252
|
|
253
|
}
|