001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.jdt.ui.examples;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.layout.GridData;
014: import org.eclipse.swt.layout.GridLayout;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Display;
017: import org.eclipse.swt.widgets.Label;
018: import org.eclipse.swt.widgets.Shell;
019: import org.eclipse.swt.widgets.TabFolder;
020: import org.eclipse.swt.widgets.TabItem;
021:
022: import org.eclipse.jface.viewers.LabelProvider;
023:
024: import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
025: import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
026: import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
027: import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
028: import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
029: import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
030:
031: public class TabExample {
032: private Shell fShell;
033:
034: public TabExample() {
035: }
036:
037: public TabExample close() {
038: if ((fShell != null) && (!fShell.isDisposed()))
039: fShell.dispose();
040: fShell = null;
041: return this ;
042: }
043:
044: public TabExample open() {
045: fShell = new Shell();
046: fShell.setText("TabTest");
047: fShell.setLayout(new GridLayout());
048:
049: TabFolder folder = new TabFolder(fShell, SWT.NONE);
050: folder.setLayoutData(new GridData(GridData.FILL_BOTH));
051: //folder.setLayout(new PageContainerFillLayout(0, 0, 20, 20));
052: //folder.setLayout(new FillLayout());
053:
054: /*folder.addSelectionListener(new SelectionAdapter() {
055: public void widgetSelected(SelectionEvent event) {
056: turnToPage(event);
057: }
058: });*/
059:
060: TabItem item;
061: Label label;
062:
063: item = new TabItem(folder, SWT.NONE);
064: item.setText("Tab0");
065:
066: String[] addButtons = new String[] {
067: /* 0 */"Add1",
068: /* 1 */"Add2",
069: /* 2 */null,
070: /* 3 */"Remove" };
071: ListDialogField list = new ListDialogField(new Adapter(),
072: addButtons, new LabelProvider());
073: list.setRemoveButtonIndex(3);
074: list.setLabelText("List: ");
075:
076: Composite c1 = new Composite(folder, SWT.NONE);
077: LayoutUtil
078: .doDefaultLayout(c1, new DialogField[] { list }, true);
079:
080: item.setControl(c1);
081:
082: item = new TabItem(folder, SWT.NONE);
083: item.setText("Tab1");
084: label = new Label(folder, SWT.LEFT);
085: label.setText("Tab1");
086: item.setControl(label);
087:
088: item = new TabItem(folder, SWT.NONE);
089: item.setText("Tab2");
090: label = new Label(folder, SWT.LEFT);
091: label.setText("Tab2");
092: item.setControl(label);
093:
094: item = new TabItem(folder, SWT.NONE);
095: item.setText("Tab3");
096: label = new Label(folder, SWT.LEFT);
097: label.setText("Tab3");
098: item.setControl(label);
099:
100: fShell.setSize(400, 500);
101: fShell.open();
102: return this ;
103: }
104:
105: private class Adapter implements IStringButtonAdapter,
106: IDialogFieldListener, IListAdapter {
107:
108: // -------- IStringButtonAdapter
109: public void changeControlPressed(DialogField field) {
110: }
111:
112: // -------- IListAdapter
113: public void customButtonPressed(ListDialogField field, int index) {
114: }
115:
116: public void selectionChanged(ListDialogField field) {
117: }
118:
119: // -------- IDialogFieldListener
120: public void dialogFieldChanged(DialogField field) {
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField)
125: */
126: public void doubleClicked(ListDialogField field) {
127: }
128: }
129:
130: public TabExample run() {
131: Display display = fShell.getDisplay();
132: while (!fShell.isDisposed()) {
133: if (!display.readAndDispatch())
134: display.sleep();
135: }
136: return this ;
137: }
138:
139: public static void main(java.lang.String[] args) {
140: new TabExample().open().run().close();
141: }
142: }
|