1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.ui.element;
|
5
|
|
6
|
import org.eclipse.swt.SWT;
|
7
|
import org.eclipse.swt.events.ModifyEvent;
|
8
|
import org.eclipse.swt.events.ModifyListener;
|
9
|
import org.eclipse.swt.events.SelectionListener;
|
10
|
import org.eclipse.swt.graphics.Color;
|
11
|
import org.eclipse.swt.widgets.Button;
|
12
|
import org.eclipse.swt.widgets.Composite;
|
13
|
import org.eclipse.swt.widgets.Label;
|
14
|
import org.eclipse.swt.widgets.Text;
|
15
|
|
16
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
17
|
|
18
|
/**
|
19
|
* <p>TextActionElement class.</p>
|
20
|
*
|
21
|
* @author nho
|
22
|
*/
|
23
|
public class TextActionElement extends AbstractCdmFormElement implements ModifyListener, ISelectable{
|
24
|
|
25
|
private Label label;
|
26
|
private Text text;
|
27
|
private Button button;
|
28
|
private Composite box;
|
29
|
|
30
|
/**
|
31
|
* <p>Constructor for TextActionElement.</p>
|
32
|
*
|
33
|
* @param style a int.
|
34
|
* @param toolkit a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
35
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
36
|
* @param labelString a {@link java.lang.String} object.
|
37
|
* @param buttonLabel a {@link java.lang.String} object.
|
38
|
* @param initialText a {@link java.lang.String} object.
|
39
|
*/
|
40
|
protected TextActionElement(CdmFormFactory toolkit, ICdmFormElement parentElement, String labelString, String buttonLabel, String initialText, int style) {
|
41
|
super(toolkit, parentElement);
|
42
|
|
43
|
label = toolkit.createLabel(getLayoutComposite(), labelString, SWT.WRAP);
|
44
|
addControl(label);
|
45
|
|
46
|
box = formFactory.createComposite(getLayoutComposite());
|
47
|
box.setLayout(LayoutConstants.LAYOUT(2, false));
|
48
|
box.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
49
|
addControl(box);
|
50
|
|
51
|
text = toolkit.createText(box, "", style);
|
52
|
addControl(text);
|
53
|
text.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
|
54
|
|
55
|
setText(CdmUtils.Nz(initialText));
|
56
|
|
57
|
button = toolkit.createButton(box, buttonLabel, SWT.PUSH);
|
58
|
addControl(button);
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* <p>Setter for the field <code>text</code>.</p>
|
63
|
*
|
64
|
* @param string a {@link java.lang.String} object.
|
65
|
*/
|
66
|
public void setText(String string) {
|
67
|
text.setText(CdmUtils.Nz(string));
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* <p>Getter for the field <code>text</code>.</p>
|
72
|
*
|
73
|
* @return the text
|
74
|
*/
|
75
|
public String getText() {
|
76
|
return text.getText();
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* <p>addSelectionListener</p>
|
81
|
*
|
82
|
* @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
|
83
|
*/
|
84
|
public void addSelectionListener(SelectionListener listener){
|
85
|
button.addSelectionListener(listener);
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* <p>removeSelectionListener</p>
|
90
|
*
|
91
|
* @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
|
92
|
*/
|
93
|
public void removeSelectionListener(SelectionListener listener){
|
94
|
button.removeSelectionListener(listener);
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
public void modifyText(ModifyEvent e) {
|
99
|
propertyChange(null);
|
100
|
}
|
101
|
|
102
|
/**
|
103
|
* <p>addModifyListener</p>
|
104
|
*
|
105
|
* @param listener a {@link org.eclipse.swt.events.ModifyListener} object.
|
106
|
*/
|
107
|
public void addModifyListener(ModifyListener listener){
|
108
|
text.addModifyListener(listener);
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* <p>removeModifyListener</p>
|
113
|
*
|
114
|
* @param listener a {@link org.eclipse.swt.events.ModifyListener} object.
|
115
|
*/
|
116
|
public void removeModifyListener(ModifyListener listener){
|
117
|
text.removeModifyListener(listener);
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public void setBackground(Color color) {
|
122
|
label.setBackground(color);
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public void setSelected(boolean selected) {
|
127
|
setBackground(selected ? SELECTED : getPersistentBackground());
|
128
|
}
|
129
|
}
|