Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.xtext.ui.editor.tasks.dialogfields;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.layout.GridLayout;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 
 public class LayoutUtil {

Calculates the number of columns needed by field editors
 
 	public static int getNumberOfColumns(DialogField[] editors) {
 		int nCulumns = 0;
 		for (int i = 0; i < editors.lengthi++) {
 			nCulumns = Math.max(editors[i].getNumberOfControls(), nCulumns);
 		}
 		return nCulumns;
 	}

Creates a composite and fills in the given editors.

Parameters:
labelOnTop Defines if the label of all fields should be on top of the fields
 
 	public static void doDefaultLayout(Composite parentDialogField[] editors,
 			boolean labelOnTop) {
 		doDefaultLayout(parenteditorslabelOnTop, 0, 0);
 	}

Creates a composite and fills in the given editors.

Parameters:
labelOnTop Defines if the label of all fields should be on top of the fields
marginWidth The margin width to be used by the composite
marginHeight The margin height to be used by the composite
 
 	public static void doDefaultLayout(Composite parentDialogField[] editors,
 			boolean labelOnTopint marginWidthint marginHeight) {
 		int nCulumns = getNumberOfColumns(editors);
 		Control[][] controls = new Control[editors.length][];
 		for (int i = 0; i < editors.lengthi++) {
 			controls[i] = editors[i].doFillIntoGrid(parentnCulumns);
 		}
 		if (labelOnTop) {
 			nCulumns--;
 			modifyLabelSpans(controlsnCulumns);
 		}
 		GridLayout layout = null;
 		if (parent.getLayout() instanceof GridLayout) {
 			layout = (GridLayout) parent.getLayout();
 		} else {
 			layout = new GridLayout();
 		}
 		if (marginWidth != SWT.DEFAULT) {
 			layout.marginWidth = marginWidth;
 		}
 		if (marginHeight != SWT.DEFAULT) {
 			layout.marginHeight = marginHeight;
 		}
 		layout.numColumns = nCulumns;
 		parent.setLayout(layout);
 	}
 
 	private static void modifyLabelSpans(Control[][] controlsint nCulumns) {
 		for (int i = 0; i < controls.length; i++) {
 			setHorizontalSpan(controls[i][0], nCulumns);
 		}
 	}

Sets the span of a control. Assumes that GridData is used.
 
 	public static void setHorizontalSpan(Control controlint span) {
 		Object ld = control.getLayoutData();
 		if (ld instanceof GridData) {
 			((GridData) ld).horizontalSpan = span;
 		} else if (span != 1) {
 			GridData gd = new GridData();
 			gd.horizontalSpan = span;
 			control.setLayoutData(gd);
 		}
	}

Sets the width hint of a control. Assumes that GridData is used.
	public static void setWidthHint(Control controlint widthHint) {
		Object ld = control.getLayoutData();
		if (ld instanceof GridData) {
			((GridData) ld).widthHint = widthHint;
		}
	}

Sets the heightHint hint of a control. Assumes that GridData is used.
	public static void setHeightHint(Control controlint heightHint) {
		Object ld = control.getLayoutData();
		if (ld instanceof GridData) {
			((GridData) ld).heightHint = heightHint;
		}
	}

Sets the horizontal indent of a control. Assumes that GridData is used.
	public static void setHorizontalIndent(Control controlint horizontalIndent) {
		Object ld = control.getLayoutData();
		if (ld instanceof GridData) {
			((GridData) ld).horizontalIndent = horizontalIndent;
		}
	}

Sets the horizontal grabbing of a control to true. Assumes that GridData is used.
	public static void setHorizontalGrabbing(Control control) {
		Object ld = control.getLayoutData();
		if (ld instanceof GridData) {
			((GridData) ld).grabExcessHorizontalSpace = true;
		}
	}
New to GrepCode? Check out our FAQ X