Project

General

Profile

Revision 4db1bbe6

ID4db1bbe63c394d6e26bcf4a5b5815c891cac3d1e
Parent 19f02eea
Child 7832ef53

Added by Patrick Plitzner over 1 year ago

ref #7875 Refactor term label provider

  • add Styler to label provider

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoLabelProvider.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.definedterm;
10 10

  
11
import org.eclipse.jface.viewers.ColumnLabelProvider;
11
import org.eclipse.jface.viewers.StyledCellLabelProvider;
12
import org.eclipse.jface.viewers.StyledString;
13
import org.eclipse.jface.viewers.StyledString.Styler;
14
import org.eclipse.jface.viewers.ViewerCell;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.StyleRange;
17
import org.eclipse.swt.graphics.Color;
18
import org.eclipse.swt.graphics.TextStyle;
19
import org.eclipse.swt.widgets.Display;
12 20

  
13 21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
14 22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
......
20 28
 * @since Oct 29, 2018
21 29
 *
22 30
 */
23
public class TermDtoLabelProvider extends ColumnLabelProvider {
31
public class TermDtoLabelProvider extends StyledCellLabelProvider {
32

  
33
    private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
34
    private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
35
    private Styler vocStyler;
36
    private Styler kindOfStyler;
37

  
38
    public TermDtoLabelProvider() {
39
    }
40

  
41
    public TermDtoLabelProvider(Styler vocStyler){
42
        this.vocStyler = vocStyler;
43
    }
24 44

  
25 45
    @Override
46
    public void update(ViewerCell cell) {
47
        Object element = cell.getElement();
48

  
49
        String text = getText(element);
50
        cell.setText(text);
51

  
52
        Styler styler = null;
53
        if (element instanceof TermVocabulary && text != null) {
54
            styler = getVocabularyStyler();
55
        }
56
        //TODO: add kindOf UUID to TermDto
57
//        else if(element instanceof TermDto && ((TermDto) element).getKindOf()!=null){
58
//            styler = getKindOfStyler();
59
//        }
60
        if(styler!=null){
61
            StyledString styledString = new StyledString(text, styler);
62
            StyleRange[] styleRanges;
63
            styleRanges = styledString.getStyleRanges();
64
            cell.setStyleRanges(styleRanges);
65
        }
66
        super.update(cell);
67
    }
68

  
26 69
    public String getText(Object element) {
70
        String label = null;
27 71
        if(element instanceof TermVocabulary){
28
            return ((TermVocabulary) element).getTitleCache();
72

  
29 73
        }
30 74
        else if(element instanceof TermDto){
31
            TermDto termDto = (TermDto) element;
75
            TermDto termDto = (TermDto)element;
32 76
            termDto.localize(new TermRepresentation_L10n());
33
            return termDto.getRepresentation_L10n();
77
            label = termDto.getRepresentation_L10n();
78

  
79
                //TODO: add idInVocabulary to TermDto
80
//                label = CdmUtils.concat(" : ", termDto.getIdInVocabulary(), label);
81
        }
82
        // TODO add fallback for label
83
        if(label==null){
84
            label = element.toString();
85
        }
86
        return label;
87
    }
88

  
89
    protected Styler getVocabularyStyler() {
90
        if (vocStyler == null) {
91
            vocStyler = new Styler() {
92
                @Override
93
                public void applyStyles(TextStyle textStyle) {
94
                    textStyle.foreground = vocColor;
95
                }
96
            };
97
        }
98
        return vocStyler;
99
    }
100

  
101
    protected Styler getKindOfStyler() {
102
        if (kindOfStyler == null) {
103
            kindOfStyler = new Styler() {
104
                @Override
105
                public void applyStyles(TextStyle textStyle) {
106
                    textStyle.foreground = kindOfColor;
107
                }
108
            };
34 109
        }
35
        return element.toString();
110
        return kindOfStyler;
36 111
    }
37 112

  
38 113
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java
41 41
    private Styler kindOfStyler;
42 42

  
43 43
    public TermLabelProvider() {
44
        this.vocStyler = new Styler() {
45
            @Override
46
            public void applyStyles(TextStyle textStyle) {
47
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
48
            }
49
        };
44 50
    }
45 51

  
46 52
    public TermLabelProvider(Styler vocStyler){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AreaLabelProvider.java
26 26
 */
27 27
public class AreaLabelProvider extends TermLabelProvider implements ILabelProvider{
28 28

  
29
    public AreaLabelProvider(){
30
        super();
31
    }
32

  
29 33
    public AreaLabelProvider(Styler vocStyler){
30 34
        super(vocStyler);
31 35
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
23 23
import org.eclipse.jface.viewers.CheckboxTreeViewer;
24 24
import org.eclipse.jface.viewers.ICheckStateListener;
25 25
import org.eclipse.jface.viewers.ITreeViewerListener;
26
import org.eclipse.jface.viewers.StyledString.Styler;
27 26
import org.eclipse.jface.viewers.TreeExpansionEvent;
28 27
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.graphics.TextStyle;
30 28
import org.eclipse.swt.layout.GridData;
31 29
import org.eclipse.swt.layout.GridLayout;
32 30
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.Display;
34 31

  
35 32
import eu.etaxonomy.cdm.api.service.IVocabularyService;
36 33
import eu.etaxonomy.cdm.model.common.CdmBase;
......
74 71
        setViewer(new CheckboxTreeViewer(composite, SWT.NULL));
75 72
        ((CheckboxTreeViewer)getViewer()).getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
76 73
        getViewer().setContentProvider(new DistributionContentProvider());
77
        Styler styler = new Styler() {
78
            @Override
79
            public void applyStyles(TextStyle textStyle) {
80
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
81
            }
82
        };
83
        getViewer().setLabelProvider(new AreaLabelProvider(styler));
74
        getViewer().setLabelProvider(new AreaLabelProvider());
84 75
        getViewer().setComparator(new AreaViewerComparator());
85 76
        ((CheckboxTreeViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
86 77

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionStatusPage.java
17 17
import org.eclipse.jface.viewers.CheckboxTreeViewer;
18 18
import org.eclipse.jface.viewers.ColumnViewer;
19 19
import org.eclipse.jface.viewers.ICheckStateListener;
20
import org.eclipse.jface.viewers.StyledString.Styler;
21 20
import org.eclipse.jface.viewers.ViewerComparator;
22 21
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.graphics.TextStyle;
24 22
import org.eclipse.swt.layout.GridData;
25 23
import org.eclipse.swt.layout.GridLayout;
26 24
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Display;
28 25

  
29 26
import eu.etaxonomy.cdm.model.common.CdmBase;
30 27
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
......
72 69
        setViewer(new CheckboxTreeViewer(composite, SWT.NULL));
73 70
        ((CheckboxTreeViewer)getViewer()).getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
74 71
//        viewer.setContentProvider(new TermContentProvider());
75
        Styler styler = new Styler() {
76
            @Override
77
            public void applyStyles(TextStyle textStyle) {
78
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
79
            }
80
        };
81 72
        getViewer().setContentProvider(new TermContentProvider());
82
        getViewer().setLabelProvider(new TermLabelProvider(styler));
73
        getViewer().setLabelProvider(new TermLabelProvider());
83 74
        getViewer().setComparator(new ViewerComparator());
84 75
        ((CheckboxTreeViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
85 76

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/CheckBoxTreeComposite.java
10 10

  
11 11
import org.eclipse.jface.viewers.AbstractTreeViewer;
12 12
import org.eclipse.jface.viewers.CheckboxTreeViewer;
13
import org.eclipse.jface.viewers.ILabelProvider;
13
import org.eclipse.jface.viewers.IBaseLabelProvider;
14 14
import org.eclipse.jface.viewers.ITreeContentProvider;
15 15
import org.eclipse.swt.SWT;
16 16
import org.eclipse.swt.layout.GridData;
......
28 28

  
29 29
    private CheckboxTreeViewer viewer;
30 30

  
31
    public CheckBoxTreeComposite(Composite parent, ITreeContentProvider contentProvider, ILabelProvider labelProvider, int style) {
31
    public CheckBoxTreeComposite(Composite parent, ITreeContentProvider contentProvider, IBaseLabelProvider labelProvider, int style) {
32 32
        super(parent, style);
33 33
        Composite composite = new Composite(parent, SWT.NULL);
34 34
        composite.setLayout(new GridLayout());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)