Simplify initialisation of styled controls
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 21 Jun 2023 08:40:51 +0000 (10:40 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 21 Jun 2023 08:40:51 +0000 (10:40 +0200)
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/StyledControl.java

index 82c04a26cde06121c7f7756c075cf3d3c7ee4dfd..9370b52c58fe859b8b719baceb3de925d5b7ec0d 100644 (file)
@@ -91,6 +91,10 @@ public abstract class StyledControl extends Composite implements SwtEditablePart
                setStyle(style.style());
        }
 
+       /**
+        * Set the style, creating all related controls and composites. It should be
+        * called <b>after</b> all properties have been set.
+        */
        public void setStyle(String style) {
                Object currentStyle = null;
                if (control != null)
@@ -107,6 +111,18 @@ public abstract class StyledControl extends Composite implements SwtEditablePart
                }
        }
 
+       /**
+        * Convenience method when no style is explicitly set, so that the control can
+        * effectively be created. Does nothing if a control already exists, otherwise
+        * it is equivalent to {@link #setStyle(String)} with a <code>null<code>
+        * argument.
+        */
+       public void initControl() {
+               if (control != null)
+                       return;
+               setStyle((String) null);
+       }
+
        /** To be overridden */
        protected void setControlLayoutData(Control control) {
                control.setLayoutData(CmsSwtUtils.fillWidth());