fixes #1041
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / CheckboxComposite.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.forms;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.util.IPropertyChangeListener;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.events.SelectionListener;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21
22 /**
23 * @author n.hoffmann
24 * @created Nov 5, 2009
25 * @version 1.0
26 */
27 public class CheckboxComposite extends AbstractFormComposite implements SelectionListener {
28
29 private static final Logger logger = Logger
30 .getLogger(CheckboxComposite.class);
31
32 private Button checkbox;
33
34 /**
35 *
36 * @param parent
37 * @param label
38 * @param initialState
39 * @param listener
40 * @param style
41 */
42 public CheckboxComposite(Composite parent, String label, boolean initialState,
43 IPropertyChangeListener listener, int style) {
44 super(parent, listener, style);
45
46 checkbox = toolkit.createButton(this, label, SWT.CHECK | style);
47 checkbox.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
48
49 checkbox.setSelection(initialState);
50
51 checkbox.addSelectionListener(this);
52 }
53
54 public void setSelection(boolean selected){
55 checkbox.removeSelectionListener(this);
56 checkbox.setSelection(selected);
57 checkbox.addSelectionListener(this);
58 }
59
60 public boolean getSelection(){
61 return checkbox.getSelection();
62 }
63
64 /* (non-Javadoc)
65 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
66 */
67 public void widgetSelected(SelectionEvent e) {
68 firePropertyChangeEvent(null);
69 }
70
71 public void widgetDefaultSelected(SelectionEvent e) {}
72 }