]>
git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.swt/src/org/argeo/app/swt/forms/EditableLink.java
1 package org
.argeo
.app
.swt
.forms
;
3 import javax
.xml
.namespace
.QName
;
5 import org
.argeo
.api
.acr
.Content
;
6 import org
.argeo
.cms
.swt
.SwtEditablePart
;
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 SwtEditablePart
{
16 private static final long serialVersionUID
= 5055000749992803591L;
19 private String message
;
20 private boolean readOnly
;
22 public EditableLink(Composite parent
, int style
, Content node
, QName propertyName
, String type
, String message
) {
23 super(parent
, style
, node
, propertyName
, message
);
24 this.message
= message
;
27 readOnly
= SWT
.READ_ONLY
== (style
& SWT
.READ_ONLY
);
28 if (node
.containsKey(propertyName
)) {
29 this.setStyle(FormStyle
.propertyText
.style());
30 this.setText(node
.attr(propertyName
));
32 this.setStyle(FormStyle
.propertyMessage
.style());
37 public void setText(String text
) {
38 Control child
= getControl();
39 if (child
instanceof Label
) {
40 Label lbl
= (Label
) child
;
41 if (EclipseUiUtils
.isEmpty(text
))
44 setLinkValue(lbl
, text
);
46 // if canEdit() we put only the value with no link
47 // to avoid glitches of the edition life cycle
49 } else if (child
instanceof Text
) {
50 Text txt
= (Text
) child
;
51 if (EclipseUiUtils
.isEmpty(text
)) {
53 txt
.setMessage(message
);
59 private void setLinkValue(Label lbl
, String text
) {
60 if (FormStyle
.email
.style().equals(type
))
61 lbl
.setText(FormUtils
.getMailLink(text
));
62 else if (FormStyle
.phone
.style().equals(type
))
63 lbl
.setText(FormUtils
.getPhoneLink(text
));
64 else if (FormStyle
.website
.style().equals(type
))
65 lbl
.setText(FormUtils
.getUrlLink(text
));
66 else if (FormStyle
.facebook
.style().equals(type
) || FormStyle
.instagram
.style().equals(type
)
67 || FormStyle
.linkedIn
.style().equals(type
) || FormStyle
.twitter
.style().equals(type
))
68 lbl
.setText(FormUtils
.getUrlLink(text
));