4 package eu
.etaxonomy
.taxeditor
.ui
.forms
;
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
30 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.forms.CdmFormFactory}
48 * @param parentElement
49 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
52 * a {@link java.lang.String} object.
54 * a {@link java.lang.String} object.
56 * a {@link java.lang.Integer} object.
60 protected TextWithLabelElement(CdmFormFactory formFactory
,
61 ICdmFormElement parentElement
, String labelString
,
62 String initialText
, Integer textHeight
, int style
) {
63 super(formFactory
, parentElement
);
65 if (labelString
!= null) {
66 label
= formFactory
.createLabel(getLayoutComposite(),
67 CdmUtils
.Nz(labelString
), SWT
.NULL
);
69 label
.setLayoutData(CdmFormFactory
.LEFT());
72 int scrollStyle
= textHeight
== null ? SWT
.NULL
73 : (SWT
.V_SCROLL
| SWT
.MULTI
);
74 text
= formFactory
.createText(getLayoutComposite(), "", SWT
.BORDER
75 | SWT
.WRAP
| scrollStyle
| style
);
81 if (textHeight
== null) {
82 text
.addKeyListener(new KeyAdapter() {
84 public void keyPressed(KeyEvent e
) {
85 if (e
.character
== SWT
.CR
) {
86 // Don't accept carriage returns as input when in single
89 } else if (e
.character
== SWT
.TAB
) {
90 // traverse is not working for wrapped text widgets so
91 // we reintroduce it here
93 TextWithLabelElement
.this.text
94 .traverse(SWT
.TRAVERSE_TAB_NEXT
);
100 TableWrapData layoutData
= CdmFormFactory
.FILL();
101 if (textHeight
!= null && textHeight
> 0) {
102 (layoutData
).heightHint
= textHeight
;
105 text
.setLayoutData(layoutData
);
107 text
.addModifyListener(this);
109 setText(initialText
);
113 * Get the text of this composites text composite
115 * @return a {@link java.lang.String} object.
117 public String
getText() {
118 return text
.getText();
122 * Set the text of this composites text composite
125 * a {@link java.lang.String} object.
127 public void setText(String string
) {
128 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
130 for (Listener listener
: listeners
) {
131 text
.removeListener(SWT
.Modify
, listener
);
134 text
.setText(CdmUtils
.Nz(string
));
136 for (Listener listener
: listeners
) {
137 text
.addListener(SWT
.Modify
, listener
);
145 * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
149 public void modifyText(ModifyEvent e
) {
150 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
154 public void setSelected(boolean selected
) {
155 setBackground(getColor(selected
));
159 public void setEnabled(boolean enabled
) {
160 text
.setEnabled(enabled
);
161 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
162 : Resources
.COLOR_TEXT_DISABLED
;
163 text
.setForeground(getColor(symbolicName
));
167 public void setIrrelevant(boolean irrelevant
) {
168 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
169 : Resources
.COLOR_COMPOSITE_BACKGROUND
;
171 Color color
= getColor(colorId
);
172 text
.setBackground(color
);
177 public void setBackground(Color color
) {
179 label
.setBackground(color
);
185 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
189 public void setFocus() {
198 * @return a {@link org.eclipse.swt.widgets.Control} object.
200 public Control
getMainControl() {
212 public void setTextLimit(int limit
) {
213 text
.setTextLimit(limit
);