X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.eclipse.ui%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2FEclipseUiUtils.java;h=f3979d074e94fbd77f8f79e646ab4ca3395b634b;hb=80af09aa2bc8252573e545b73f1dbc8bf2b287a5;hp=06f569dce7c216467543d3a4dbfe90fed8c9cf2e;hpb=60e8274d08b93c5dbb46a2fc2a4f8b1a0d18c0ed;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java index 06f569dce..f3979d074 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java @@ -19,16 +19,24 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** Utilities to simplify UI development. */ public class EclipseUiUtils { - - + + /** Dispose all children of a Composite */ + public static void clear(Composite composite) { + for (Control child : composite.getChildren()) + child.dispose(); + } + // // Simplify grid layouts management // @@ -48,23 +56,46 @@ public class EclipseUiUtils { return grabWidth(SWT.FILL, SWT.FILL); } + public static GridData fillWidth(int colSpan) { + GridData gd = grabWidth(SWT.FILL, SWT.FILL); + gd.horizontalSpan = colSpan; + return gd; + } + public static GridData fillAll() { return new GridData(SWT.FILL, SWT.FILL, true, true); } + public static GridData fillAll(int colSpan, int rowSpan) { + return new GridData(SWT.FILL, SWT.FILL, true, true, colSpan, rowSpan); + } + public static GridData grabWidth(int horizontalAlignment, int verticalAlignment) { return new GridData(horizontalAlignment, horizontalAlignment, true, false); } - - - - + // + // Simplify Form layout management + // + + /** + * Creates a basic form data that is attached to the 4 corners of the parent + * composite + */ + public static FormData fillFormData() { + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 0); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + formData.bottom = new FormAttachment(100, 0); + return formData; + } + /** - * Create a label and a text field for a grid layout, the text field grabbing - * excess horizontal + * Create a label and a text field for a grid layout, the text field + * grabbing excess horizontal * * @param parent * the parent composite @@ -122,11 +153,15 @@ public class EclipseUiUtils { lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD); txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); - if (txt != null) + if (modifyListener != null) txt.addModifyListener(modifyListener); return txt; } + // + // FONTS + // + /** Shortcut to retrieve default italic font from display */ public static Font getItalicFont(Composite parent) { return JFaceResources.getFontRegistry().defaultFontDescriptor()