Project

General

Profile

Download (4.51 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.view.search.facet.term;
10

    
11
import org.eclipse.jface.layout.GridDataFactory;
12
import org.eclipse.jface.resource.JFaceResources;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.DragDetectEvent;
15
import org.eclipse.swt.events.DragDetectListener;
16
import org.eclipse.swt.events.FocusEvent;
17
import org.eclipse.swt.events.FocusListener;
18
import org.eclipse.swt.events.MouseEvent;
19
import org.eclipse.swt.events.MouseListener;
20
import org.eclipse.swt.graphics.Color;
21
import org.eclipse.swt.layout.FillLayout;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26

    
27
import eu.etaxonomy.taxeditor.model.ColorResources;
28
import eu.etaxonomy.taxeditor.preference.Resources;
29

    
30
/**
31
 * @author pplitzner
32
 * @since Jan 23, 2019
33
 *
34
 */
35
public class TermSearchResultComposite extends Composite {
36

    
37
    private Label label;
38
    private boolean isSelected;
39
    private TermSearchResult result;
40
    private Label lblItemDash;
41

    
42
    /**
43
     * Create the composite.
44
     * @param result
45
     * @param parent
46
     * @param style
47
     */
48
    public TermSearchResultComposite(TermSearchResult result, Composite parent, int style) {
49
        super(parent, style);
50
        this.result = result;
51
        setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
52
        GridLayout gridLayout = new GridLayout();
53
        gridLayout.marginWidth = 0;
54
        gridLayout.horizontalSpacing = 0;
55
        gridLayout.numColumns = 2;
56
        setLayout(gridLayout);
57

    
58
        Composite composite = new Composite(this, SWT.NONE);
59
        composite.setLayout(new FillLayout(SWT.HORIZONTAL));
60
        composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2));
61

    
62
        lblItemDash = new Label(composite, SWT.NONE);
63
        lblItemDash.setText("   -   ");
64
        label = new Label(this, SWT.NONE);
65
        label.setText(result.getContent().getRepresentation_L10n());
66
        label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
67
        GridDataFactory.fillDefaults().applyTo(label);
68

    
69
        Label lblDescription = new Label(this, SWT.NONE);
70
        lblDescription.setText("Some description of the term. This can be a longer text. Also images appear in this area if they are present.");
71
        label.addFocusListener(new FocusListener() {
72

    
73
            @Override
74
            public void focusLost(FocusEvent e) {
75
                System.out.println("focusLost");
76
            }
77

    
78
            @Override
79
            public void focusGained(FocusEvent e) {
80
                System.out.println("focusGained");
81
            }
82
        });
83
        label.addDragDetectListener(new DragDetectListener() {
84

    
85
            @Override
86
            public void dragDetected(DragDetectEvent e) {
87
                System.out.println("dragDetected");
88
            }
89
        });
90
        label.addMouseListener(new MouseListener() {
91

    
92
            @Override
93
            public void mouseUp(MouseEvent e) {
94
                System.out.println("mouseUp");
95
                isSelected = !isSelected;
96
                setBgColor();
97
            }
98

    
99

    
100
            @Override
101
            public void mouseDown(MouseEvent e) {
102
            }
103

    
104
            @Override
105
            public void mouseDoubleClick(MouseEvent e) {
106
                System.out.println("mouseDoubleClick");
107
            }
108
        });
109
    }
110

    
111
    public boolean isSelected() {
112
        return isSelected;
113
    }
114

    
115
    public TermSearchResult getResult() {
116
        return result;
117
    }
118

    
119
    private void setBgColor() {
120
        if(isSelected){
121
            Color colorSelected = ColorResources.getColor(Resources.COLOR_LIST_EVEN);
122
            TermSearchResultComposite.this.setBackground(colorSelected);
123
            label.setBackground(colorSelected);
124
            lblItemDash.setBackground(colorSelected);
125
        }
126
        else{
127
            Color colorControlBackground = ColorResources.getColor(Resources.COLOR_SWT_BG_DEFAULT);
128
            TermSearchResultComposite.this.setBackground(colorControlBackground);
129
            label.setBackground(colorControlBackground);
130
            lblItemDash.setBackground(colorControlBackground);
131
        }
132
    }
133
    @Override
134
    protected void checkSubclass() {
135
        // Disable the check that prevents subclassing of SWT components
136
    }
137
}
(5-5/5)