Project

General

Profile

Revision cb1498ea

IDcb1498eaae20b613517905baa613566cdd286dbf
Parent 3dbe4420
Child ab94d85b

Added by Patrick Plitzner almost 3 years ago

ref #6216 Added button to select color instead of clicking on color
field

  • resized color field

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/PresenceAbsenceTermDetailElement.java
11 11

  
12 12
import java.text.ParseException;
13 13

  
14
import org.eclipse.swt.events.MouseEvent;
15
import org.eclipse.swt.events.MouseListener;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.events.SelectionListener;
16 17
import org.eclipse.swt.graphics.Color;
17 18
import org.eclipse.swt.graphics.RGB;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
18 22
import org.eclipse.swt.widgets.ColorDialog;
23
import org.eclipse.swt.widgets.Composite;
19 24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.ui.forms.widgets.TableWrapData;
20 26

  
21 27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 28
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
23 29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
30
import eu.etaxonomy.taxeditor.model.ImageResources;
24 31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25 32
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26 33
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
27 34
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
35
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
28 36

  
29 37
/**
30 38
 *
......
32 40
 * @date Nov 24, 2016
33 41
 *
34 42
 */
35
public class PresenceAbsenceTermDetailElement extends DefinedTermDetailElement<PresenceAbsenceTerm> implements MouseListener{
43
public class PresenceAbsenceTermDetailElement extends DefinedTermDetailElement<PresenceAbsenceTerm> implements SelectionListener{
36 44

  
37 45
    private Label colorLabel;
38 46

  
39 47
    private Color color;
40 48

  
49
    private Button btnColorChooser;
50

  
41 51
	public PresenceAbsenceTermDetailElement(CdmFormFactory formFactory,
42 52
			ICdmFormElement formElement) {
43 53
		super(formFactory, formElement);
......
49 59

  
50 60
	    Label colorTextLabel = new Label(getLayoutComposite(), style);
51 61
	    colorTextLabel.setText("Color");
52
	    colorLabel = new Label(getLayoutComposite(), style);
53
	    colorLabel.addMouseListener(this);
54

  
55
	    String defaultColor = entity.getDefaultColor();
56
	    if(defaultColor!=null){
57
	        java.awt.Color awtColor = java.awt.Color.decode("#"+defaultColor);
62
	    TableWrapData left = LayoutConstants.LEFT();
63
	    left.valign = TableWrapData.MIDDLE;
64
	    colorTextLabel.setLayoutData(left);
65
	    addControl(colorTextLabel);
66

  
67
	    //composite(color label + button)
68
        Composite colorAndButton = formFactory.createComposite(getLayoutComposite(), style);
69
        addControl(colorAndButton);
70
        GridLayout layout = new GridLayout(2, false);
71
        layout.marginWidth = 0;
72
        colorAndButton.setLayout(layout);
73

  
74
        colorLabel = new Label(colorAndButton, style|SWT.BORDER);
75
        colorLabel.setLayoutData(new GridData(16, 16));
76

  
77
        String defaultColor = entity.getDefaultColor();
78
        if(defaultColor!=null){
79
            //TODO: Is there any utility method from SWT?
80
            java.awt.Color awtColor = java.awt.Color.decode("#"+defaultColor);
58 81
            RGB rgb = new RGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
59
	        color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
60
	        colorLabel.setBackground(color);
61
	    }
82
            color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
83
            colorLabel.setBackground(color);
84
        }
85

  
86
        //button
87
        btnColorChooser = formFactory.createButton(colorAndButton, "", SWT.NONE); //$NON-NLS-1$
88
        btnColorChooser.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
89
        btnColorChooser.setToolTipText("Choose color");
90
        btnColorChooser.addSelectionListener(this);
62 91
	}
63 92

  
64 93
	@Override
......
75 104
     * {@inheritDoc}
76 105
     */
77 106
    @Override
78
    public void mouseDoubleClick(MouseEvent e) {
79

  
80
    }
81

  
82
    /**
83
     * {@inheritDoc}
84
     */
85
    @Override
86
    public void mouseDown(MouseEvent e) {
87
    }
88

  
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public void mouseUp(MouseEvent e) {
107
    public void widgetSelected(SelectionEvent e) {
94 108
        ColorDialog dialog = new ColorDialog(AbstractUtility.getShell());
95 109
        if(color!=null){
96 110
            dialog.setRGB(color.getRGB());
......
112 126
        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
113 127
    }
114 128

  
129
    /**
130
     * {@inheritDoc}
131
     */
132
    @Override
133
    public void widgetDefaultSelected(SelectionEvent e) {
134
    }
135

  
115 136
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)