Project

General

Profile

Revision eebb08aa

IDeebb08aabcd4d1a8dc0d530af8808e60a835a1b1
Parent a3c56b93
Child 501ab766

Added by Patrick Plitzner over 1 year ago

ref #7887 Use term DTOs in feature selection dialog for feature trees

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/AvailableFeaturesWizardPage.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.featuretree;
11 11

  
12
import java.util.Arrays;
12 13
import java.util.HashSet;
13 14
import java.util.List;
14 15
import java.util.Set;
16
import java.util.stream.Collectors;
15 17

  
16
import org.eclipse.jface.viewers.CheckStateChangedEvent;
17
import org.eclipse.jface.viewers.CheckboxTreeViewer;
18
import org.eclipse.jface.viewers.ICheckStateListener;
18
import org.eclipse.jface.layout.GridLayoutFactory;
19 19
import org.eclipse.jface.wizard.WizardPage;
20 20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.GridData;
22 21
import org.eclipse.swt.layout.GridLayout;
23 22
import org.eclipse.swt.widgets.Composite;
24 23

  
24
import eu.etaxonomy.cdm.api.service.ITermService;
25 25
import eu.etaxonomy.cdm.api.service.IVocabularyService;
26 26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27 27
import eu.etaxonomy.cdm.model.common.TermType;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29 28
import eu.etaxonomy.cdm.model.description.Feature;
29
import eu.etaxonomy.cdm.persistence.dto.TermDto;
30
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
30 31
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
31
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
34
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
33 35
import eu.etaxonomy.taxeditor.store.CdmStore;
34 36

  
35 37
/**
......
39 41
 */
40 42
public class AvailableFeaturesWizardPage extends WizardPage {
41 43

  
42
	private CheckboxTreeViewer viewer;
44
    private CheckBoxTreeComposite treeComposite;
43 45

  
44 46
	protected AvailableFeaturesWizardPage() {
45 47
		super("AvailableFeaturesWizardPage");
......
50 52
	/** {@inheritDoc} */
51 53
	@Override
52 54
	public void createControl(Composite parent) {
53
		Composite composite = new Composite(parent, SWT.NULL);
54
		composite.setLayout(new GridLayout());
55

  
56
		viewer = new CheckboxTreeViewer(composite, SWT.NULL);
57

  
58
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
59

  
60
		viewer.setComparator(new DefinedTermSorter());
61

  
62
        viewer.setContentProvider(new TermContentProvider());
63
        viewer.setLabelProvider(new TermLabelProvider());
64
        // When user checks a checkbox in the tree, check all its children
65
        viewer.addCheckStateListener(new ICheckStateListener() {
66
            @Override
67
            public void checkStateChanged(CheckStateChangedEvent event) {
68
                viewer.setSubtreeChecked(event.getElement(), event.getChecked());
69
            }
70
        });
71

  
72
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.Feature, null);
73
		viewer.setInput(vocs);
74

  
75
		setControl(composite);
55
	    parent.setLayout(new GridLayout());
56
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
57
        List<TermVocabularyDto> vocabularyDtos = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(TermType.Feature);
58
        treeComposite.getViewer().setComparator(new DefinedTermSorter());
59
        treeComposite.getViewer().setInput(vocabularyDtos);
60
        GridLayoutFactory.fillDefaults().applyTo(treeComposite);
61

  
62
		setControl(treeComposite);
76 63
	}
77 64

  
78 65
	public Set<Feature> getSelectedFeatures() {
79 66

  
80
		Object[] checkedElements = viewer.getCheckedElements();
67
        List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
68
        checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList());
81 69

  
82
		Set<Feature> features = new HashSet<Feature>(checkedElements.length);
70
		Set<Feature> features = new HashSet<Feature>();
83 71

  
84 72
		for(Object element : checkedElements){
85
		    if(element instanceof Feature){
86
		        features.add((Feature) element);
73
		    if(element instanceof TermDto){
74
		        DefinedTermBase feature = CdmStore.getService(ITermService.class).load(((TermDto) element).getUuid());
75
		        features.add((Feature) feature);
87 76
		    }
88 77
		}
89 78
		return features;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)