Project

General

Profile

Revision 3c6e3fc6

ID3c6e3fc61e0a9908eafbc04f67f392c3aef0b71d
Parent 9df52c92
Child ceed9ceb

Added by Patrick Plitzner over 1 year ago

ref #7875 Adapt to TermDto based services

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/AreasSelectionDialog.java
27 27
import eu.etaxonomy.cdm.model.common.TermType;
28 28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29 29
import eu.etaxonomy.cdm.model.location.NamedArea;
30
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
31
import eu.etaxonomy.taxeditor.editor.definedterm.TermUuidAndTitleCacheContentProvider;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermUuidAndTitleCacheLabelProvider;
30
import eu.etaxonomy.cdm.persistence.dto.TermDto;
31
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
33 33
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
34 34
import eu.etaxonomy.taxeditor.store.CdmStore;
35 35

  
......
42 42

  
43 43
    private CheckBoxTreeComposite treeComposite;
44 44

  
45
    private Set<UuidAndTitleCache> selectedAreas = new HashSet<>();
45
    private Set<TermDto> selectedAreas = new HashSet<>();
46 46

  
47 47
    private Collection<TermVocabulary<NamedArea>> areaVocabularies;
48 48

  
49 49

  
50
    protected AreasSelectionDialog(Shell parentShell, Set<UuidAndTitleCache> selectedAreas) {
50
    protected AreasSelectionDialog(Shell parentShell, Set<TermDto> selectedAreas) {
51 51
        super(parentShell);
52 52
        this.selectedAreas = selectedAreas;
53 53
        this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
......
56 56
    @Override
57 57
    protected Control createDialogArea(Composite parent) {
58 58
        parent.setLayout(new GridLayout());
59
        treeComposite = new CheckBoxTreeComposite(parent, new TermUuidAndTitleCacheContentProvider(), new TermUuidAndTitleCacheLabelProvider(), SWT.NONE);
59
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
60 60
        treeComposite.getViewer().setInput(areaVocabularies);
61 61
        treeComposite.setCheckedElements(selectedAreas.toArray());
62 62
        treeComposite.getViewer().reveal(selectedAreas);
......
75 75
    protected void okPressed() {
76 76
        selectedAreas.clear();
77 77
        List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
78
        checkedElements = checkedElements.stream().filter(element->element instanceof UuidAndTitleCache).collect(Collectors.toList());
78
        checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList());
79 79
        selectedAreas = new HashSet(checkedElements);
80 80
        super.okPressed();
81 81
    }
......
85 85
        return true;
86 86
    }
87 87

  
88
    public Set<UuidAndTitleCache> getSelectedAreas(){
88
    public Set<TermDto> getSelectedAreas(){
89 89
        return selectedAreas;
90 90
    }
91 91
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
25 25
import eu.etaxonomy.cdm.model.common.TermType;
26 26
import eu.etaxonomy.cdm.model.description.FeatureTree;
27 27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
28
import eu.etaxonomy.cdm.persistence.dto.TermDto;
29
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
29 30
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
30 31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
31 32
import eu.etaxonomy.taxeditor.model.ImageResources;
......
44 45
    private TermUuidComboViewer comboRankMax;
45 46
    private FeatureTreeEditorComposite featureTreeEditorComposite;
46 47
    private TreeViewer taxonNodeTree;
47
    private Set<UuidAndTitleCache> areas = new HashSet<>();
48
    private Set<TermDto> areas = new HashSet<>();
48 49
    private Text textAreaText;
49 50
    private Button btnChooseArea;
50 51
    private Button btnRemoveRankMin;
......
173 174
    public TreeViewer getTaxonNodeTree() {
174 175
        return taxonNodeTree;
175 176
    }
176
    public Set<UuidAndTitleCache> getAreas() {
177
    public Set<TermDto> getAreas() {
177 178
        return areas;
178 179
    }
179
    public void setAreas(Set<UuidAndTitleCache> areas) {
180
    public void setAreas(Set<TermDto> areas) {
180 181
        this.areas = areas;
181
        textAreaText.setText(areas.stream().map(area->area.getTitleCache()).collect(Collectors.joining(", ")));
182
        textAreaText.setText(areas.stream().map(area->{
183
            area.localize(new TermRepresentation_L10n());
184
            return area.getRepresentation_L10n();
185
        }).collect(Collectors.joining(", ")));
182 186
    }
183 187
    public Button getBtnChooseArea() {
184 188
        return btnChooseArea;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
65 65
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
66 66
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
67 67
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
68
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
68
import eu.etaxonomy.cdm.persistence.dto.TermDto;
69 69
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
70 70
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
71 71
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
156 156
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
157 157
                AreasSelectionDialog areasSelectionDialog = new AreasSelectionDialog(composite.getShell(), composite.getAreas());
158 158
                if(areasSelectionDialog.open()==Window.OK){
159
                    Set<UuidAndTitleCache> selectedAreas = areasSelectionDialog.getSelectedAreas();
159
                    Set<TermDto> selectedAreas = areasSelectionDialog.getSelectedAreas();
160 160
                    if(selectedAreas!=null){
161 161
                        composite.setAreas(selectedAreas);
162 162
                        dirty.setDirty(true);
......
204 204
        }
205 205
        Set<NamedArea> geoFilter = descriptiveDataSet.getGeoFilter();
206 206
        if(geoFilter!=null && !geoFilter.isEmpty()){
207
            Set<UuidAndTitleCache> uuidAndTitleCaches = geoFilter.stream().map(filter->new UuidAndTitleCache(filter.getUuid(), filter.getId(), filter.getTitleCache())).collect(Collectors.toSet());
208
            composite.setAreas(uuidAndTitleCaches);
207
            Set<TermDto> terms = geoFilter.stream().map(filter->new TermDto(
208
                    filter.getUuid(),
209
                    filter.getRepresentations(),
210
                    filter.getPartOf()!=null?filter.getPartOf().getUuid():null,
211
                    filter.getVocabulary().getUuid(),
212
                    filter.getOrderIndex())).collect(Collectors.toSet());
213
            composite.setAreas(terms);
209 214
        }
210 215
        Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
211 216
        if(taxonSubtreeFilter!=null){
......
269 274
    @Persist
270 275
    @Override
271 276
    public void save(IProgressMonitor monitor) {
272
        Set<UuidAndTitleCache> areas = composite.getAreas();
277
        Set<TermDto> areas = composite.getAreas();
273 278
        Object input = composite.getTaxonNodeTree().getInput();
274 279
        if(input!=null){
275 280
            descriptiveDataSet.setTaxonSubtreeFilter(new HashSet<>());//clear existing filter
......
303 308
        descriptiveDataSet.setMinRank(rankMin);
304 309
        descriptiveDataSet.setDescriptiveSystem(characters);
305 310
        List<DefinedTermBase> terms = CdmStore.getService(ITermService.class)
306
                .loadByIds(areas.stream().map(area -> area.getId()).collect(Collectors.toList()), null);
311
                .load(areas.stream().map(area -> area.getUuid()).collect(Collectors.toList()), null);
307 312
        Set<NamedArea> areaTerms = new HashSet<>();
308 313
        terms.forEach(term->areaTerms.add((NamedArea) term));
309 314
        descriptiveDataSet.setGeoFilter(areaTerms);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java
1
/**
2
* Copyright (C) 2009 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.editor.definedterm;
10

  
11
import java.util.Collection;
12
import java.util.HashSet;
13

  
14
import org.eclipse.jface.viewers.TreeNodeContentProvider;
15

  
16
import eu.etaxonomy.cdm.api.service.ITermService;
17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
18
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22

  
23
/**
24
 *
25
 * @author pplitzner
26
 * @since Oct 29, 2018
27
 *
28
 */
29
public class TermDtoContentProvider extends TreeNodeContentProvider {
30

  
31
	@Override
32
	public Object[] getElements(Object inputElement) {
33
		Collection<TermVocabulary> inputElements = (Collection<TermVocabulary>) inputElement;
34
		return inputElements.toArray();
35
	}
36

  
37
	@Override
38
	public Object[] getChildren(Object parentElement) {
39
	    Collection<Object> children = new HashSet<>();
40
	    if(parentElement instanceof TermVocabulary){
41
	        children.addAll(CdmStore.getService(IVocabularyService.class).getTopLevelTerms(((TermVocabulary)parentElement).getId()));
42
	    } else {
43
	        Collection<Object> includes = new HashSet<>();
44
	        Collection<Object> generalizationOfs = new HashSet<>();
45
	        if (parentElement instanceof DefinedTermBase) {
46
	            includes = ((DefinedTermBase) parentElement).getIncludes();
47
	            generalizationOfs = ((DefinedTermBase) parentElement).getGeneralizationOf();
48
	        }
49
	        else if(parentElement instanceof TermDto){
50
	            includes.addAll(CdmStore.getService(ITermService.class).getIncludesAsUuidAndTitleCache((TermDto) parentElement));
51
	            generalizationOfs.addAll(CdmStore.getService(ITermService.class).getKindOfsAsUuidAndTitleCache((TermDto) parentElement));
52
	        }
53
	        children.addAll(includes);
54
	        children.addAll(generalizationOfs);
55
	    }
56
	    return children.toArray();
57
	}
58

  
59
	@Override
60
	public Object getParent(Object element) {
61
		if(element instanceof DefinedTermBase){
62
			DefinedTermBase definedTermBase = (DefinedTermBase)element;
63
			if (definedTermBase.getPartOf() != null) {
64
			    return definedTermBase.getPartOf();
65
			}else if (definedTermBase.getKindOf() != null) {
66
                return definedTermBase.getKindOf();
67
            } else {
68
			    return definedTermBase.getVocabulary();
69
			}
70
		}
71
		else if(element instanceof TermDto){
72
		    return CdmStore.getService(ITermService.class).getParentUuidAndTitleCache((TermDto)element);
73
		}
74
		return null;
75

  
76
	}
77

  
78
	@Override
79
	public boolean hasChildren(Object element) {
80
		if (getChildren(element) != null){
81
			return getChildren(element).length > 0;
82
		}
83
		return false;
84
	}
85

  
86
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoLabelProvider.java
1
/**
2
 * Copyright (C) 2009 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.editor.definedterm;
10

  
11
import org.eclipse.jface.viewers.ColumnLabelProvider;
12

  
13
import eu.etaxonomy.cdm.model.common.TermVocabulary;
14
import eu.etaxonomy.cdm.persistence.dto.TermDto;
15
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
16

  
17
/**
18
 *
19
 * @author pplitzner
20
 * @since Oct 29, 2018
21
 *
22
 */
23
public class TermDtoLabelProvider extends ColumnLabelProvider {
24

  
25
    @Override
26
    public String getText(Object element) {
27
        if(element instanceof TermVocabulary){
28
            return ((TermVocabulary) element).getTitleCache();
29
        }
30
        else if(element instanceof TermDto){
31
            TermDto termDto = (TermDto) element;
32
            termDto.localize(new TermRepresentation_L10n());
33
            return termDto.getRepresentation_L10n();
34
        }
35
        return element.toString();
36
    }
37

  
38
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermUuidAndTitleCacheContentProvider.java
1
/**
2
* Copyright (C) 2009 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.editor.definedterm;
10

  
11
import java.util.Collection;
12
import java.util.HashSet;
13

  
14
import org.eclipse.jface.viewers.TreeNodeContentProvider;
15

  
16
import eu.etaxonomy.cdm.api.service.ITermService;
17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
18
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22

  
23
/**
24
 *
25
 * @author pplitzner
26
 * @since Oct 29, 2018
27
 *
28
 */
29
public class TermUuidAndTitleCacheContentProvider extends TreeNodeContentProvider {
30

  
31
	@Override
32
	public Object[] getElements(Object inputElement) {
33
		Collection<TermVocabulary> inputElements = (Collection<TermVocabulary>) inputElement;
34
		return inputElements.toArray();
35
	}
36

  
37
	@Override
38
	public Object[] getChildren(Object parentElement) {
39
	    Collection<Object> children = new HashSet<>();
40
	    if(parentElement instanceof TermVocabulary){
41
	        children.addAll(CdmStore.getService(IVocabularyService.class).getTopLevelTerms(((TermVocabulary)parentElement).getId()));
42
	    } else {
43
	        Collection<Object> includes = new HashSet<>();
44
	        Collection<Object> generalizationOfs = new HashSet<>();
45
	        if (parentElement instanceof DefinedTermBase) {
46
	            includes = ((DefinedTermBase) parentElement).getIncludes();
47
	            generalizationOfs = ((DefinedTermBase) parentElement).getGeneralizationOf();
48
	        }
49
	        else if(parentElement instanceof UuidAndTitleCache){
50
	            includes.addAll(CdmStore.getService(ITermService.class).getIncludesAsUuidAndTitleCache((UuidAndTitleCache<DefinedTermBase>) parentElement));
51
	            generalizationOfs.addAll(CdmStore.getService(ITermService.class).getKindOfsAsUuidAndTitleCache((UuidAndTitleCache<DefinedTermBase>) parentElement));
52
	        }
53
	        children.addAll(includes);
54
	        children.addAll(generalizationOfs);
55
	    }
56
	    return children.toArray();
57
	}
58

  
59
	@Override
60
	public Object getParent(Object element) {
61
		if(element instanceof DefinedTermBase){
62
			DefinedTermBase definedTermBase = (DefinedTermBase)element;
63
			if (definedTermBase.getPartOf() != null) {
64
			    return definedTermBase.getPartOf();
65
			}else if (definedTermBase.getKindOf() != null) {
66
                return definedTermBase.getKindOf();
67
            } else {
68
			    return definedTermBase.getVocabulary();
69
			}
70
		}
71
		else if(element instanceof UuidAndTitleCache){
72
		    return CdmStore.getService(ITermService.class).getParentUuidAndTitleCache((UuidAndTitleCache)element);
73
		}
74
		return null;
75

  
76
	}
77

  
78
	@Override
79
	public boolean hasChildren(Object element) {
80
		if (getChildren(element) != null){
81
			return getChildren(element).length > 0;
82
		}
83
		return false;
84
	}
85

  
86
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermUuidAndTitleCacheLabelProvider.java
1
/**
2
 * Copyright (C) 2009 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.editor.definedterm;
10

  
11
import org.eclipse.jface.viewers.ColumnLabelProvider;
12

  
13
import eu.etaxonomy.cdm.model.common.TermVocabulary;
14
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
15

  
16
/**
17
 *
18
 * @author pplitzner
19
 * @since Oct 29, 2018
20
 *
21
 */
22
public class TermUuidAndTitleCacheLabelProvider extends ColumnLabelProvider {
23

  
24
    @Override
25
    public String getText(Object element) {
26
        if(element instanceof TermVocabulary){
27
            return ((TermVocabulary) element).getTitleCache();
28
        }
29
        else if(element instanceof UuidAndTitleCache){
30
            return ((UuidAndTitleCache) element).getTitleCache();
31
        }
32
        return element.toString();
33
    }
34

  
35
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)