2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.ui
.mvc
.element
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.KeyAdapter
;
13 import org
.eclipse
.swt
.events
.KeyEvent
;
14 import org
.eclipse
.swt
.events
.ModifyEvent
;
15 import org
.eclipse
.swt
.events
.ModifyListener
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
21 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractRelevanceFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
28 import eu
.etaxonomy
.taxeditor
.ui
.mvc
.interfaces
.CdmCompositeController
;
31 * TextWithLabelElement class.
35 public class TextWithLabelElementController
36 extends AbstractRelevanceFormElement
37 implements ModifyListener
, IEnableableFormElement
, ISelectable
, CdmCompositeController
{
40 // private Label label;
42 /** Constant <code>MAX_HEIGHT=0</code> */
43 public static final int MAX_HEIGHT
= 0;
44 /** Constant <code>SINGLE=-1</code> */
45 public static final int SINGLE
= -1;
48 * Constructor for TextWithLabelElement.
50 public TextWithLabelElementController(TextWithLabelElementMVC textWithLabelElement
, CdmFormFactory formFactory
, ICdmFormElement parentElement
,
51 String initialText
, Integer textHeight
, int style
) {
52 super(formFactory
, parentElement
);
54 int scrollStyle
= textHeight
== null ? SWT
.NULL
: (SWT
.V_SCROLL
| SWT
.MULTI
);
56 int combinedStyle
= style
| SWT
.BORDER
| scrollStyle
;
58 // SWT.PASSWORD does not work when SWT.WRAP is set.
59 if (style
!= SWT
.PASSWORD
) {
60 combinedStyle
= combinedStyle
| SWT
.WRAP
;
63 text
= textWithLabelElement
.getText();
67 if (textHeight
== null) {
68 text
.addKeyListener(new KeyAdapter() {
70 public void keyPressed(KeyEvent e
) {
71 if (e
.character
== SWT
.CR
) {
72 // Don't accept carriage returns as input when in single
75 } else if (e
.character
== SWT
.TAB
) {
76 // traverse is not working for wrapped text widgets so
77 // we reintroduce it here
79 TextWithLabelElementController
.this.text
.traverse(SWT
.TRAVERSE_TAB_NEXT
);
85 text
.addModifyListener(this);
89 * Get the text of this composites text composite
91 public String
getText() {
92 return text
.getText();
96 * Set the text of this composites text composite
98 public void setText(String string
) {
99 StoreUtil
.setTextWithoutModifyListeners(text
, string
);
103 public void modifyText(ModifyEvent e
) {
104 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e
));
108 public void setEnabled(boolean enabled
) {
109 text
.setEnabled(enabled
);
110 String symbolicName
= enabled ? Resources
.COLOR_FONT_DEFAULT
: Resources
.COLOR_TEXT_DISABLED
;
111 text
.setForeground(getColor(symbolicName
));
115 public boolean isEnabled() {
116 return text
.isEnabled();
120 public void updateCacheRelevance() {
121 Color color
= cacheRelevance().getColor();
122 text
.setBackground(color
);
126 public void setBackground(Color color
) {
127 // if (label != null) {
128 // label.setBackground(color);
133 public void setSelected(boolean selected
) {
134 setBackground(selected ? SELECTED
: getPersistentBackground());
138 public void setFocus() {
145 public Control
getMainControl() {
152 public void setTextLimit(int limit
) {
153 text
.setTextLimit(limit
);