]> git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.swt/src/org/argeo/app/swt/forms/EditableLink.java
Remove legacy map overview
[gpl/argeo-suite.git] / swt / org.argeo.app.swt / src / org / argeo / app / swt / forms / EditableLink.java
1 package org.argeo.app.swt.forms;
2
3 import javax.xml.namespace.QName;
4
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;
13
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;
17
18 private String type;
19 private String message;
20 private boolean readOnly;
21
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;
25 this.type = type;
26
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));
31 } else {
32 this.setStyle(FormStyle.propertyMessage.style());
33 this.setText("");
34 }
35 }
36
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))
42 lbl.setText(message);
43 else if (readOnly)
44 setLinkValue(lbl, text);
45 else
46 // if canEdit() we put only the value with no link
47 // to avoid glitches of the edition life cycle
48 lbl.setText(text);
49 } else if (child instanceof Text) {
50 Text txt = (Text) child;
51 if (EclipseUiUtils.isEmpty(text)) {
52 txt.setText("");
53 txt.setMessage(message);
54 } else
55 txt.setText(text);
56 }
57 }
58
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));
69 }
70 }