1
/*******************************************************************************
2
* Copyright (c) 2008, 2009 Wind River Systems, Inc. and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Wind River Systems - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.dsf.debug.internal.ui.preferences;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.events.SelectionAdapter;
15
import org.eclipse.swt.events.SelectionEvent;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Label;
22
* A string field editor with an enablement check box.
24
public class StringWithBooleanFieldEditor extends DecoratingStringFieldEditor {
26
private final String fEnableKey;
27
private Button fCheckbox;
28
private boolean fWasSelected;
30
public StringWithBooleanFieldEditor(String enableKey, String nameKey, String labelText, Composite parent) {
31
super(nameKey, labelText, parent);
32
fEnableKey= enableKey;
35
public StringWithBooleanFieldEditor(String enableKey, String nameKey, String labelText, int width, Composite parent) {
36
super(nameKey, labelText, width, parent);
37
fEnableKey= enableKey;
40
public StringWithBooleanFieldEditor(String enableKey, String nameKey, String labelText, int width, int strategy, Composite parent) {
41
super(nameKey, labelText, width, strategy, parent);
42
fEnableKey= enableKey;
46
protected void doFillIntoGrid(Composite parent, int numColumns) {
47
getCheckboxControl(parent);
48
super.doFillIntoGrid(parent, numColumns);
51
private Button getCheckboxControl(Composite parent) {
52
if (fCheckbox == null) {
53
Composite inner= new Composite(parent, SWT.NULL);
54
final GridLayout layout= new GridLayout(2, false);
55
layout.marginWidth = 0;
56
inner.setLayout(layout);
57
fCheckbox= new Button(inner, SWT.CHECK);
58
fCheckbox.setFont(parent.getFont());
59
fCheckbox.setText(getLabelText());
60
// create and hide label from base class
61
Label label = getLabelControl(inner);
62
label.setText(""); //$NON-NLS-1$
63
label.setVisible(false);
64
fCheckbox.addSelectionListener(new SelectionAdapter() {
66
public void widgetSelected(SelectionEvent e) {
67
boolean isSelected = fCheckbox.getSelection();
68
valueChanged(fWasSelected, isSelected);
69
fWasSelected = isSelected;
73
checkParent(fCheckbox.getParent(), parent);
79
public Label getLabelControl(Composite parent) {
80
final Label label= getLabelControl();
82
return super.getLabelControl(parent);
84
checkParent(label.getParent(), parent);
89
protected void valueChanged(boolean oldValue, boolean newValue) {
90
if (oldValue != newValue) {
92
fireStateChanged(VALUE, oldValue, newValue);
93
getTextControl().setEnabled(newValue);
94
getLabelControl().setEnabled(newValue);
99
protected boolean checkState() {
100
if (fCheckbox != null && !fCheckbox.getSelection()) {
104
return super.checkState();
108
protected void doLoad() {
110
if (fCheckbox != null) {
111
boolean value = getPreferenceStore().getBoolean(fEnableKey);
112
fCheckbox.setSelection(value);
113
fWasSelected = value;
114
getTextControl().setEnabled(value);
115
getLabelControl().setEnabled(value);
120
protected void doLoadDefault() {
121
super.doLoadDefault();
122
if (fCheckbox != null) {
123
boolean value = getPreferenceStore().getDefaultBoolean(fEnableKey);
124
fCheckbox.setSelection(value);
125
fWasSelected = value;
126
getTextControl().setEnabled(value);
127
getLabelControl().setEnabled(value);
132
protected void doStore() {
134
getPreferenceStore().setValue(fEnableKey, fCheckbox.getSelection());
138
* Returns this field editor's current boolean value.
142
public boolean getBooleanValue() {
143
return fCheckbox.getSelection();