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
;
22 * <p>TextWithLabelElement class.</p>
27 public class TextWithLabelElement
extends AbstractCdmFormElement
implements ModifyListener
, IEnableableFormElement
{
32 /** Constant <code>MAX_HEIGHT=0</code> */
33 public static final int MAX_HEIGHT
= 0;
34 /** Constant <code>SINGLE=-1</code> */
35 public static final int SINGLE
= -1;
38 * <p>Constructor for TextWithLabelElement.</p>
40 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
41 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
42 * @param labelString a {@link java.lang.String} object.
43 * @param initialText a {@link java.lang.String} object.
44 * @param textHeight a {@link java.lang.Integer} object.
47 protected TextWithLabelElement(CdmFormFactory formFactory
, ICdmFormElement parentElement
, String labelString
, String initialText
, Integer textHeight
, int style
)
49 super(formFactory
, parentElement
);
51 if(labelString
!= null && ! labelString
.equals("")){
52 label
= formFactory
.createLabel(getLayoutComposite(), CdmUtils
.Nz(labelString
), SWT
.NULL
);
54 label
.setLayoutData(CdmFormFactory
.LEFT());
57 int scrollStyle
= textHeight
== null ? SWT
.NULL
: (SWT
.V_SCROLL
| SWT
.MULTI
);
58 text
= formFactory
.createText(getLayoutComposite(), "", SWT
.BORDER
| SWT
.WRAP
| scrollStyle
);
64 if(textHeight
== null){
65 text
.addKeyListener( new KeyAdapter(){
67 public void keyPressed(KeyEvent e
) {
68 if(e
.character
== SWT
.CR
){
69 // Don't accept carriage returns as input when in single line mode
71 }else if(e
.character
== SWT
.TAB
){
72 // traverse is not working for wrapped text widgets so
73 // we reintroduce it here
75 TextWithLabelElement
.this.text
.traverse(SWT
.TRAVERSE_TAB_NEXT
);
81 TableWrapData layoutData
= CdmFormFactory
.FILL();
82 if (textHeight
!= null && textHeight
> 0){
83 ((TableWrapData
) layoutData
).heightHint
= textHeight
;
86 text
.setLayoutData(layoutData
);
88 text
.addModifyListener(this);
94 * Get the text of this composites text composite
96 * @return a {@link java.lang.String} object.
98 public String
getText() {
99 return text
.getText();
103 * Set the text of this composites text composite
105 * @param string a {@link java.lang.String} object.
107 public void setText(String string
) {
108 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
110 for(Listener listener
: listeners
){
111 text
.removeListener(SWT
.Modify
, listener
);
114 text
.setText(CdmUtils
.Nz(string
));
116 for(Listener listener
: listeners
){
117 text
.addListener(SWT
.Modify
, listener
);
122 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
125 public void modifyText(ModifyEvent e
) {
126 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
130 public void setSelected(boolean selected
) {
131 setBackground(getColor(selected
));
135 public void setEnabled(boolean enabled
) {
136 text
.setEnabled(enabled
);
137 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
: Resources
.COLOR_TEXT_DISABLED
;
138 text
.setForeground(getColor(symbolicName
));
142 public void setIrrelevant(boolean irrelevant
) {
143 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
145 Color color
= getColor(colorId
);
146 text
.setBackground(color
);
151 public void setBackground(Color color
) {
153 label
.setBackground(color
);
157 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
161 public void setFocus() {
166 * <p>getMainControl</p>
168 * @return a {@link org.eclipse.swt.widgets.Control} object.
170 public Control
getMainControl() {
175 * <p>setTextLimit</p>
177 * @param limit a int.
179 public void setTextLimit(int limit
) {
180 text
.setTextLimit(limit
);