]> git.argeo.org Git - lgpl/argeo-commons.git/blob - forms/EditablePropertyString.java
Prepare next development cycle
[lgpl/argeo-commons.git] / forms / EditablePropertyString.java
1 package org.argeo.cms.forms;
2
3 import static org.argeo.cms.forms.FormStyle.propertyMessage;
4 import static org.argeo.cms.forms.FormStyle.propertyText;
5
6 import javax.jcr.Node;
7 import javax.jcr.RepositoryException;
8
9 import org.argeo.cms.viewers.EditablePart;
10 import org.argeo.cms.widgets.EditableText;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Text;
15
16 /** Editable String in a CMS context */
17 public class EditablePropertyString extends EditableText implements
18 EditablePart {
19 private static final long serialVersionUID = 5055000749992803591L;
20
21 private String propertyName;
22 private String message;
23
24 public EditablePropertyString(Composite parent, int style, Node node,
25 String propertyName, String message) throws RepositoryException {
26 super(parent, style, node, true);
27
28 this.propertyName = propertyName;
29 this.message = message;
30
31 if (node.hasProperty(propertyName)) {
32 this.setStyle(propertyText.style());
33 this.setText(node.getProperty(propertyName).getString());
34 } else {
35 this.setStyle(propertyMessage.style());
36 this.setText(message + " ");
37 }
38 }
39
40 public void setText(String text) {
41 Control child = getControl();
42 if (child instanceof Label) {
43 Label lbl = (Label) child;
44 if (FormUtils.notEmpty(text))
45 lbl.setText(message + " ");
46 else
47 lbl.setText(text);
48 } else if (child instanceof Text) {
49 Text txt = (Text) child;
50 if (FormUtils.notEmpty(text)) {
51 txt.setText("");
52 txt.setMessage(message + " ");
53 } else
54 txt.setText(text.replaceAll("<br/>", "\n"));
55 }
56 }
57
58 public synchronized void startEditing() {
59 getControl().setData(STYLE, propertyText.style());
60 super.startEditing();
61 }
62
63 public synchronized void stopEditing() {
64 if (FormUtils.notEmpty(((Text) getControl()).getText()))
65 getControl().setData(STYLE, propertyMessage.style());
66 else
67 getControl().setData(STYLE, propertyText.style());
68 super.stopEditing();
69 }
70
71 public String getPropertyName() {
72 return propertyName;
73 }
74 }