]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/forms/EditableLink.java
1 package org
.argeo
.cms
.forms
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.cms
.viewers
.EditablePart
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
8 import org
.eclipse
.swt
.SWT
;
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 String that displays a browsable link when read-only */
15 public class EditableLink
extends EditablePropertyString
implements
17 private static final long serialVersionUID
= 5055000749992803591L;
20 private String message
;
21 private boolean readOnly
;
23 public EditableLink(Composite parent
, int style
, Node node
,
24 String propertyName
, String type
, String message
)
25 throws RepositoryException
{
26 super(parent
, style
, node
, propertyName
, message
);
27 this.message
= message
;
30 readOnly
= SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
);
31 if (node
.hasProperty(propertyName
)) {
32 this.setStyle(FormStyle
.propertyText
.style());
33 this.setText(node
.getProperty(propertyName
).getString());
35 this.setStyle(FormStyle
.propertyMessage
.style());
40 public void setText(String text
) {
41 Control child
= getControl();
42 if (child
instanceof Label
) {
43 Label lbl
= (Label
) child
;
44 if (EclipseUiUtils
.isEmpty(text
))
47 setLinkValue(lbl
, text
);
49 // if canEdit() we put only the value with no link
50 // to avoid glitches of the edition life cycle
52 } else if (child
instanceof Text
) {
53 Text txt
= (Text
) child
;
54 if (EclipseUiUtils
.isEmpty(text
)) {
56 txt
.setMessage(message
);
62 private void setLinkValue(Label lbl
, String text
) {
63 if (FormStyle
.email
.style().equals(type
))
64 lbl
.setText(FormUtils
.getMailLink(text
));
65 else if (FormStyle
.phone
.style().equals(type
))
66 lbl
.setText(FormUtils
.getPhoneLink(text
));
67 else if (FormStyle
.website
.style().equals(type
))
68 lbl
.setText(FormUtils
.getUrlLink(text
));
69 else if (FormStyle
.facebook
.style().equals(type
)
70 || FormStyle
.instagram
.style().equals(type
)
71 || FormStyle
.linkedIn
.style().equals(type
)
72 || FormStyle
.twitter
.style().equals(type
))
73 lbl
.setText(FormUtils
.getUrlLink(text
));