Mercurial > projects > dwt2
comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.d @ 99:5d5bd660917f
build some databind snippets
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 22 Apr 2009 18:59:26 +0200 |
parents | 6086085e153d |
children |
comparison
equal
deleted
inserted
replaced
98:48d4ee626868 | 99:5d5bd660917f |
---|---|
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Brad Reynolds - bug 116920 | 10 * Brad Reynolds - bug 116920 |
11 *******************************************************************************/ | 11 *******************************************************************************/ |
12 package org.eclipse.jface.examples.databinding.snippets; | 12 module org.eclipse.jface.examples.databinding.snippets.Snippet005MenuUpdater; |
13 | |
14 import java.lang.all; | |
13 | 15 |
14 import java.util.Date; | 16 import java.util.Date; |
15 import java.util.Iterator; | 17 import java.util.Iterator; |
16 | 18 |
17 import org.eclipse.core.databinding.observable.Realm; | 19 import org.eclipse.core.databinding.observable.Realm; |
22 import org.eclipse.swt.widgets.Display; | 24 import org.eclipse.swt.widgets.Display; |
23 import org.eclipse.swt.widgets.Menu; | 25 import org.eclipse.swt.widgets.Menu; |
24 import org.eclipse.swt.widgets.MenuItem; | 26 import org.eclipse.swt.widgets.MenuItem; |
25 import org.eclipse.swt.widgets.Shell; | 27 import org.eclipse.swt.widgets.Shell; |
26 | 28 |
29 import tango.io.Stdout; | |
30 | |
27 /** | 31 /** |
28 */ | 32 */ |
29 public class Snippet005MenuUpdater { | 33 public class Snippet005MenuUpdater { |
30 public static void main(String[] args) { | 34 public static void main(String[] args) { |
31 final Display display = new Display(); | 35 void add(Display d, WritableList menuItemStrings){ |
32 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { | 36 Stdout.formatln("adding item"); |
33 public void run() { | 37 menuItemStrings.add(stringcast((new Date()).toString())); |
34 Shell shell = new Shell(display); | 38 d.timerExec(5000, dgRunnable( &add, d, menuItemStrings )); |
39 } | |
40 final Display display = new Display(); | |
41 Realm.runWithDefault(SWTObservables.getRealm(display), dgRunnable( (Display display_) { | |
42 Shell shell = new Shell(display_); | |
35 | 43 |
36 final WritableList menuItemStrings = new WritableList(); | 44 final WritableList menuItemStrings = new WritableList(); |
37 display.asyncExec(new Runnable() { | 45 display_.asyncExec(dgRunnable( &add, display_, menuItemStrings)); |
38 public void run() { | |
39 System.out.println("adding item"); | |
40 menuItemStrings.add(new Date().toString()); | |
41 display.timerExec(5000, this); | |
42 } | |
43 }); | |
44 | 46 |
45 Menu bar = new Menu(shell, SWT.BAR); | 47 Menu bar = new Menu(shell, SWT.BAR); |
46 shell.setMenuBar(bar); | 48 shell.setMenuBar(bar); |
47 MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); | 49 MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); |
48 fileItem.setText("&Test Menu"); | 50 fileItem.setText("&Test Menu"); |
49 final Menu submenu = new Menu(shell, SWT.DROP_DOWN); | 51 final Menu submenu = new Menu(shell, SWT.DROP_DOWN); |
50 fileItem.setMenu(submenu); | 52 fileItem.setMenu(submenu); |
51 new MenuUpdater(submenu) { | 53 new class( submenu) MenuUpdater { |
52 protected void updateMenu() { | 54 this( Menu m ){ |
53 System.out.println("updating menu"); | 55 super(m); |
54 MenuItem[] items = submenu.getItems(); | 56 } |
55 int itemIndex = 0; | 57 protected void updateMenu() { |
56 for (Iterator it = menuItemStrings.iterator(); it | 58 Stdout.formatln("updating menu"); |
57 .hasNext();) { | 59 MenuItem[] items = submenu.getItems(); |
58 MenuItem item; | 60 int itemIndex = 0; |
59 if (itemIndex < items.length) { | 61 for (Iterator it = menuItemStrings.iterator(); it |
60 item = items[itemIndex++]; | 62 .hasNext();) { |
61 } else { | 63 MenuItem item; |
62 item = new MenuItem(submenu, SWT.NONE); | 64 if (itemIndex < items.length) { |
63 } | 65 item = items[itemIndex++]; |
64 String string = (String) it.next(); | 66 } else { |
65 item.setText(string); | 67 item = new MenuItem(submenu, SWT.NONE); |
66 } | 68 } |
67 while (itemIndex < items.length) { | 69 String string = stringcast( it.next()); |
68 items[itemIndex++].dispose(); | 70 item.setText(string); |
69 } | 71 } |
70 } | 72 while (itemIndex < items.length) { |
71 }; | 73 items[itemIndex++].dispose(); |
74 } | |
75 } | |
76 }; | |
72 | 77 |
73 shell.open(); | 78 shell.open(); |
74 | 79 |
75 // The SWT event loop | 80 // The SWT event loop |
76 while (!shell.isDisposed()) { | 81 while (!shell.isDisposed()) { |
77 if (!display.readAndDispatch()) { | 82 if (!display_.readAndDispatch()) { |
78 display.sleep(); | 83 display_.sleep(); |
79 } | 84 } |
80 } | 85 } |
81 } | 86 }, display)); |
82 }); | 87 display.dispose(); |
83 display.dispose(); | 88 } |
84 } | |
85 } | 89 } |
90 | |
91 void main( String[] args ){ | |
92 Snippet005MenuUpdater.main(args); | |
93 } | |
94 |