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
;
18 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
20 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
23 * <p>CheckboxElement class.</p>
26 * @created Nov 5, 2009
29 public class CheckboxElement
extends AbstractCdmFormElement
implements SelectionListener
, IEnableableFormElement
, ISelectable
{
31 private final Button checkbox
;
36 * <p>Constructor for CheckboxElement.</p>
38 * @param initialState a boolean.
40 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
41 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
42 * @param labelString a {@link java.lang.String} object.
44 protected CheckboxElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
, boolean initialState
,
46 super(formFactory
, parentElement
);
48 if(labelString
!= null){
49 label
= formFactory
.createLabel(getLayoutComposite(), labelString
);
53 checkbox
= formFactory
.createButton(getLayoutComposite(), null, SWT
.CHECK
| style
);
54 checkbox
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
56 checkbox
.setSelection(initialState
);
58 checkbox
.addSelectionListener(this);
65 * @param selected a boolean.
67 public void setSelection(boolean selected
){
68 checkbox
.removeSelectionListener(this);
69 checkbox
.setSelection(selected
);
70 checkbox
.addSelectionListener(this);
78 public boolean getSelection(){
79 return checkbox
.getSelection();
83 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
87 public void widgetSelected(SelectionEvent e
) {
88 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
91 public Button
getMainControl(){
97 public void widgetDefaultSelected(SelectionEvent e
) {}
101 public void setSelected(boolean selected
) {
102 setBackground(selected ? SELECTED
: getPersistentBackground());
107 public void setEnabled(boolean enabled
) {
108 checkbox
.setEnabled(enabled
);
109 label
.setEnabled(enabled
);
113 * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
116 public boolean isEnabled() {
117 return checkbox
.isEnabled();
122 public void setIrrelevant(boolean irrelevant
) {
123 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
125 Color color
= getColor(colorId
);
126 setBackground(color
);
130 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setBackground(org.eclipse.swt.graphics.Color)
134 public void setBackground(Color color
) {
135 if (checkbox
.isDisposed()){
138 checkbox
.setBackground(color
);
140 label
.setBackground(color
);
143 public void setIndent(int indent
){
144 TableWrapData tableWrapData
= (TableWrapData
)label
.getLayoutData();
145 if (tableWrapData
== null){
146 tableWrapData
= new TableWrapData();
149 tableWrapData
.indent
= indent
;
150 label
.setLayoutData(tableWrapData
);
151 getLayoutComposite().layout();