blob: e7e2d6a180f9c81023e6d99ef1a34007ddfb6e38 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.widgets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
/**
* @author Donald G. Dunne
*/
public class XCheckBox extends XButtonCommon {
protected Button checkButton;
private Composite parent;
private boolean labelAfter = true;
public XCheckBox(String displayLabel) {
super(displayLabel);
}
@Override
public Control getControl() {
return checkButton;
}
@Override
public void setEditable(boolean editable) {
super.setEditable(editable);
if (getControl() != null && !getControl().isDisposed()) {
getControl().setEnabled(editable);
}
}
/**
* Create Check Widgets. Widgets Created: Label: "text entry" horizonatalSpan takes up 2 columns; horizontalSpan must
* be >=2
*/
@Override
protected void createControls(Composite parent, int horizontalSpan) {
if (horizontalSpan < 2) {
horizontalSpan = 2;
}
this.parent = parent;
// Create Text Widgets
if (!labelAfter) {
labelWidget = new Label(parent, SWT.NONE);
labelWidget.setText(getLabel() + ":");
}
checkButton = new Button(parent, SWT.CHECK);
GridData gd2 = new GridData(GridData.BEGINNING);
checkButton.setLayoutData(gd2);
checkButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
selected = checkButton.getSelection();
validate();
notifyXModifiedListeners();
}
});
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gd.horizontalSpan = horizontalSpan - 1;
if (labelAfter) {
labelWidget = new Label(parent, SWT.NONE);
labelWidget.setText(getLabel());
}
if (getToolTip() != null) {
labelWidget.setToolTipText(getToolTip());
}
checkButton.setLayoutData(gd);
updateCheckWidget();
checkButton.setEnabled(isEditable());
}
@Override
public void dispose() {
labelWidget.dispose();
checkButton.dispose();
if (parent != null && !parent.isDisposed()) {
parent.layout();
}
}
public void addSelectionListener(SelectionListener selectionListener) {
checkButton.addSelectionListener(selectionListener);
}
public boolean isChecked() {
if (checkButton == null || checkButton.isDisposed()) {
return selected;
} else {
return checkButton.getSelection();
}
}
private void updateCheckWidget() {
if (checkButton != null && !checkButton.isDisposed()) {
checkButton.setSelection(selected);
}
validate();
}
/**
* If set, label will be displayed after the check box NOTE: Has to be set before call to createWidgets
*
* @param labelAfter The labelAfter to set.
*/
public void setLabelAfter(boolean labelAfter) {
this.labelAfter = labelAfter;
}
public Button getCheckButton() {
return checkButton;
}
}
|