]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/widgets/EditableText.java
1 package org
.argeo
.cms
.widgets
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.cms
.util
.CmsUtils
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.layout
.GridData
;
9 import org
.eclipse
.swt
.widgets
.Composite
;
10 import org
.eclipse
.swt
.widgets
.Control
;
11 import org
.eclipse
.swt
.widgets
.Label
;
12 import org
.eclipse
.swt
.widgets
.Text
;
14 /** Editable text part displaying styled text. */
15 public class EditableText
extends StyledControl
{
16 private static final long serialVersionUID
= -6372283442330912755L;
18 public EditableText(Composite parent
, int swtStyle
) {
19 super(parent
, swtStyle
);
22 public EditableText(Composite parent
, int style
, Item item
)
23 throws RepositoryException
{
24 this(parent
, style
, item
, false);
27 public EditableText(Composite parent
, int style
, Item item
,
28 boolean cacheImmediately
) throws RepositoryException
{
29 super(parent
, style
, item
, cacheImmediately
);
33 protected Control
createControl(Composite box
, String style
) {
35 return createText(box
, style
);
37 return createLabel(box
, style
);
40 protected Label
createLabel(Composite box
, String style
) {
41 Label lbl
= new Label(box
, getStyle() | SWT
.WRAP
);
42 lbl
.setLayoutData(CmsUtils
.fillWidth());
43 CmsUtils
.style(lbl
, style
);
45 if (mouseListener
!= null)
46 lbl
.addMouseListener(mouseListener
);
50 protected Text
createText(Composite box
, String style
) {
51 final Text text
= new Text(box
, getStyle() | SWT
.MULTI
| SWT
.WRAP
);
52 GridData textLayoutData
= CmsUtils
.fillWidth();
53 // textLayoutData.heightHint = preferredHeight;
54 text
.setLayoutData(textLayoutData
);
55 CmsUtils
.style(text
, style
);
60 public void setText(String text
) {
61 Control child
= getControl();
62 if (child
instanceof Label
)
63 ((Label
) child
).setText(text
);
64 else if (child
instanceof Text
)
65 ((Text
) child
).setText(text
);
68 public Text
getAsText() {
69 return (Text
) getControl();
72 public Label
getAsLabel() {
73 return (Label
) getControl();