Project

General

Profile

Revision cf4bd11f

IDcf4bd11fd2a394c795f744111f8b2cbf7f59f7e5
Parent 033aad78
Child 15f5a1bd

Added by Patrick Plitzner almost 3 years ago

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

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
78 78
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
79 79
import eu.etaxonomy.cdm.model.description.KeyStatement;
80 80
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
81
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
81 82
import eu.etaxonomy.cdm.model.description.QuantitativeData;
82 83
import eu.etaxonomy.cdm.model.description.State;
83 84
import eu.etaxonomy.cdm.model.description.StateData;
......
319 320
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionElement;
320 321
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
321 322
import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
323
import eu.etaxonomy.taxeditor.ui.section.vocabulary.PresenceAbsenceTermDetailElement;
322 324
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
323 325
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesElement;
324 326
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionElement;
......
1596 1598
            element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1597 1599
        } else if (definedTermClass.equals(Feature.class)) {
1598 1600
            element = new FeatureDetailElement(this, parentElement);
1601
        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
1602
            element = new PresenceAbsenceTermDetailElement(this, parentElement);
1599 1603
        } else {
1600 1604
            element = new DefinedTermDetailElement(this, parentElement);
1601 1605
        }
1602 1606

  
1607

  
1603 1608
        adapt(element);
1604 1609
        parentElement.addElement(element);
1605 1610
        return element;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/PresenceAbsenceTermDetailElement.java
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
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)