4 package eu
.etaxonomy
.taxeditor
.ui
.mvc
.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
.Listener
;
14 import org
.eclipse
.swt
.widgets
.Text
;
16 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
17 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
18 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
19 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
24 import eu
.etaxonomy
.taxeditor
.ui
.mvc
.interfaces
.CdmCompositeController
;
28 * TextWithLabelElement class.
34 public class TextWithLabelElementController
extends AbstractCdmFormElement
implements ModifyListener
, IEnableableFormElement
,
35 ISelectable
, CdmCompositeController
{
38 // private Label label;
40 /** Constant <code>MAX_HEIGHT=0</code> */
41 public static final int MAX_HEIGHT
= 0;
42 /** Constant <code>SINGLE=-1</code> */
43 public static final int SINGLE
= -1;
47 * Constructor for TextWithLabelElement.
51 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
53 * @param parentElement
54 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 * a {@link java.lang.String} object.
59 * a {@link java.lang.String} object.
61 * a {@link java.lang.Integer} object.
64 * @wbp.parser.entryPoint
66 public TextWithLabelElementController(TextWithLabelElementMVC textWithLabelElement
, CdmFormFactory formFactory
, ICdmFormElement parentElement
,
67 String initialText
, Integer textHeight
, int style
) {
68 super(formFactory
, parentElement
);
70 int scrollStyle
= textHeight
== null ? SWT
.NULL
: (SWT
.V_SCROLL
| SWT
.MULTI
);
72 int combinedStyle
= style
| SWT
.BORDER
| scrollStyle
;
74 // SWT.PASSWORD does not work when SWT.WRAP is set.
75 if (style
!= SWT
.PASSWORD
) {
76 combinedStyle
= combinedStyle
| SWT
.WRAP
;
79 text
= textWithLabelElement
.getText();
83 if (textHeight
== null) {
84 text
.addKeyListener(new KeyAdapter() {
86 public void keyPressed(KeyEvent e
) {
87 if (e
.character
== SWT
.CR
) {
88 // Don't accept carriage returns as input when in single
91 } else if (e
.character
== SWT
.TAB
) {
92 // traverse is not working for wrapped text widgets so
93 // we reintroduce it here
95 TextWithLabelElementController
.this.text
.traverse(SWT
.TRAVERSE_TAB_NEXT
);
101 text
.addModifyListener(this);
105 * Get the text of this composites text composite
107 * @return a {@link java.lang.String} object.
109 public String
getText() {
110 return text
.getText();
114 * Set the text of this composites text composite
117 * a {@link java.lang.String} object.
119 public void setText(String string
) {
120 Listener
[] listeners
= text
.getListeners(SWT
.Modify
);
122 for (Listener listener
: listeners
) {
123 text
.removeListener(SWT
.Modify
, listener
);
126 text
.setText(CdmUtils
.Nz(string
));
128 for (Listener listener
: listeners
) {
129 text
.addListener(SWT
.Modify
, listener
);
137 * org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events
142 public void modifyText(ModifyEvent e
) {
143 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
148 public void setEnabled(boolean enabled
) {
149 text
.setEnabled(enabled
);
150 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
: Resources
.COLOR_TEXT_DISABLED
;
151 text
.setForeground(getColor(symbolicName
));
155 * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
158 public boolean isEnabled() {
159 return text
.isEnabled();
164 public void setIrrelevant(boolean irrelevant
) {
165 String colorId
= irrelevant ? Resources
.COLOR_COMPOSITE_IRRELEVANT
: Resources
.COLOR_COMPOSITE_BACKGROUND
;
167 Color color
= getColor(colorId
);
168 text
.setBackground(color
);
173 public void setBackground(Color color
) {
174 // if (label != null) {
175 // label.setBackground(color);
180 public void setSelected(boolean selected
) {
181 setBackground(selected ? SELECTED
: getPersistentBackground());
187 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#setFocus()
191 public void setFocus() {
200 * @return a {@link org.eclipse.swt.widgets.Control} object.
202 public Control
getMainControl() {
214 public void setTextLimit(int limit
) {
215 text
.setTextLimit(limit
);