001: /*******************************************************************************
002: * Copyright (c) 2001, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.views.properties.tabbed;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.custom.CCombo;
014: import org.eclipse.swt.custom.CLabel;
015: import org.eclipse.swt.custom.CTabFolder;
016: import org.eclipse.swt.custom.CTabItem;
017: import org.eclipse.swt.custom.ScrolledComposite;
018: import org.eclipse.swt.layout.FormLayout;
019: import org.eclipse.swt.widgets.Composite;
020: import org.eclipse.swt.widgets.Display;
021: import org.eclipse.swt.widgets.Group;
022: import org.eclipse.swt.widgets.List;
023: import org.eclipse.ui.forms.widgets.FormToolkit;
024:
025: /**
026: * A FormToolkit customized for use by tabbed property sheet page.
027: *
028: * @author Anthony Hunter
029: */
030: public class TabbedPropertySheetWidgetFactory extends FormToolkit {
031:
032: /**
033: * private constructor.
034: */
035: public TabbedPropertySheetWidgetFactory() {
036: super (Display.getCurrent());
037: }
038:
039: /**
040: * Creates the tab folder as a part of the form.
041: *
042: * @param parent
043: * the composite parent.
044: * @param style
045: * the tab folder style.
046: * @return the tab folder
047: */
048: public CTabFolder createTabFolder(Composite parent, int style) {
049: CTabFolder tabFolder = new CTabFolder(parent, style);
050: return tabFolder;
051: }
052:
053: /**
054: * Creates the tab item as a part of the tab folder.
055: *
056: * @param tabFolder
057: * the parent.
058: * @param style
059: * the tab folder style.
060: * @return the tab item.
061: */
062: public CTabItem createTabItem(CTabFolder tabFolder, int style) {
063: CTabItem tabItem = new CTabItem(tabFolder, style);
064: return tabItem;
065: }
066:
067: /**
068: * Creates the list as a part of the form.
069: *
070: * @param parent
071: * the composite parent.
072: * @param style
073: * the list style.
074: * @return the list.
075: */
076: public List createList(Composite parent, int style) {
077: List list = new org.eclipse.swt.widgets.List(parent, style);
078: return list;
079: }
080:
081: public Composite createComposite(Composite parent, int style) {
082: Composite c = super .createComposite(parent, style);
083: paintBordersFor(c);
084: return c;
085: }
086:
087: public Composite createComposite(Composite parent) {
088: Composite c = createComposite(parent, SWT.NONE);
089: return c;
090: }
091:
092: /**
093: * Creates a plain composite as a part of the form.
094: *
095: * @param parent
096: * the composite parent.
097: * @param style
098: * the composite style.
099: * @return the composite.
100: */
101: public Composite createPlainComposite(Composite parent, int style) {
102: Composite c = super .createComposite(parent, style);
103: c.setBackground(parent.getBackground());
104: paintBordersFor(c);
105: return c;
106: }
107:
108: /**
109: * Creates a scrolled composite as a part of the form.
110: *
111: * @param parent
112: * the composite parent.
113: * @param style
114: * the composite style.
115: * @return the composite.
116: */
117: public ScrolledComposite createScrolledComposite(Composite parent,
118: int style) {
119: ScrolledComposite scrolledComposite = new ScrolledComposite(
120: parent, style);
121: return scrolledComposite;
122: }
123:
124: /**
125: * Creates a combo box as a part of the form.
126: *
127: * @param parent
128: * the combo box parent.
129: * @param comboStyle
130: * the combo box style.
131: * @return the combo box.
132: */
133: public CCombo createCCombo(Composite parent, int comboStyle) {
134: CCombo combo = new CCombo(parent, comboStyle);
135: adapt(combo, true, false);
136: // Bugzilla 145837 - workaround for no borders on Windows XP
137: if (getBorderStyle() == SWT.BORDER) {
138: combo.setData(FormToolkit.KEY_DRAW_BORDER,
139: FormToolkit.TEXT_BORDER);
140: }
141: return combo;
142: }
143:
144: /**
145: * Creates a combo box as a part of the form.
146: *
147: * @param parent
148: * the combo box parent.
149: * @return the combo box.
150: */
151: public CCombo createCCombo(Composite parent) {
152: return createCCombo(parent, SWT.FLAT | SWT.READ_ONLY);
153: }
154:
155: /**
156: * Creates a group as a part of the form.
157: *
158: * @param parent
159: * the group parent.
160: * @param text
161: * the group title.
162: * @return the composite.
163: */
164: public Group createGroup(Composite parent, String text) {
165: Group group = new Group(parent, SWT.SHADOW_NONE);
166: group.setText(text);
167: group.setBackground(getColors().getBackground());
168: group.setForeground(getColors().getForeground());
169: return group;
170: }
171:
172: /**
173: * Creates a flat form composite as a part of the form.
174: *
175: * @param parent
176: * the composite parent.
177: * @return the composite.
178: */
179: public Composite createFlatFormComposite(Composite parent) {
180: Composite composite = createComposite(parent);
181: FormLayout layout = new FormLayout();
182: layout.marginWidth = ITabbedPropertyConstants.HSPACE + 2;
183: layout.marginHeight = ITabbedPropertyConstants.VSPACE;
184: layout.spacing = ITabbedPropertyConstants.VMARGIN + 1;
185: composite.setLayout(layout);
186: return composite;
187: }
188:
189: /**
190: * Creates a label as a part of the form.
191: *
192: * @param parent
193: * the label parent.
194: * @param text
195: * the label text.
196: * @return the label.
197: */
198: public CLabel createCLabel(Composite parent, String text) {
199: return createCLabel(parent, text, SWT.NONE);
200: }
201:
202: /**
203: * Creates a label as a part of the form.
204: *
205: * @param parent
206: * the label parent.
207: * @param text
208: * the label text.
209: * @param style
210: * the label style.
211: * @return the label.
212: */
213: public CLabel createCLabel(Composite parent, String text, int style) {
214: final CLabel label = new CLabel(parent, style);
215: label.setBackground(parent.getBackground());
216: label.setText(text);
217: return label;
218: }
219:
220: public void dispose() {
221: if (getColors() != null) {
222: super.dispose();
223: }
224: }
225: }
|