Revision 99fab853
Added by Katja Luther almost 4 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenSelectionDialog.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 | 12 |
import java.util.Collection; |
13 |
import java.util.Iterator; |
|
13 | 14 |
import java.util.List; |
14 | 15 |
import java.util.stream.Collectors; |
15 | 16 |
|
... | ... | |
66 | 67 |
private Collection<SpecimenNodeWrapper> selectedSpecimens = new ArrayList<>(); |
67 | 68 |
private CharacterMatrix matrix; |
68 | 69 |
private Text txtTextFilter; |
69 |
private List<String> treeIndex; |
|
70 |
private List<String> treeIndexList; |
|
71 |
private List<String> taxonTitleList; |
|
72 |
private Label l_title; |
|
70 | 73 |
|
71 | 74 |
|
72 |
public SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix, List<String> treeIndex) { |
|
75 |
public SpecimenSelectionDialog(Shell parentShell, CharacterMatrix matrix, List<String> treeIndex, List<String> taxonTitleList) {
|
|
73 | 76 |
super(parentShell); |
74 | 77 |
this.matrix = matrix; |
75 |
this.treeIndex = treeIndex; |
|
78 |
this.treeIndexList = treeIndex; |
|
79 |
this.taxonTitleList = taxonTitleList; |
|
76 | 80 |
} |
77 | 81 |
|
78 | 82 |
@Override |
... | ... | |
81 | 85 |
GridLayout gl_composite = new GridLayout(); |
82 | 86 |
gl_composite.numColumns = 2; |
83 | 87 |
composite.setLayout(gl_composite); |
84 |
|
|
88 |
l_title = new Label(composite, SWT.NULL); |
|
89 |
if (taxonTitleList != null && !taxonTitleList.isEmpty()){ |
|
90 |
Iterator<String> iterator = taxonTitleList.iterator(); |
|
91 |
String titleString=iterator.next(); |
|
92 |
while(iterator.hasNext() ){ |
|
93 |
titleString += ", "+ iterator.next(); |
|
94 |
} |
|
95 |
l_title.setText("Taxon Filter: " + titleString); |
|
96 |
} |
|
85 | 97 |
Composite composite_1 = new Composite(composite, SWT.NONE); |
86 | 98 |
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); |
87 | 99 |
composite_1.setLayout(new GridLayout(5, false)); |
... | ... | |
124 | 136 |
@Override |
125 | 137 |
public void widgetSelected(SelectionEvent e) { |
126 | 138 |
loadSpecimens(); |
127 |
refreshInput(matrix.getSpecimenCache());
|
|
139 |
refreshInput(); |
|
128 | 140 |
} |
129 | 141 |
}); |
130 | 142 |
|
131 |
Button btnRemoveTaxonFilterButton = new Button(composite_1, SWT.NONE);
|
|
132 |
btnRemoveTaxonFilterButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
|
133 |
btnRemoveTaxonFilterButton.setToolTipText(Messages.SpecimenSelectionDialog_REMOVE_FILTER);
|
|
134 |
btnRemoveTaxonFilterButton.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
|
|
135 |
btnRemoveTaxonFilterButton.addSelectionListener(new SelectionAdapter() {
|
|
143 |
Button btnRemoveFilterButton = new Button(composite_1, SWT.NONE); |
|
144 |
btnRemoveFilterButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
|
145 |
btnRemoveFilterButton.setToolTipText(Messages.SpecimenSelectionDialog_REMOVE_FILTER); |
|
146 |
btnRemoveFilterButton.setImage(ImageResources.getImage(ImageResources.TRASH_ICON)); |
|
147 |
btnRemoveFilterButton.addSelectionListener(new SelectionAdapter() { |
|
136 | 148 |
@Override |
137 | 149 |
public void widgetSelected(SelectionEvent e) { |
138 | 150 |
txtTextFilter.setText(""); |
139 |
refreshInput(matrix.getSpecimenCache()); |
|
151 |
treeIndexList = null; |
|
152 |
l_title.setText(""); |
|
153 |
refreshInput(); |
|
140 | 154 |
} |
141 | 155 |
}); |
142 | 156 |
|
... | ... | |
207 | 221 |
if(matrix.getSpecimenCache()==null){ |
208 | 222 |
loadSpecimens(); |
209 | 223 |
} |
210 |
if(treeIndex !=null){ |
|
211 |
filterByTaxonNode(treeIndex, null);
|
|
224 |
if(treeIndexList !=null){
|
|
225 |
filterByTaxonNode( null); |
|
212 | 226 |
}else{ |
213 |
refreshInput(matrix.getSpecimenCache());
|
|
227 |
refreshInput(); |
|
214 | 228 |
} |
215 | 229 |
|
216 | 230 |
columnSpecimen.getColumn().pack(); |
... | ... | |
218 | 232 |
return composite; |
219 | 233 |
} |
220 | 234 |
|
221 |
private void refreshInput(Object input){
|
|
222 |
list.setInput(input);
|
|
235 |
private void refreshInput(){ |
|
236 |
applyFilter();
|
|
223 | 237 |
} |
224 | 238 |
|
225 | 239 |
private void applyFilter(){ |
... | ... | |
227 | 241 |
Collection<SpecimenNodeWrapper> specimenCache = matrix.getSpecimenCache(); |
228 | 242 |
String text = txtTextFilter.getText(); |
229 | 243 |
|
230 |
//filter for treeIndex is missing |
|
244 |
//filter for treeIndexList is missing
|
|
231 | 245 |
if(CdmUtils.isBlank(text)){ |
232 | 246 |
result = new ArrayList<>(specimenCache); |
233 | 247 |
} |
... | ... | |
242 | 256 |
.collect(Collectors.toList())); |
243 | 257 |
} |
244 | 258 |
} |
245 |
filterByTaxonNode(treeIndex, result);
|
|
259 |
filterByTaxonNode(result); |
|
246 | 260 |
|
247 | 261 |
} |
248 | 262 |
|
... | ... | |
335 | 349 |
} |
336 | 350 |
} |
337 | 351 |
|
338 |
private void filterByTaxonNode(List<String> treeIndexList, Collection<SpecimenNodeWrapper> specimenCache){
|
|
352 |
private void filterByTaxonNode( Collection<SpecimenNodeWrapper> specimenCache){ |
|
339 | 353 |
Collection<SpecimenNodeWrapper> result = new ArrayList<>(); |
340 | 354 |
if (specimenCache == null){ |
341 | 355 |
specimenCache = matrix.getSpecimenCache(); |
342 | 356 |
} |
343 |
for (String treeIndex: treeIndexList){ |
|
344 |
if (StringUtils.isNotBlank(treeIndex)){ |
|
345 |
result.addAll(specimenCache.stream() |
|
346 |
.filter(wrapper->wrapper.getTaxonNode().getTreeIndex().startsWith(treeIndex)) |
|
347 |
.collect(Collectors.toList())); |
|
357 |
if (treeIndexList != null){ |
|
358 |
for (String treeIndex: this.treeIndexList){ |
|
359 |
if (StringUtils.isNotBlank(treeIndex)){ |
|
360 |
result.addAll(specimenCache.stream() |
|
361 |
.filter(wrapper->wrapper.getTaxonNode().getTreeIndex().startsWith(treeIndex)) |
|
362 |
.collect(Collectors.toList())); |
|
363 |
} |
|
348 | 364 |
} |
365 |
}else{ |
|
366 |
result.addAll(specimenCache); |
|
349 | 367 |
} |
350 | 368 |
|
351 | 369 |
|
352 |
refreshInput(result);
|
|
370 |
list.setInput(result);
|
|
353 | 371 |
} |
354 | 372 |
} |
Also available in: Unified diff
ref #8785: add remove filter button and title containing the selected taxa