]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - 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
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.widgets
.Composite
;
9 import org
.eclipse
.swt
.widgets
.Control
;
10 import org
.eclipse
.swt
.widgets
.Label
;
11 import org
.eclipse
.swt
.widgets
.Text
;
13 /** Editable String that displays a browsable link when read-only */
14 public class EditableLink
extends EditablePropertyString
implements
16 private static final long serialVersionUID
= 5055000749992803591L;
19 private String message
;
20 private boolean readOnly
;
22 public EditableLink(Composite parent
, int style
, Node node
,
23 String propertyName
, String type
, String message
)
24 throws RepositoryException
{
25 super(parent
, style
, node
, propertyName
, message
);
26 this.message
= message
;
29 readOnly
= SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
);
30 if (node
.hasProperty(propertyName
)) {
31 this.setStyle(FormStyle
.propertyText
.style());
32 this.setText(node
.getProperty(propertyName
).getString());
34 this.setStyle(FormStyle
.propertyMessage
.style());
39 public void setText(String text
) {
40 Control child
= getControl();
41 if (child
instanceof Label
) {
42 Label lbl
= (Label
) child
;
43 if (FormUtils
.notEmpty(text
))
46 setLinkValue(lbl
, text
);
48 // if canEdit() we put only the value with no link
49 // to avoid glitches of the edition life cycle
51 } else if (child
instanceof Text
) {
52 Text txt
= (Text
) child
;
53 if (FormUtils
.notEmpty(text
)) {
55 txt
.setMessage(message
);
61 private void setLinkValue(Label lbl
, String text
) {
62 if (FormStyle
.email
.style().equals(type
))
63 lbl
.setText(FormUtils
.getMailLink(text
));
64 else if (FormStyle
.phone
.style().equals(type
))
65 lbl
.setText(FormUtils
.getPhoneLink(text
));
66 else if (FormStyle
.website
.style().equals(type
))
67 lbl
.setText(FormUtils
.getUrlLink(text
));
68 else if (FormStyle
.facebook
.style().equals(type
)
69 || FormStyle
.instagram
.style().equals(type
)
70 || FormStyle
.linkedIn
.style().equals(type
)
71 || FormStyle
.twitter
.style().equals(type
))
72 lbl
.setText(FormUtils
.getUrlLink(text
));