2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
15 import org
.eclipse
.swt
.graphics
.Color
;
16 import org
.eclipse
.swt
.widgets
.Button
;
17 import org
.eclipse
.swt
.widgets
.Label
;
19 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
22 * <p>CheckboxElement class.</p>
25 * @created Nov 5, 2009
28 public class CheckboxElement
extends AbstractCdmFormElement
implements SelectionListener
, IEnableableFormElement
, ISelectable
{
30 private final Button checkbox
;
35 * <p>Constructor for CheckboxElement.</p>
37 * @param initialState a boolean.
39 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
40 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
41 * @param labelString a {@link java.lang.String} object.
43 protected CheckboxElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
, boolean initialState
,
45 super(formFactory
, parentElement
);
47 if(labelString
!= null){
48 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
52 checkbox
= formFactory
.createButton(getLayoutComposite(), null, SWT
.CHECK
| style
);
53 checkbox
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
55 checkbox
.setSelection(initialState
);
57 checkbox
.addSelectionListener(this);
64 * @param selected a boolean.
66 public void setSelection(boolean selected
){
67 checkbox
.removeSelectionListener(this);
68 checkbox
.setSelection(selected
);
69 checkbox
.addSelectionListener(this);
77 public boolean getSelection(){
78 return checkbox
.getSelection();
82 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
86 public void widgetSelected(SelectionEvent e
) {
87 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
92 public void widgetDefaultSelected(SelectionEvent e
) {}
96 public void setSelected(boolean selected
) {
97 setBackground(selected ? SELECTED
: getPersistentBackground());
102 public void setEnabled(boolean enabled
) {
103 checkbox
.setEnabled(enabled
);
104 label
.setEnabled(enabled
);
108 * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
111 public boolean isEnabled() {
112 return checkbox
.isEnabled();
117 public void setIrrelevant(boolean irrelevant
) {
118 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
120 Color color
= getColor(colorId
);
121 setBackground(color
);
125 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setBackground(org.eclipse.swt.graphics.Color)
129 public void setBackground(Color color
) {
130 checkbox
.setBackground(color
);
132 label
.setBackground(color
);