]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ui/widgets/EditableText.java
1 package org
.argeo
.cms
.ui
.widgets
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.events
.FocusEvent
;
9 import org
.eclipse
.swt
.events
.FocusListener
;
10 import org
.eclipse
.swt
.layout
.GridData
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Control
;
13 import org
.eclipse
.swt
.widgets
.Label
;
14 import org
.eclipse
.swt
.widgets
.Text
;
16 /** Editable text part displaying styled text. */
17 public class EditableText
extends StyledControl
{
18 private static final long serialVersionUID
= -6372283442330912755L;
20 private boolean editable
= true;
22 public EditableText(Composite parent
, int style
) {
24 editable
= !(SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
));
27 public EditableText(Composite parent
, int style
, Item item
) throws RepositoryException
{
28 this(parent
, style
, item
, false);
31 public EditableText(Composite parent
, int style
, Item item
, boolean cacheImmediately
) throws RepositoryException
{
32 super(parent
, style
, item
, cacheImmediately
);
33 editable
= !(SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
));
37 protected Control
createControl(Composite box
, String style
) {
38 if (isEditing() && getEditable()) {
39 return createText(box
, style
, true);
41 // return createText(box, style, false);
42 return createLabel(box
, style
);
46 protected Label
createLabel(Composite box
, String style
) {
47 Label lbl
= new Label(box
, getStyle() | SWT
.WRAP
);
48 lbl
.setLayoutData(CmsUiUtils
.fillWidth());
49 CmsUiUtils
.style(lbl
, style
);
50 CmsUiUtils
.markup(lbl
);
51 if (mouseListener
!= null)
52 lbl
.addMouseListener(mouseListener
);
56 protected Text
createText(Composite box
, String style
, boolean editable
) {
57 final Text text
= new Text(box
, getStyle() | SWT
.MULTI
| SWT
.WRAP
);
58 text
.setEditable(editable
);
59 GridData textLayoutData
= CmsUiUtils
.fillWidth();
60 // textLayoutData.heightHint = preferredHeight;
61 text
.setLayoutData(textLayoutData
);
62 CmsUiUtils
.style(text
, style
);
67 public void setText(String text
) {
68 Control child
= getControl();
69 if (child
instanceof Label
)
70 ((Label
) child
).setText(text
);
71 else if (child
instanceof Text
)
72 ((Text
) child
).setText(text
);
75 public Text
getAsText() {
76 return (Text
) getControl();
79 public Label
getAsLabel() {
80 return (Label
) getControl();
83 public String
getText() {
84 Control child
= getControl();
86 if (child
instanceof Label
)
87 return ((Label
) child
).getText();
88 else if (child
instanceof Text
)
89 return ((Text
) child
).getText();
91 throw new IllegalStateException("Unsupported control " + child
.getClass());
94 public boolean getEditable() {