comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.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 ******************************************************************************/ 10 ******************************************************************************/
11 11
12 package org.eclipse.jface.examples.databinding.snippets; 12 module org.eclipse.jface.examples.databinding.snippets.Snippet016TableUpdater;
13
14 import java.lang.all;
13 15
14 import org.eclipse.core.databinding.observable.Realm; 16 import org.eclipse.core.databinding.observable.Realm;
15 import org.eclipse.core.databinding.observable.list.WritableList; 17 import org.eclipse.core.databinding.observable.list.WritableList;
16 import org.eclipse.core.databinding.observable.value.WritableValue; 18 import org.eclipse.core.databinding.observable.value.WritableValue;
17 import org.eclipse.jface.databinding.swt.SWTObservables; 19 import org.eclipse.jface.databinding.swt.SWTObservables;
26 /** 28 /**
27 * @since 3.2 29 * @since 3.2
28 * 30 *
29 */ 31 */
30 public class Snippet016TableUpdater { 32 public class Snippet016TableUpdater {
31 public static void main(String[] args) { 33 public static void main(String[] args) {
32 final Display display = new Display(); 34 final Display display = new Display();
33 35
34 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { 36 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
35 public void run() { 37 public void run() {
36 final Shell shell = createShell(display); 38 final Shell shell = createShell(display);
37 GridLayoutFactory.fillDefaults().generateLayout(shell); 39 GridLayoutFactory.fillDefaults().generateLayout(shell);
38 shell.open(); 40 shell.open();
39 // The SWT event loop 41 // The SWT event loop
40 while (!shell.isDisposed()) { 42 while (!shell.isDisposed()) {
41 if (!display.readAndDispatch()) { 43 if (!display.readAndDispatch()) {
42 display.sleep(); 44 display.sleep();
43 } 45 }
44 } 46 }
45 } 47 }
46 }); 48 });
47 } 49 }
48 50
49 static class Stuff { 51 static class Stuff {
50 private WritableValue counter = new WritableValue(new Integer(1), Integer.class); 52 private WritableValue counter = new WritableValue(new Integer(1), Integer.class);
51 53
52 public Stuff(final Display display) { 54 public Stuff(final Display display) {
53 display.timerExec(1000, new Runnable() { 55 display.timerExec(1000, new Runnable() {
54 public void run() { 56 public void run() {
55 counter.setValue(new Integer(1 + ((Integer) counter 57 counter.setValue(new Integer(1 + ((Integer) counter
56 .getValue()).intValue())); 58 .getValue()).intValue()));
57 display.timerExec(1000, this); 59 display.timerExec(1000, this);
58 } 60 }
59 }); 61 });
60 } 62 }
61 63
62 public String toString() { 64 public String toString() {
63 return counter.getValue().toString(); 65 return counter.getValue().toString();
64 } 66 }
65 } 67 }
66 68
67 protected static Shell createShell(final Display display) { 69 protected static Shell createShell(final Display display) {
68 Shell shell = new Shell(); 70 Shell shell = new Shell();
69 Table t = new Table(shell, SWT.VIRTUAL); 71 Table t = new Table(shell, SWT.VIRTUAL);
70 final WritableList list = new WritableList(); 72 final WritableList list = new WritableList();
71 new TableUpdater(t, list) { 73 new TableUpdater(t, list) {
72 74
73 protected void updateItem(int index, TableItem item, Object element) { 75 protected void updateItem(int index, TableItem item, Object element) {
74 item.setText(element.toString()); 76 item.setText(element.toString());
75 } 77 }
76 }; 78 };
77 display.timerExec(2000, new Runnable() { 79 display.timerExec(2000, new Runnable() {
78 public void run() { 80 public void run() {
79 list.add(new Stuff(display)); 81 list.add(new Stuff(display));
80 display.timerExec(2000, this); 82 display.timerExec(2000, this);
81 } 83 }
82 }); 84 });
83 return shell; 85 return shell;
84 } 86 }
85 87
86 } 88 }
89 void main( String[] args ){
90 Snippet016TableUpdater.main(args);
91 }