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
, ISelectable
{
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
);
75 int combinedStyle
= style
| SWT
.BORDER
| scrollStyle
;
77 //SWT.PASSWORD does not work when SWT.WRAP is set.
78 if(style
!= SWT
.PASSWORD
){
79 combinedStyle
= combinedStyle
| SWT
.WRAP
;
82 text
= formFactory
.createText(getLayoutComposite(), "", combinedStyle
);
88 if (textHeight
== null) {
89 text
.addKeyListener(new KeyAdapter() {
91 public void keyPressed(KeyEvent e
) {
92 if (e
.character
== SWT
.CR
) {
93 // Don't accept carriage returns as input when in single
96 } else if (e
.character
== SWT
.TAB
) {
97 // traverse is not working for wrapped text widgets so
98 // we reintroduce it here
100 TextWithLabelElement
.this.text
101 .traverse(SWT
.TRAVERSE_TAB_NEXT
);
107 TableWrapData layoutData
= CdmFormFactory
.FILL();
108 if (textHeight
!= null && textHeight
> 0) {
109 (layoutData
).heightHint
= textHeight
;
112 text
.setLayoutData(layoutData
);
114 text
.addModifyListener(this);
116 setText(initialText
);
120 * Get the text of this composites text composite
122 * @return a {@link java.lang.String} object.
124 public String
getText() {
125 return text
.getText();
129 * Set the text of this composites text composite
132 * a {@link java.lang.String} object.
134 public void setText(String string
) {
135 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
137 for (Listener listener
: listeners
) {
138 text
.removeListener(SWT
.Modify
, listener
);
141 text
.setText(CdmUtils
.Nz(string
));
143 for (Listener listener
: listeners
) {
144 text
.addListener(SWT
.Modify
, listener
);
152 * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
156 public void modifyText(ModifyEvent e
) {
157 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
161 public void setEnabled(boolean enabled
) {
162 text
.setEnabled(enabled
);
163 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
164 : Resources
.COLOR_TEXT_DISABLED
;
165 text
.setForeground(getColor(symbolicName
));
169 public void setIrrelevant(boolean irrelevant
) {
170 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
171 : Resources
.COLOR_COMPOSITE_BACKGROUND
;
173 Color color
= getColor(colorId
);
174 text
.setBackground(color
);
179 public void setBackground(Color color
) {
181 label
.setBackground(color
);
185 public void setSelected(boolean selected
) {
186 setBackground(selected ? SELECTED
: getPersistentBackground());
192 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
196 public void setFocus() {
205 * @return a {@link org.eclipse.swt.widgets.Control} object.
207 public Control
getMainControl() {
219 public void setTextLimit(int limit
) {
220 text
.setTextLimit(limit
);