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