001: package org.pentaho.designstudio.controls;
002:
003: import org.eclipse.swt.SWT;
004: import org.eclipse.swt.widgets.Button;
005: import org.eclipse.swt.widgets.Combo;
006: import org.eclipse.swt.widgets.Composite;
007: import org.eclipse.swt.widgets.Control;
008: import org.eclipse.swt.widgets.Label;
009: import org.eclipse.swt.widgets.Table;
010: import org.eclipse.swt.widgets.Text;
011: import org.eclipse.swt.widgets.Tree;
012: import org.eclipse.ui.forms.widgets.Section;
013:
014: public class WidgetFactory {
015:
016: public static Button createButton(Composite parent, String text,
017: int style) {
018: Button button = new Button(parent, style);
019: if (text != null)
020: button.setText(text);
021: adapt(button);
022: return button;
023: }
024:
025: public static Combo createCombo(Composite parent, int style) {
026: Combo combo = new Combo(parent, style);
027: adapt(combo);
028: return combo;
029: }
030:
031: public static Text createText(Composite parent, String value,
032: int style) {
033: Text text = new Text(parent, style);
034: if (value != null) {
035: text.setText(value);
036: }
037: adapt(text);
038: return text;
039: }
040:
041: public static Text createText(Composite parent, String value) {
042: return createText(parent, value, SWT.SINGLE | SWT.BORDER);
043: }
044:
045: public static Table createTable(Composite parent, int style) {
046: Table table = new Table(parent, style);
047: adapt(table);
048: return table;
049: }
050:
051: public static Label createLabel(Composite parent, String text,
052: int style) {
053: Label label = new Label(parent, style);
054: if (text != null) {
055: label.setText(text);
056: }
057: adapt(label);
058: return label;
059: }
060:
061: public static Label createLabel(Composite parent, String text) {
062: return createLabel(parent, text, SWT.NONE);
063: }
064:
065: public static Composite createComposite(Composite parent, int style) {
066: Composite composite = new Composite(parent, style);
067: adapt(composite);
068: return composite;
069: }
070:
071: public static Composite createComposite(Composite parent) {
072: return createComposite(parent, SWT.NULL);
073: }
074:
075: public static void adapt(Control control) {
076: }
077:
078: public static void adapt(Composite composite) {
079: }
080:
081: public static Tree createTree(Composite parent, int style) {
082: Tree tree = new Tree(parent, style);
083: adapt(tree);
084: return tree;
085: }
086:
087: public static Section createSection(Composite parent,
088: int sectionStyle) {
089: Section section = new Section(parent, sectionStyle);
090: section.setMenu(parent.getMenu());
091: adapt(section);
092: return section;
093: }
094:
095: public static Label createSeparator(final Composite parent) {
096: Label separator = new Label(parent, SWT.HORIZONTAL
097: | SWT.SEPARATOR);
098: if (parent instanceof Section)
099: ((Section) parent).setSeparatorControl(separator);
100: return separator;
101: }
102: }
|