]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - jcr/org.argeo.cms.ui/src/org/argeo/cms/ui/forms/EditablePropertyString.java
1 package org
.argeo
.cms
.ui
.forms
;
3 import static org
.argeo
.cms
.ui
.forms
.FormStyle
.propertyMessage
;
4 import static org
.argeo
.cms
.ui
.forms
.FormStyle
.propertyText
;
7 import javax
.jcr
.RepositoryException
;
9 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
10 import org
.argeo
.cms
.swt
.SwtEditablePart
;
11 import org
.argeo
.cms
.ui
.widgets
.EditableText
;
12 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Control
;
15 import org
.eclipse
.swt
.widgets
.Label
;
16 import org
.eclipse
.swt
.widgets
.Text
;
18 /** Editable String in a CMS context */
19 public class EditablePropertyString
extends EditableText
implements SwtEditablePart
{
20 private static final long serialVersionUID
= 5055000749992803591L;
22 private String propertyName
;
23 private String message
;
25 // encode the '&' character in rap
26 private final static String AMPERSAND
= "&";
27 private final static String AMPERSAND_REGEX
= "&(?![#a-zA-Z0-9]+;)";
29 public EditablePropertyString(Composite parent
, int style
, Node node
, String propertyName
, String message
)
30 throws RepositoryException
{
31 super(parent
, style
, node
, true);
32 //setUseTextAsLabel(true);
33 this.propertyName
= propertyName
;
34 this.message
= message
;
36 if (node
.hasProperty(propertyName
)) {
37 this.setStyle(propertyText
.style());
38 this.setText(node
.getProperty(propertyName
).getString());
40 this.setStyle(propertyMessage
.style());
41 this.setText(message
+ " ");
45 public void setText(String text
) {
46 Control child
= getControl();
47 if (child
instanceof Label
) {
48 Label lbl
= (Label
) child
;
49 if (EclipseUiUtils
.isEmpty(text
))
50 lbl
.setText(message
+ " ");
53 lbl
.setText(text
.replaceAll(AMPERSAND_REGEX
, AMPERSAND
));
54 } else if (child
instanceof Text
) {
55 Text txt
= (Text
) child
;
56 if (EclipseUiUtils
.isEmpty(text
)) {
58 txt
.setMessage(message
+ " ");
60 txt
.setText(text
.replaceAll("<br/>", "\n"));
64 public synchronized void startEditing() {
65 CmsSwtUtils
.style(getControl(), FormStyle
.propertyText
);
69 public synchronized void stopEditing() {
70 if (EclipseUiUtils
.isEmpty(((Text
) getControl()).getText()))
71 CmsSwtUtils
.style(getControl(), FormStyle
.propertyMessage
);
73 CmsSwtUtils
.style(getControl(), FormStyle
.propertyText
);
77 public String
getPropertyName() {