Mercurial > projects > dwt-samples
comparison dwtsnippets/tree/Snippet8.d @ 27:580d6cc14afd
Added tree and table snippets. Cleaned up .hgignore.
author | Jesse Phillips <Jesse.K.Phillips+D@gmail.com> |
---|---|
date | Sun, 02 Mar 2008 11:11:34 -0800 |
parents | |
children | 8ee0dfe6f685 |
comparison
equal
deleted
inserted
replaced
26:ff27e8ad465c | 27:580d6cc14afd |
---|---|
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 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
13 module dwtsnippets.tree.Snippet8; | |
14 | |
15 /* | |
16 * Tree example snippet: create a tree (lazy) | |
17 * | |
18 * For a list of all DWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 | |
22 import dwt.DWT; | |
23 import dwt.layout.FillLayout; | |
24 import dwt.graphics.Point; | |
25 import dwt.widgets.Display; | |
26 import dwt.widgets.Event; | |
27 import dwt.widgets.Listener; | |
28 import dwt.widgets.Shell; | |
29 import dwt.widgets.Tree; | |
30 import dwt.widgets.TreeItem; | |
31 | |
32 import tango.math.Math; | |
33 import tango.io.FilePath; | |
34 import tango.io.FileRoots; | |
35 | |
36 void main () { | |
37 auto display = new Display (); | |
38 auto shell = new Shell (display); | |
39 shell.setText ("Lazy Tree"); | |
40 shell.setLayout (new FillLayout ()); | |
41 auto tree = new Tree (shell, DWT.BORDER); | |
42 auto roots = FileRoots.list(); | |
43 foreach (file; roots) { | |
44 auto root = new TreeItem (tree, 0); | |
45 root.setText (file); | |
46 root.setData (new FilePath(file)); | |
47 new TreeItem (root, 0); | |
48 } | |
49 tree.addListener (DWT.Expand, new class Listener { | |
50 public void handleEvent (Event event) { | |
51 auto root = cast(TreeItem) event.item; | |
52 auto items = root.getItems (); | |
53 foreach(item; items) { | |
54 if (item.getData () !is null) return; | |
55 item.dispose (); | |
56 } | |
57 auto file = cast(FilePath) root.getData (); | |
58 auto files = file.toList(); | |
59 if (files is null) return; | |
60 foreach (f; files) { | |
61 TreeItem item = new TreeItem (root, 0); | |
62 item.setText (f.toString()); | |
63 item.setData (f); | |
64 if (f.isFolder()) { | |
65 new TreeItem (item, 0); | |
66 } | |
67 } | |
68 } | |
69 }); | |
70 auto size = tree.computeSize (300, DWT.DEFAULT); | |
71 auto width = Math.max (300, size.x); | |
72 auto height = Math.max (300, size.y); | |
73 shell.setSize (shell.computeSize (width, height)); | |
74 shell.open (); | |
75 while (!shell.isDisposed ()) { | |
76 if (!display.readAndDispatch ()) display.sleep (); | |
77 } | |
78 display.dispose (); | |
79 } |