]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
5fadbc07ba436b0a0a867f4c602e3b68d3ba51df
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
.graphics
.Color
;
9 import org
.eclipse
.swt
.layout
.GridData
;
10 import org
.eclipse
.swt
.widgets
.Composite
;
11 import org
.eclipse
.swt
.widgets
.Control
;
12 import org
.eclipse
.swt
.widgets
.Label
;
13 import org
.eclipse
.swt
.widgets
.Text
;
15 /** Editable text part displaying styled text. */
16 public class EditableText
extends StyledControl
{
17 private static final long serialVersionUID
= -6372283442330912755L;
19 private boolean editable
= true;
21 private Color highlightColor
;
22 private Composite highlight
;
24 public EditableText(Composite parent
, int style
) {
26 editable
= !(SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
));
27 highlightColor
= parent
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
);
30 public EditableText(Composite parent
, int style
, Item item
) throws RepositoryException
{
31 this(parent
, style
, item
, false);
34 public EditableText(Composite parent
, int style
, Item item
, boolean cacheImmediately
) throws RepositoryException
{
35 super(parent
, style
, item
, cacheImmediately
);
36 editable
= !(SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
));
37 highlightColor
= parent
.getDisplay().getSystemColor(SWT
.COLOR_GRAY
);
41 protected Control
createControl(Composite box
, String style
) {
42 if (isEditing() && getEditable()) {
43 return createText(box
, style
, true);
45 // return createText(box, style, false);
46 return createLabel(box
, style
);
50 protected Label
createLabel(Composite box
, String style
) {
51 Label lbl
= new Label(box
, getStyle() | SWT
.WRAP
);
52 lbl
.setLayoutData(CmsUiUtils
.fillWidth());
54 CmsUiUtils
.style(lbl
, style
);
55 CmsUiUtils
.markup(lbl
);
56 if (mouseListener
!= null)
57 lbl
.addMouseListener(mouseListener
);
61 protected Text
createText(Composite box
, String style
, boolean editable
) {
62 highlight
= new Composite(box
, SWT
.NONE
);
63 highlight
.setBackground(highlightColor
);
64 GridData highlightGd
= new GridData(SWT
.FILL
, SWT
.FILL
, false, false);
65 highlightGd
.widthHint
= 5;
66 highlightGd
.heightHint
= 3;
67 highlight
.setLayoutData(highlightGd
);
69 final Text text
= new Text(box
, getStyle() | SWT
.MULTI
| SWT
.WRAP
);
70 text
.setEditable(editable
);
71 GridData textLayoutData
= CmsUiUtils
.fillWidth();
72 // textLayoutData.heightHint = preferredHeight;
73 text
.setLayoutData(textLayoutData
);
75 CmsUiUtils
.style(text
, style
);
81 protected void clear(boolean deep
) {
82 if (highlight
!= null)
87 public void setText(String text
) {
88 Control child
= getControl();
89 if (child
instanceof Label
)
90 ((Label
) child
).setText(text
);
91 else if (child
instanceof Text
)
92 ((Text
) child
).setText(text
);
95 public Text
getAsText() {
96 return (Text
) getControl();
99 public Label
getAsLabel() {
100 return (Label
) getControl();
103 public String
getText() {
104 Control child
= getControl();
106 if (child
instanceof Label
)
107 return ((Label
) child
).getText();
108 else if (child
instanceof Text
)
109 return ((Text
) child
).getText();
111 throw new IllegalStateException("Unsupported control " + child
.getClass());
114 public boolean getEditable() {