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