28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2005 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 * Bill Baxter <wbaxter@gmail.com>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.snippets.Snippet193;
|
|
14
|
|
15 /*
|
|
16 * Tree example snippet: allow user to reorder columns by dragging and programmatically.
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * @since 3.2
|
|
22 */
|
|
23 import org.eclipse.swt.SWT;
|
|
24 import org.eclipse.swt.widgets.Display;
|
|
25 import org.eclipse.swt.widgets.Shell;
|
|
26 import org.eclipse.swt.widgets.Tree;
|
|
27 import org.eclipse.swt.widgets.TreeItem;
|
|
28 import org.eclipse.swt.widgets.TreeColumn;
|
|
29 import org.eclipse.swt.widgets.Button;
|
|
30 import org.eclipse.swt.widgets.Listener;
|
|
31 import org.eclipse.swt.widgets.Event;
|
|
32 import org.eclipse.swt.layout.RowLayout;
|
|
33 import org.eclipse.swt.layout.RowData;
|
|
34
|
112
|
35 version(Tango){
|
|
36 import tango.util.Convert;
|
|
37 import tango.io.Stdout;
|
|
38 } else { // Phobos
|
|
39 import std.conv;
|
|
40 import std.stdio;
|
|
41 }
|
28
|
42
|
|
43 import java.lang.all;
|
|
44
|
|
45
|
|
46 void main() {
|
|
47 Display display = new Display();
|
|
48 Shell shell = new Shell(display);
|
|
49 shell.setLayout(new RowLayout(SWT.HORIZONTAL));
|
112
|
50 Tree tree = new Tree(shell, SWT.BORDER | SWT.CHECK);
|
28
|
51 tree.setLayoutData(new RowData(-1, 300));
|
|
52 tree.setHeaderVisible(true);
|
|
53 TreeColumn column = new TreeColumn(tree, SWT.LEFT);
|
|
54 column.setText("Column 0");
|
|
55 column = new TreeColumn(tree, SWT.CENTER);
|
|
56 column.setText("Column 1");
|
|
57 column = new TreeColumn(tree, SWT.LEFT);
|
|
58 column.setText("Column 2");
|
|
59 column = new TreeColumn(tree, SWT.RIGHT);
|
|
60 column.setText("Column 3");
|
|
61 column = new TreeColumn(tree, SWT.CENTER);
|
|
62 column.setText("Column 4");
|
|
63 for (int i = 0; i < 5; i++) {
|
|
64 TreeItem item = new TreeItem(tree, SWT.NONE);
|
|
65 auto istr = to!(String)(i);
|
|
66 String[] text = [istr~":0",
|
|
67 istr~":1",
|
|
68 istr~":2",
|
|
69 istr~":3",
|
|
70 istr~":4"];
|
|
71 item.setText(text);
|
|
72 for (int j = 0; j < 5; j++) {
|
|
73 auto jstr = to!(String)(j);
|
|
74 TreeItem subItem = new TreeItem(item, SWT.NONE);
|
|
75 text = [istr~","~jstr~":0",
|
|
76 istr~","~jstr~":1",
|
|
77 istr~","~jstr~":2",
|
|
78 istr~","~jstr~":3",
|
|
79 istr~","~jstr~":4"];
|
|
80 subItem.setText(text);
|
|
81 for (int k = 0; k < 5; k++) {
|
|
82 auto kstr = to!(String)(k);
|
|
83 TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
|
|
84 text = [istr~","~jstr~","~kstr~":0",
|
|
85 istr~","~jstr~","~kstr~":1",
|
|
86 istr~","~jstr~","~kstr~":2",
|
|
87 istr~","~jstr~","~kstr~":3",
|
|
88 istr~","~jstr~","~kstr~":4"];
|
|
89 subsubItem.setText(text);
|
|
90 }
|
|
91 }
|
|
92 }
|
|
93 Listener listener = new class Listener {
|
|
94 public void handleEvent(Event e) {
|
112
|
95 version(Tango){
|
|
96 Stdout.print("Move "~e.widget.toString).newline;
|
|
97 } else {
|
|
98 writeln("Move "~e.widget.toString);
|
|
99 }
|
28
|
100 }
|
|
101 };
|
|
102 TreeColumn[] columns = tree.getColumns();
|
|
103 for (int i = 0; i < columns.length; i++) {
|
|
104 columns[i].setWidth(100);
|
|
105 columns[i].setMoveable(true);
|
|
106 columns[i].addListener(SWT.Move, listener);
|
|
107 }
|
|
108 Button b = new Button(shell, SWT.PUSH);
|
|
109 b.setText("invert column order");
|
|
110 b.addListener(SWT.Selection, new class Listener {
|
|
111 public void handleEvent(Event e) {
|
|
112 int[] order = tree.getColumnOrder();
|
|
113 for (int i = 0; i < order.length / 2; i++) {
|
|
114 int temp = order[i];
|
|
115 order[i] = order[order.length - i - 1];
|
|
116 order[order.length - i - 1] = temp;
|
|
117 }
|
|
118 tree.setColumnOrder(order);
|
|
119 }
|
|
120 });
|
|
121 shell.pack();
|
|
122 shell.open();
|
|
123 while (!shell.isDisposed()) {
|
|
124 if (!display.readAndDispatch())
|
|
125 display.sleep();
|
|
126 }
|
|
127 display.dispose();
|
|
128 }
|