Introduce Makefile for Java build
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / widgets / EditableText.java
index 5fadbc07ba436b0a0a867f4c602e3b68d3ba51df..e3499ac4b91dc6790cad7ffa90fb3d32a172e407 100644 (file)
@@ -3,7 +3,7 @@ package org.argeo.cms.ui.widgets;
 import javax.jcr.Item;
 import javax.jcr.RepositoryException;
 
-import org.argeo.cms.ui.util.CmsUiUtils;
+import org.argeo.cms.swt.CmsSwtUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
@@ -21,6 +21,8 @@ public class EditableText extends StyledControl {
        private Color highlightColor;
        private Composite highlight;
 
+       private boolean useTextAsLabel = false;
+
        public EditableText(Composite parent, int style) {
                super(parent, style);
                editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY));
@@ -42,17 +44,32 @@ public class EditableText extends StyledControl {
                if (isEditing() && getEditable()) {
                        return createText(box, style, true);
                } else {
-//                     return createText(box, style, false);
-                       return createLabel(box, style);
+                       if (useTextAsLabel) {
+                               return createTextLabel(box, style);
+                       } else {
+                               return createLabel(box, style);
+                       }
                }
        }
 
        protected Label createLabel(Composite box, String style) {
                Label lbl = new Label(box, getStyle() | SWT.WRAP);
-               lbl.setLayoutData(CmsUiUtils.fillWidth());
+               lbl.setLayoutData(CmsSwtUtils.fillWidth());
                if (style != null)
-                       CmsUiUtils.style(lbl, style);
-               CmsUiUtils.markup(lbl);
+                       CmsSwtUtils.style(lbl, style);
+               CmsSwtUtils.markup(lbl);
+               if (mouseListener != null)
+                       lbl.addMouseListener(mouseListener);
+               return lbl;
+       }
+
+       protected Text createTextLabel(Composite box, String style) {
+               Text lbl = new Text(box, getStyle() | SWT.MULTI);
+               lbl.setEditable(false);
+               lbl.setLayoutData(CmsSwtUtils.fillWidth());
+               if (style != null)
+                       CmsSwtUtils.style(lbl, style);
+               CmsSwtUtils.markup(lbl);
                if (mouseListener != null)
                        lbl.addMouseListener(mouseListener);
                return lbl;
@@ -68,11 +85,11 @@ public class EditableText extends StyledControl {
 
                final Text text = new Text(box, getStyle() | SWT.MULTI | SWT.WRAP);
                text.setEditable(editable);
-               GridData textLayoutData = CmsUiUtils.fillWidth();
+               GridData textLayoutData = CmsSwtUtils.fillWidth();
                // textLayoutData.heightHint = preferredHeight;
                text.setLayoutData(textLayoutData);
                if (style != null)
-                       CmsUiUtils.style(text, style);
+                       CmsSwtUtils.style(text, style);
                text.setFocus();
                return text;
        }
@@ -111,8 +128,18 @@ public class EditableText extends StyledControl {
                        throw new IllegalStateException("Unsupported control " + child.getClass());
        }
 
+       /** @deprecated Use {@link #isEditable()} instead. */
+       @Deprecated
        public boolean getEditable() {
+               return isEditable();
+       }
+
+       public boolean isEditable() {
                return editable;
        }
 
+       public void setUseTextAsLabel(boolean useTextAsLabel) {
+               this.useTextAsLabel = useTextAsLabel;
+       }
+
 }