]> git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.swt/src/org/argeo/app/swt/forms/EditablePropertyString.java
Remove legacy map overview
[gpl/argeo-suite.git] / swt / org.argeo.app.swt / src / org / argeo / app / swt / forms / EditablePropertyString.java
1 package org.argeo.app.swt.forms;
2
3 import static org.argeo.app.swt.forms.FormStyle.propertyMessage;
4 import static org.argeo.app.swt.forms.FormStyle.propertyText;
5
6 import javax.xml.namespace.QName;
7
8 import org.argeo.api.acr.Content;
9 import org.argeo.cms.swt.CmsSwtUtils;
10 import org.argeo.cms.swt.SwtEditablePart;
11 import org.argeo.cms.swt.widgets.EditableText;
12 import org.argeo.cms.ux.acr.ContentPart;
13 import org.argeo.eclipse.ui.EclipseUiUtils;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
18
19 /** Editable String in a CMS context */
20 public class EditablePropertyString extends EditableText implements SwtEditablePart, ContentPart {
21 private static final long serialVersionUID = 5055000749992803591L;
22
23 private QName propertyName;
24 private String message;
25
26 // encode the '&' character in rap
27 private final static String AMPERSAND = "&";
28 private final static String AMPERSAND_REGEX = "&(?![#a-zA-Z0-9]+;)";
29
30 public EditablePropertyString(Composite parent, int style, Content node, QName propertyName, String message) {
31 super(parent, style);
32 // setUseTextAsLabel(true);
33 this.propertyName = propertyName;
34 this.message = message;
35 setData(node);
36
37 if (node.containsKey(propertyName)) {
38 this.setStyle(propertyText.style());
39 this.setText(node.attr(propertyName));
40 } else {
41 this.setStyle(propertyMessage.style());
42 this.setText(message + " ");
43 }
44 }
45
46 public void setText(String text) {
47 Control child = getControl();
48 if (child instanceof Label) {
49 Label lbl = (Label) child;
50 if (EclipseUiUtils.isEmpty(text))
51 lbl.setText(message + " ");
52 else
53 // TODO enhance this
54 lbl.setText(text.replaceAll(AMPERSAND_REGEX, AMPERSAND));
55 } else if (child instanceof Text) {
56 Text txt = (Text) child;
57 if (EclipseUiUtils.isEmpty(text)) {
58 txt.setText("");
59 txt.setMessage(message + " ");
60 } else
61 txt.setText(text.replaceAll("<br/>", "\n"));
62 }
63 }
64
65 public synchronized void startEditing() {
66 CmsSwtUtils.style(getControl(), FormStyle.propertyText);
67 super.startEditing();
68 }
69
70 public synchronized void stopEditing() {
71 if (EclipseUiUtils.isEmpty(((Text) getControl()).getText()))
72 CmsSwtUtils.style(getControl(), FormStyle.propertyMessage);
73 else
74 CmsSwtUtils.style(getControl(), FormStyle.propertyText);
75 super.stopEditing();
76 }
77
78 public QName getPropertyName() {
79 return propertyName;
80 }
81
82 @Override
83 public Content getContent() {
84 return (Content) getData();
85 }
86
87 }