commit cf4bd11fd2a394c795f744111f8b2cbf7f59f7e5
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Thu Nov 24 10:22:05 2016 +0100

    fix #6216 Implement color dialog to change color of presence absence
    terms

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
index 5d7f94576..f3a4a7481 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
@@ -78,6 +78,7 @@ import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.model.description.State;
 import eu.etaxonomy.cdm.model.description.StateData;
@@ -319,6 +320,7 @@ import eu.etaxonomy.taxeditor.ui.section.vocabulary.FeatureDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.vocabulary.PresenceAbsenceTermDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesElement;
 import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionElement;
@@ -1596,10 +1598,13 @@ public class CdmFormFactory extends FormToolkit {
             element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
         } else if (definedTermClass.equals(Feature.class)) {
             element = new FeatureDetailElement(this, parentElement);
+        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
+            element = new PresenceAbsenceTermDetailElement(this, parentElement);
         } else {
             element = new DefinedTermDetailElement(this, parentElement);
         }
 
+
         adapt(element);
         parentElement.addElement(element);
         return element;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/PresenceAbsenceTermDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/PresenceAbsenceTermDetailElement.java
new file mode 100644
index 000000000..0389233aa
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/PresenceAbsenceTermDetailElement.java
@@ -0,0 +1,112 @@
+// $Id$
+/**
+* Copyright (C) 2009 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.section.vocabulary;
+
+import java.text.ParseException;
+
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.ColorDialog;
+import org.eclipse.swt.widgets.Label;
+
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+
+/**
+ *
+ * @author pplitzner
+ * @date Nov 24, 2016
+ *
+ */
+public class PresenceAbsenceTermDetailElement extends DefinedTermDetailElement<PresenceAbsenceTerm> implements MouseListener{
+
+    private Label colorLabel;
+
+    private Color color;
+
+	public PresenceAbsenceTermDetailElement(CdmFormFactory formFactory,
+			ICdmFormElement formElement) {
+		super(formFactory, formElement);
+	}
+
+	@Override
+    protected void createControls(ICdmFormElement formElement, PresenceAbsenceTerm entity, int style) {
+	    super.createControls(formElement, entity, style);
+
+	    Label colorTextLabel = new Label(getLayoutComposite(), style);
+	    colorTextLabel.setText("Color");
+	    colorLabel = new Label(getLayoutComposite(), style);
+	    colorLabel.addMouseListener(this);
+
+	    String defaultColor = entity.getDefaultColor();
+	    if(defaultColor!=null){
+	        java.awt.Color awtColor = java.awt.Color.decode("#"+defaultColor);
+            RGB rgb = new RGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
+	        color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
+	        colorLabel.setBackground(color);
+	    }
+	}
+
+	@Override
+	public void handleEvent(Object eventSource) {
+	    super.handleEvent(eventSource);
+	}
+
+	@Override
+	public TermVocabulary getVocabulary() {
+		return getEntity() != null ? getEntity().getVocabulary() : null;
+	}
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void mouseDoubleClick(MouseEvent e) {
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void mouseDown(MouseEvent e) {
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void mouseUp(MouseEvent e) {
+        ColorDialog dialog = new ColorDialog(AbstractUtility.getShell());
+        RGB rgb = dialog.open();
+        if(rgb!=null){
+            if(color!=null){
+                color.dispose();
+            }
+            color = new Color(AbstractUtility.getShell().getDisplay(), rgb);
+            colorLabel.setBackground(color);
+            try {
+                String hexCode = String.format("%02x%02x%02x", rgb.red,rgb.green,rgb.blue);
+                getEntity().setDefaultColor(hexCode);
+            } catch (ParseException pe) {
+                MessagingUtils.error(PresenceAbsenceTermDetailElement.class, "Color could not be set", pe);
+            }
+        }
+        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
+    }
+
+}
