3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.vocabulary
;
12 import java
.text
.ParseException
;
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
;
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
;
35 public class PresenceAbsenceTermDetailElement
extends DefinedTermDetailElement
<PresenceAbsenceTerm
> implements MouseListener
{
37 private Label colorLabel
;
41 public PresenceAbsenceTermDetailElement(CdmFormFactory formFactory
,
42 ICdmFormElement formElement
) {
43 super(formFactory
, formElement
);
47 protected void createControls(ICdmFormElement formElement
, PresenceAbsenceTerm entity
, int style
) {
48 super.createControls(formElement
, entity
, style
);
50 Label colorTextLabel
= new Label(getLayoutComposite(), style
);
51 colorTextLabel
.setText("Color");
52 colorLabel
= new Label(getLayoutComposite(), style
);
53 colorLabel
.addMouseListener(this);
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
);
65 public void handleEvent(Object eventSource
) {
66 super.handleEvent(eventSource
);
70 public TermVocabulary
getVocabulary() {
71 return getEntity() != null ?
getEntity().getVocabulary() : null;
78 public void mouseDoubleClick(MouseEvent e
) {
86 public void mouseDown(MouseEvent e
) {
93 public void mouseUp(MouseEvent e
) {
94 ColorDialog dialog
= new ColorDialog(AbstractUtility
.getShell());
96 dialog
.setRGB(color
.getRGB());
98 RGB rgb
= dialog
.open();
103 color
= new Color(AbstractUtility
.getShell().getDisplay(), rgb
);
104 colorLabel
.setBackground(color
);
106 String hexCode
= String
.format("%02x%02x%02x", rgb
.red
,rgb
.green
,rgb
.blue
);
107 getEntity().setDefaultColor(hexCode
);
108 } catch (ParseException pe
) {
109 MessagingUtils
.error(PresenceAbsenceTermDetailElement
.class, "Color could not be set", pe
);
112 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));