From: Mathieu Baudier Date: Wed, 21 Jun 2023 08:40:51 +0000 (+0200) Subject: Simplify initialisation of styled controls X-Git-Tag: v2.3.18~16 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=1880924eb6c8320bb39996aee07ac9c5975568fe;p=lgpl%2Fargeo-commons.git Simplify initialisation of styled controls --- diff --git a/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/StyledControl.java b/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/StyledControl.java index 82c04a26c..9370b52c5 100644 --- a/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/StyledControl.java +++ b/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/widgets/StyledControl.java @@ -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 after 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 null + * argument. + */ + public void initControl() { + if (control != null) + return; + setStyle((String) null); + } + /** To be overridden */ protected void setControlLayoutData(Control control) { control.setLayoutData(CmsSwtUtils.fillWidth());