Project

General

Profile

Revision ce2334e5

IDce2334e542a60e8b78dbc87da9e8e4b976ff0cb8
Parent 790e1587
Child 9df52c92

Added by Patrick Plitzner over 1 year ago

ref #7875 Use UuidAndTitleCache based services for area selection dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/AreasSelectionDialog.java
17 17

  
18 18
import org.eclipse.jface.dialogs.Dialog;
19 19
import org.eclipse.jface.layout.GridLayoutFactory;
20
import org.eclipse.jface.viewers.StyledString.Styler;
21 20
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.TextStyle;
23 21
import org.eclipse.swt.layout.GridLayout;
24 22
import org.eclipse.swt.widgets.Composite;
25 23
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Display;
27 24
import org.eclipse.swt.widgets.Shell;
28 25

  
29 26
import eu.etaxonomy.cdm.api.service.IVocabularyService;
30 27
import eu.etaxonomy.cdm.model.common.TermType;
31 28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
32 29
import eu.etaxonomy.cdm.model.location.NamedArea;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
34
import eu.etaxonomy.taxeditor.preference.wizard.AreaLabelProvider;
30
import eu.etaxonomy.taxeditor.editor.definedterm.TermUuidAndTitleCacheContentProvider;
31
import eu.etaxonomy.taxeditor.editor.definedterm.TermUuidAndTitleCacheLabelProvider;
35 32
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
36 33
import eu.etaxonomy.taxeditor.store.CdmStore;
37 34

  
......
58 55
    @Override
59 56
    protected Control createDialogArea(Composite parent) {
60 57
        parent.setLayout(new GridLayout());
61
        Styler styler = new Styler() {
62
            @Override
63
            public void applyStyles(TextStyle textStyle) {
64
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
65
            }
66
        };
67
        treeComposite = new CheckBoxTreeComposite(parent, new TermContentProvider(), new AreaLabelProvider(styler), SWT.NONE);
58
        treeComposite = new CheckBoxTreeComposite(parent, new TermUuidAndTitleCacheContentProvider(), new TermUuidAndTitleCacheLabelProvider(), SWT.NONE);
68 59
        treeComposite.getViewer().setInput(namedAreas);
69 60
        treeComposite.setCheckedElements(selectedAreas.toArray());
70 61
        treeComposite.getViewer().reveal(selectedAreas);
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).getGeneralizationsAsUuidAndTitleCache((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)