package org.dbgl.gui.controls;

import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;


public class ControlBuilder<T extends ControlBuilder<T>> {

	protected final Composite composite_;
	private Object customLayoutData_;
	protected int style_;
	protected int horizontalAlignment_, verticalAlignment_;
	protected boolean grabExcessHorizontalSpace_, grabExcessVerticalSpace_;
	protected int horSpan_ = 1;

	protected ControlBuilder(Composite composite, int style, int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) {
		composite_ = composite;
		style_ = style;
		horizontalAlignment_ = horizontalAlignment;
		verticalAlignment_ = verticalAlignment;
		grabExcessHorizontalSpace_ = grabExcessHorizontalSpace;
		grabExcessVerticalSpace_ = grabExcessVerticalSpace;
	}

	@SuppressWarnings("unchecked")
	public T getThis() {
		return (T)this;
	}

	public T style(int style) {
		style_ = style;
		return getThis();
	}

	public T layoutData(Object layoutData) {
		customLayoutData_ = layoutData;
		return getThis();
	}

	public T horSpan(int horizontalSpan) {
		horSpan_ = horizontalSpan;
		return getThis();
	}

	protected Object layoutData() {
		return customLayoutData_ != null ? customLayoutData_: new GridData(horizontalAlignment_, verticalAlignment_, grabExcessHorizontalSpace_, grabExcessVerticalSpace_, horSpan_, 1);
	}
}
