X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fwidgets%2FStyledControl.java;h=e3a5cb473d588fa47254ddb752773f04fda823d1;hb=163f18fdace8b3171abe3a3b2282d040b205e0c8;hp=0455d2cdc9e1f0669b8e5eecd521f1a5c53c83d3;hpb=4ccc02902dad75faebe4aaa9b0b9880e2785c298;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java index 0455d2cdc..e3a5cb473 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java @@ -2,8 +2,8 @@ package org.argeo.cms.ui.widgets; import javax.jcr.Item; -import org.argeo.cms.ui.CmsConstants; -import org.argeo.cms.ui.util.CmsUiUtils; +import org.argeo.cms.swt.CmsSwtUtils; +import org.argeo.cms.ui.CmsUiConstants; import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusListener; @@ -12,7 +12,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; /** Editable text part displaying styled text. */ -public abstract class StyledControl extends JcrComposite implements CmsConstants { +public abstract class StyledControl extends JcrComposite implements CmsUiConstants { private static final long serialVersionUID = -6372283442330912755L; private Control control; @@ -24,9 +24,11 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants private Boolean editing = Boolean.FALSE; + private Composite ancestorToLayout; + public StyledControl(Composite parent, int swtStyle) { super(parent, swtStyle); - setLayout(CmsUiUtils.noSpaceGridLayout()); + setLayout(CmsSwtUtils.noSpaceGridLayout()); } public StyledControl(Composite parent, int style, Item item) { @@ -39,14 +41,20 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants protected abstract Control createControl(Composite box, String style); - protected Composite createBox(Composite parent) { - Composite box = new Composite(parent, SWT.INHERIT_DEFAULT); + protected Composite createBox() { + Composite box = new Composite(container, SWT.INHERIT_DEFAULT); setContainerLayoutData(box); - box.setLayout(CmsUiUtils.noSpaceGridLayout()); - // new Label(box, SWT.NONE).setText("BOX"); + box.setLayout(CmsSwtUtils.noSpaceGridLayout(3)); return box; } + protected Composite createContainer() { + Composite container = new Composite(this, SWT.INHERIT_DEFAULT); + setContainerLayoutData(container); + container.setLayout(CmsSwtUtils.noSpaceGridLayout()); + return container; + } + public Control getControl() { return control; } @@ -61,8 +69,7 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants // int height = control.getSize().y; String style = (String) EclipseUiSpecificUtils.getStyleData(control); clear(false); - control = createControl(box, style); - setControlLayoutData(control); + refreshControl(style); // add the focus listener to the newly created edition control if (focusListener != null) @@ -74,8 +81,16 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants editing = false; String style = (String) EclipseUiSpecificUtils.getStyleData(control); clear(false); + refreshControl(style); + } + + protected void refreshControl(String style) { control = createControl(box, style); setControlLayoutData(control); + if (ancestorToLayout != null) + ancestorToLayout.layout(true, true); + else + getParent().layout(true, true); } public void setStyle(String style) { @@ -85,34 +100,31 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants if (currentStyle != null && currentStyle.equals(style)) return; - // Integer preferredHeight = control != null ? control.getSize().y : - // null; clear(true); - control = createControl(box, style); - setControlLayoutData(control); + refreshControl(style); -// control.getParent().setData(STYLE, style + "_box"); - EclipseUiSpecificUtils.setStyleData(control.getParent(), style + "_box"); -// control.getParent().getParent().setData(STYLE, style + "_container"); - EclipseUiSpecificUtils.setStyleData(control.getParent().getParent(), style + "_container"); + if (style != null) { + CmsSwtUtils.style(box, style + "_box"); + CmsSwtUtils.style(container, style + "_container"); + } } /** To be overridden */ protected void setControlLayoutData(Control control) { - control.setLayoutData(CmsUiUtils.fillWidth()); + control.setLayoutData(CmsSwtUtils.fillWidth()); } /** To be overridden */ protected void setContainerLayoutData(Composite composite) { - composite.setLayoutData(CmsUiUtils.fillWidth()); + composite.setLayoutData(CmsSwtUtils.fillWidth()); } protected void clear(boolean deep) { if (deep) { for (Control control : getChildren()) control.dispose(); - container = createBox(this); - box = createBox(container); + container = createContainer(); + box = createBox(); } else { control.dispose(); } @@ -133,4 +145,9 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants if (control != null && this.focusListener != null) control.addFocusListener(focusListener); } + + public void setAncestorToLayout(Composite ancestorToLayout) { + this.ancestorToLayout = ancestorToLayout; + } + }