~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/preferences/StringWithBooleanFieldEditor.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     Wind River Systems - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.dsf.debug.internal.ui.preferences;
 
12
 
 
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;
 
20
 
 
21
/**
 
22
 * A string field editor with an enablement check box.
 
23
 */
 
24
public class StringWithBooleanFieldEditor extends DecoratingStringFieldEditor {
 
25
 
 
26
        private final String fEnableKey;
 
27
        private Button fCheckbox;
 
28
        private boolean fWasSelected;
 
29
 
 
30
        public StringWithBooleanFieldEditor(String enableKey, String nameKey, String labelText, Composite parent) {
 
31
                super(nameKey, labelText, parent);
 
32
                fEnableKey= enableKey;
 
33
        }
 
34
 
 
35
        public StringWithBooleanFieldEditor(String enableKey, String nameKey, String labelText, int width, Composite parent) {
 
36
                super(nameKey, labelText, width, parent);
 
37
                fEnableKey= enableKey;
 
38
        }
 
39
 
 
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;
 
43
        }
 
44
        
 
45
        @Override
 
46
        protected void doFillIntoGrid(Composite parent, int numColumns) {
 
47
                getCheckboxControl(parent);
 
48
                super.doFillIntoGrid(parent, numColumns);
 
49
        }
 
50
 
 
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() {
 
65
                                @Override
 
66
                                public void widgetSelected(SelectionEvent e) {
 
67
                    boolean isSelected = fCheckbox.getSelection();
 
68
                    valueChanged(fWasSelected, isSelected);
 
69
                    fWasSelected = isSelected;
 
70
                                }
 
71
                        });
 
72
                } else {
 
73
                        checkParent(fCheckbox.getParent(), parent);
 
74
                }
 
75
                return fCheckbox;
 
76
        }
 
77
 
 
78
        @Override
 
79
        public Label getLabelControl(Composite parent) {
 
80
                final Label label= getLabelControl();
 
81
                if (label == null) {
 
82
                        return super.getLabelControl(parent);
 
83
                } else {
 
84
                        checkParent(label.getParent(), parent);
 
85
                }
 
86
                return label;
 
87
        }
 
88
 
 
89
        protected void valueChanged(boolean oldValue, boolean newValue) {
 
90
        if (oldValue != newValue) {
 
91
                valueChanged();
 
92
                        fireStateChanged(VALUE, oldValue, newValue);
 
93
                getTextControl().setEnabled(newValue);
 
94
                getLabelControl().setEnabled(newValue);
 
95
                }
 
96
        }
 
97
 
 
98
        @Override
 
99
        protected boolean checkState() {
 
100
                if (fCheckbox != null && !fCheckbox.getSelection()) {
 
101
                        clearErrorMessage();
 
102
                        return true;
 
103
                }
 
104
                return super.checkState();
 
105
        }
 
106
 
 
107
        @Override
 
108
        protected void doLoad() {
 
109
                super.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);
 
116
        }
 
117
        }
 
118
 
 
119
        @Override
 
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);
 
128
        }
 
129
        }
 
130
 
 
131
    @Override
 
132
        protected void doStore() {
 
133
        super.doStore();
 
134
        getPreferenceStore().setValue(fEnableKey, fCheckbox.getSelection());
 
135
    }
 
136
 
 
137
    /**
 
138
     * Returns this field editor's current boolean value.
 
139
     *
 
140
     * @return the value
 
141
     */
 
142
    public boolean getBooleanValue() {
 
143
        return fCheckbox.getSelection();
 
144
    }
 
145
 
 
146
}