4 package eu
.etaxonomy
.taxeditor
.ui
.element
;
6 import org
.eclipse
.swt
.SWT
;
7 import org
.eclipse
.swt
.events
.KeyAdapter
;
8 import org
.eclipse
.swt
.events
.KeyEvent
;
9 import org
.eclipse
.swt
.events
.ModifyEvent
;
10 import org
.eclipse
.swt
.events
.ModifyListener
;
11 import org
.eclipse
.swt
.graphics
.Color
;
12 import org
.eclipse
.swt
.widgets
.Control
;
13 import org
.eclipse
.swt
.widgets
.Label
;
14 import org
.eclipse
.swt
.widgets
.Listener
;
15 import org
.eclipse
.swt
.widgets
.Text
;
16 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
23 * TextWithLabelElement class.
29 public class TextWithLabelElement
extends AbstractCdmFormElement
implements ModifyListener
, IEnableableFormElement
,
35 /** Constant <code>MAX_HEIGHT=0</code> */
36 public static final int MAX_HEIGHT
= 0;
37 /** Constant <code>SINGLE=-1</code> */
38 public static final int SINGLE
= -1;
42 * Constructor for TextWithLabelElement.
46 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
48 * @param parentElement
49 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
52 * a {@link java.lang.String} object.
54 * a {@link java.lang.String} object.
56 * a {@link java.lang.Integer} object.
59 * @wbp.parser.entryPoint
61 protected TextWithLabelElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
,
62 String initialText
, Integer textHeight
, int style
) {
63 super(formFactory
, parentElement
);
65 if (labelString
!= null) {
66 label
= formFactory
.createLabel(getLayoutComposite(), CdmUtils
.Nz(labelString
), SWT
.NULL
);
68 label
.setLayoutData(LayoutConstants
.LEFT());
71 int scrollStyle
= textHeight
== null ? SWT
.NULL
: (SWT
.V_SCROLL
| SWT
.MULTI
);
73 int combinedStyle
= style
| SWT
.BORDER
| scrollStyle
;
75 // SWT.PASSWORD does not work when SWT.WRAP is set.
76 if (style
!= SWT
.PASSWORD
) {
77 combinedStyle
= combinedStyle
| SWT
.WRAP
;
80 text
= formFactory
.createText(getLayoutComposite(), "", combinedStyle
);
86 if (textHeight
== null) {
87 text
.addKeyListener(new KeyAdapter() {
89 public void keyPressed(KeyEvent e
) {
90 if (e
.character
== SWT
.CR
) {
91 // Don't accept carriage returns as input when in single
94 } else if (e
.character
== SWT
.TAB
) {
95 // traverse is not working for wrapped text widgets so
96 // we reintroduce it here
98 TextWithLabelElement
.this.text
.traverse(SWT
.TRAVERSE_TAB_NEXT
);
104 TableWrapData layoutData
= LayoutConstants
.FILL();
105 if (textHeight
!= null && textHeight
> 0) {
106 (layoutData
).heightHint
= textHeight
;
109 text
.setLayoutData(layoutData
);
111 text
.addModifyListener(this);
113 setText(initialText
);
117 * Get the text of this composites text composite
119 * @return a {@link java.lang.String} object.
121 public String
getText() {
122 return text
.getText();
126 * Set the text of this composites text composite
129 * a {@link java.lang.String} object.
131 public void setText(String string
) {
132 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
134 for (Listener listener
: listeners
) {
135 text
.removeListener(SWT
.Modify
, listener
);
138 text
.setText(CdmUtils
.Nz(string
));
140 for (Listener listener
: listeners
) {
141 text
.addListener(SWT
.Modify
, listener
);
149 * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
154 public void modifyText(ModifyEvent e
) {
155 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
160 public void setEnabled(boolean enabled
) {
161 text
.setEnabled(enabled
);
162 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
: Resources
.COLOR_TEXT_DISABLED
;
163 text
.setForeground(getColor(symbolicName
));
168 public void setIrrelevant(boolean irrelevant
) {
169 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
171 Color color
= getColor(colorId
);
172 text
.setBackground(color
);
177 public void setBackground(Color color
) {
179 label
.setBackground(color
);
184 public void setSelected(boolean selected
) {
185 setBackground(selected ? SELECTED
: getPersistentBackground());
191 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
195 public void setFocus() {
204 * @return a {@link org.eclipse.swt.widgets.Control} object.
206 public Control
getMainControl() {
218 public void setTextLimit(int limit
) {
219 text
.setTextLimit(limit
);