|
1 |
// $Id$
|
|
2 |
/**
|
|
3 |
* Copyright (C) 2009 EDIT
|
|
4 |
* European Distributed Institute of Taxonomy
|
|
5 |
* http://www.e-taxonomy.eu
|
|
6 |
*
|
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms.
|
|
9 |
*/
|
|
10 |
package eu.etaxonomy.taxeditor.ui.section.vocabulary;
|
|
11 |
|
|
12 |
import java.text.ParseException;
|
|
13 |
|
|
14 |
import org.eclipse.swt.events.MouseEvent;
|
|
15 |
import org.eclipse.swt.events.MouseListener;
|
|
16 |
import org.eclipse.swt.graphics.Color;
|
|
17 |
import org.eclipse.swt.graphics.RGB;
|
|
18 |
import org.eclipse.swt.widgets.ColorDialog;
|
|
19 |
import org.eclipse.swt.widgets.Label;
|
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
|
22 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
|
23 |
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
|
24 |
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
|
25 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
|
26 |
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
|
27 |
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
|
28 |
|
|
29 |
/**
|
|
30 |
*
|
|
31 |
* @author pplitzner
|
|
32 |
* @date Nov 24, 2016
|
|
33 |
*
|
|
34 |
*/
|
|
35 |
public class PresenceAbsenceTermDetailElement extends DefinedTermDetailElement<PresenceAbsenceTerm> implements MouseListener{
|
|
36 |
|
|
37 |
private Label colorLabel;
|
|
38 |
|
|
39 |
private Color color;
|
|
40 |
|
|
41 |
public PresenceAbsenceTermDetailElement(CdmFormFactory formFactory,
|
|
42 |
ICdmFormElement formElement) {
|
|
43 |
super(formFactory, formElement);
|
|
44 |
}
|
|
45 |
|
|
46 |
@Override
|
|
47 |
protected void createControls(ICdmFormElement formElement, PresenceAbsenceTerm entity, int style) {
|
|
48 |
super.createControls(formElement, entity, style);
|
|
49 |
|
|
50 |
Label colorTextLabel = new Label(getLayoutComposite(), style);
|
|
51 |
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);
|
|
58 |
RGB rgb = new RGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
|
|
59 |
color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
|
|
60 |
colorLabel.setBackground(color);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
@Override
|
|
65 |
public void handleEvent(Object eventSource) {
|
|
66 |
super.handleEvent(eventSource);
|
|
67 |
}
|
|
68 |
|
|
69 |
@Override
|
|
70 |
public TermVocabulary getVocabulary() {
|
|
71 |
return getEntity() != null ? getEntity().getVocabulary() : null;
|
|
72 |
}
|
|
73 |
|
|
74 |
/**
|
|
75 |
* {@inheritDoc}
|
|
76 |
*/
|
|
77 |
@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) {
|
|
94 |
ColorDialog dialog = new ColorDialog(AbstractUtility.getShell());
|
|
95 |
RGB rgb = dialog.open();
|
|
96 |
if(rgb!=null){
|
|
97 |
if(color!=null){
|
|
98 |
color.dispose();
|
|
99 |
}
|
|
100 |
color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
|
|
101 |
colorLabel.setBackground(color);
|
|
102 |
try {
|
|
103 |
String hexCode = String.format("%02x%02x%02x", rgb.red,rgb.green,rgb.blue);
|
|
104 |
getEntity().setDefaultColor(hexCode);
|
|
105 |
} catch (ParseException pe) {
|
|
106 |
MessagingUtils.error(PresenceAbsenceTermDetailElement.class, "Color could not be set", pe);
|
|
107 |
}
|
|
108 |
}
|
|
109 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
|
|
110 |
}
|
|
111 |
|
|
112 |
}
|
fix #6216 Implement color dialog to change color of presence absence
terms