28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * D Port:
|
|
11 * Thomas Demmer <t_demmer AT web DOT de>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.snippets.Snippet82;
|
|
14
|
|
15 /*
|
|
16 * CTabFolder example snippet: prevent an item from closing
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * @since 3.0
|
|
22 */
|
|
23 import org.eclipse.swt.SWT;
|
|
24 import org.eclipse.swt.custom.CTabFolder;
|
|
25 import org.eclipse.swt.custom.CTabFolder2Adapter;
|
|
26 import org.eclipse.swt.custom.CTabFolderEvent;
|
|
27 import org.eclipse.swt.custom.CTabItem;
|
|
28 import org.eclipse.swt.layout.FillLayout;
|
|
29 import org.eclipse.swt.widgets.Button;
|
|
30 import org.eclipse.swt.widgets.Display;
|
|
31 import org.eclipse.swt.widgets.Item;
|
|
32 import org.eclipse.swt.widgets.Shell;
|
|
33 import org.eclipse.swt.widgets.Text;
|
|
34
|
|
35 import java.lang.all;
|
|
36
|
|
37 import tango.util.Convert;
|
|
38
|
|
39 void main(String[] args) {
|
|
40 Display display = new Display();
|
|
41 Shell shell = new Shell(display);
|
|
42 shell.setLayout(new FillLayout());
|
|
43 CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
|
|
44 for (int i = 0; i < 4; i++) {
|
|
45 CTabItem item = new CTabItem(folder, SWT.CLOSE);
|
|
46 item.setText("Item " ~ to!(String)(i) );
|
|
47 Text text = new Text(folder, SWT.MULTI);
|
|
48 text.setText("Content for Item "~ to!(String)(i));
|
|
49 item.setControl(text);
|
|
50 }
|
|
51
|
|
52 CTabItem specialItem = new CTabItem(folder, SWT.CLOSE);
|
|
53 specialItem.setText("Don't Close Me");
|
|
54 Text text = new Text(folder, SWT.MULTI);
|
|
55 text.setText("This tab can never be closed");
|
|
56 specialItem.setControl(text);
|
|
57
|
|
58 folder.addCTabFolder2Listener(new class() CTabFolder2Adapter {
|
|
59 public void close(CTabFolderEvent event) {
|
|
60 if (event.item == specialItem) {
|
|
61 event.doit = false;
|
|
62 }
|
|
63 }
|
|
64 });
|
|
65
|
|
66 CTabItem noCloseItem = new CTabItem(folder, SWT.NONE);
|
|
67 noCloseItem.setText("No Close Button");
|
|
68 Text text2 = new Text(folder, SWT.MULTI);
|
|
69 text2.setText("This tab does not have a close button");
|
|
70 noCloseItem.setControl(text2);
|
|
71
|
|
72 shell.pack();
|
|
73 shell.open();
|
|
74 while (!shell.isDisposed()) {
|
|
75 if (!display.readAndDispatch())
|
|
76 display.sleep();
|
|
77 }
|
|
78 display.dispose();
|
|
79 }
|
|
80
|