Revision 501ab766
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/AreasSelectionDialog.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.Arrays; |
12 | 13 |
import java.util.Collection; |
13 | 14 |
import java.util.Collections; |
14 |
import java.util.HashSet; |
|
15 | 15 |
import java.util.List; |
16 |
import java.util.Set; |
|
17 | 16 |
import java.util.stream.Collectors; |
18 | 17 |
|
19 | 18 |
import org.eclipse.jface.dialogs.Dialog; |
... | ... | |
26 | 25 |
|
27 | 26 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
28 | 27 |
import eu.etaxonomy.cdm.model.common.TermType; |
29 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
|
30 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
31 | 28 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
29 |
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; |
|
30 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter; |
|
32 | 31 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider; |
33 | 32 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider; |
34 | 33 |
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite; |
... | ... | |
43 | 42 |
|
44 | 43 |
private CheckBoxTreeComposite treeComposite; |
45 | 44 |
|
46 |
private Set<TermDto> selectedAreas = new HashSet<>();
|
|
45 |
private List<TermDto> selectedAreas;
|
|
47 | 46 |
|
48 |
private Collection<TermVocabulary<NamedArea>> areaVocabularies;
|
|
47 |
private Collection<TermVocabularyDto> areaVocabularies;
|
|
49 | 48 |
|
50 | 49 |
|
51 |
protected AreasSelectionDialog(Shell parentShell, Set<TermDto> selectedAreas) {
|
|
50 |
protected AreasSelectionDialog(Shell parentShell, List<TermDto> selectedAreas) {
|
|
52 | 51 |
super(parentShell); |
53 | 52 |
this.selectedAreas = selectedAreas; |
54 |
this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
|
|
53 |
this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(TermType.NamedArea);
|
|
55 | 54 |
} |
56 | 55 |
|
57 | 56 |
@Override |
58 | 57 |
protected Control createDialogArea(Composite parent) { |
59 | 58 |
parent.setLayout(new GridLayout()); |
60 | 59 |
treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE); |
60 |
treeComposite.getViewer().setComparator(new DefinedTermSorter()); |
|
61 | 61 |
treeComposite.getViewer().setInput(areaVocabularies); |
62 |
Collections.sort(selectedAreas, (o1, o2)->o1.getOrderIndex()-o2.getOrderIndex()); |
|
62 | 63 |
treeComposite.setCheckedElements(selectedAreas.toArray()); |
63 | 64 |
GridLayoutFactory.fillDefaults().applyTo(treeComposite); |
64 | 65 |
return treeComposite; |
... | ... | |
76 | 77 |
selectedAreas.clear(); |
77 | 78 |
List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements()); |
78 | 79 |
checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList()); |
79 |
Collections.sort(checkedElements, (o1, o2)->((TermDto)o1).getOrderIndex()-((TermDto)o2).getOrderIndex()); |
|
80 |
selectedAreas = new HashSet(checkedElements); |
|
80 |
selectedAreas = new ArrayList(checkedElements); |
|
81 | 81 |
super.okPressed(); |
82 | 82 |
} |
83 | 83 |
|
... | ... | |
86 | 86 |
return true; |
87 | 87 |
} |
88 | 88 |
|
89 |
public Set<TermDto> getSelectedAreas(){
|
|
89 |
public List<TermDto> getSelectedAreas(){
|
|
90 | 90 |
return selectedAreas; |
91 | 91 |
} |
92 | 92 |
} |
Also available in: Unified diff
ref #7875 Completely convert area selection to DTOs