X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fwidgets%2FEditableText.java;h=e3499ac4b91dc6790cad7ffa90fb3d32a172e407;hb=633a8acd189cc22f06944d278879601189be1bc8;hp=1ae44d0f74147843243ddb54710fc45a7d819c1b;hpb=fb3182380d9688998a81d853a4eebcf87b6a48c7;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java index 1ae44d0f7..e3499ac4b 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java @@ -3,10 +3,9 @@ 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.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -19,9 +18,15 @@ public class EditableText extends StyledControl { private boolean editable = true; + 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)); + highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); } public EditableText(Composite parent, int style, Item item) throws RepositoryException { @@ -31,6 +36,7 @@ public class EditableText extends StyledControl { public EditableText(Composite parent, int style, Item item, boolean cacheImmediately) throws RepositoryException { super(parent, style, item, cacheImmediately); editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY)); + highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY); } @Override @@ -38,32 +44,63 @@ 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()); - CmsUiUtils.style(lbl, style); - CmsUiUtils.markup(lbl); + lbl.setLayoutData(CmsSwtUtils.fillWidth()); + if (style != null) + 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; } protected Text createText(Composite box, String style, boolean editable) { + highlight = new Composite(box, SWT.NONE); + highlight.setBackground(highlightColor); + GridData highlightGd = new GridData(SWT.FILL, SWT.FILL, false, false); + highlightGd.widthHint = 5; + highlightGd.heightHint = 3; + highlight.setLayoutData(highlightGd); + 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); - CmsUiUtils.style(text, style); + if (style != null) + CmsSwtUtils.style(text, style); text.setFocus(); return text; } + @Override + protected void clear(boolean deep) { + if (highlight != null) + highlight.dispose(); + super.clear(deep); + } + public void setText(String text) { Control child = getControl(); if (child instanceof Label) @@ -82,7 +119,7 @@ public class EditableText extends StyledControl { public String getText() { Control child = getControl(); - + if (child instanceof Label) return ((Label) child).getText(); else if (child instanceof Text) @@ -91,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; + } + }