Add ancestor to refresh.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / widgets / StyledControl.java
index 1814131f4b39d5f8bc32dc73a572512ec2d405fb..b413faf3e59352c439ea32d69db3ac830ed44cb0 100644 (file)
@@ -24,6 +24,8 @@ 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());
@@ -47,10 +49,10 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants
        }
 
        protected Composite createContainer() {
-               Composite box = new Composite(this, SWT.INHERIT_DEFAULT);
-               setContainerLayoutData(box);
-               box.setLayout(CmsUiUtils.noSpaceGridLayout());
-               return box;
+               Composite container = new Composite(this, SWT.INHERIT_DEFAULT);
+               setContainerLayoutData(container);
+               container.setLayout(CmsUiUtils.noSpaceGridLayout());
+               return container;
        }
 
        public Control getControl() {
@@ -67,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)
@@ -80,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) {
@@ -91,11 +100,8 @@ 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);
 
                if (style != null) {
                        CmsUiUtils.style(box, style + "_box");
@@ -139,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;
+       }
+
 }