-// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
import org.eclipse.swt.widgets.Label;
import eu.etaxonomy.taxeditor.preference.Resources;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
/**
* <p>CheckboxElement class.</p>
* @version 1.0
*/
public class CheckboxElement extends AbstractCdmFormElement implements SelectionListener, IEnableableFormElement, ISelectable {
-
- private Button checkbox;
+
+ private final Button checkbox;
private Label label;
-
+
/**
* <p>Constructor for CheckboxElement.</p>
*
protected CheckboxElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString, boolean initialState,
int style) {
super(formFactory, parentElement);
-
+
if(labelString != null){
label = formFactory.createLabel(getLayoutComposite(), labelString);
addControl(label);
}
-
+
checkbox = formFactory.createButton(getLayoutComposite(), null, SWT.CHECK | style);
checkbox.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
-
+
checkbox.setSelection(initialState);
-
+
checkbox.addSelectionListener(this);
addControl(checkbox);
}
checkbox.setSelection(selected);
checkbox.addSelectionListener(this);
}
-
+
/**
* <p>getSelection</p>
*
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
/** {@inheritDoc} */
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
}
-
+
/** {@inheritDoc} */
- public void widgetDefaultSelected(SelectionEvent e) {}
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {}
/** {@inheritDoc} */
- public void setSelected(boolean selected) {
+ @Override
+ public void setSelected(boolean selected) {
setBackground(selected ? SELECTED : getPersistentBackground());
}
/** {@inheritDoc} */
- public void setEnabled(boolean enabled) {
+ @Override
+ public void setEnabled(boolean enabled) {
checkbox.setEnabled(enabled);
+ label.setEnabled(enabled);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ return checkbox.isEnabled();
}
/** {@inheritDoc} */
- public void setIrrelevant(boolean irrelevant) {
+ @Override
+ public void setIrrelevant(boolean irrelevant) {
String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND;
-
+
Color color = getColor(colorId);
setBackground(color);
}
-
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setBackground(org.eclipse.swt.graphics.Color)
*/
@Override
public void setBackground(Color color) {
checkbox.setBackground(color);
- if (label != null) label.setBackground(color);
+ if (label != null) {
+ label.setBackground(color);
+ }
}
}