Mercurial > projects > dwt2
comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet016TableUpdater.d @ 90:6086085e153d
Added databinding snippets. unmodified java sources.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 19 Apr 2009 11:33:55 +0200 |
parents | |
children | 5d5bd660917f |
comparison
equal
deleted
inserted
replaced
89:0ca1aee7decf | 90:6086085e153d |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 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 ******************************************************************************/ | |
11 | |
12 package org.eclipse.jface.examples.databinding.snippets; | |
13 | |
14 import org.eclipse.core.databinding.observable.Realm; | |
15 import org.eclipse.core.databinding.observable.list.WritableList; | |
16 import org.eclipse.core.databinding.observable.value.WritableValue; | |
17 import org.eclipse.jface.databinding.swt.SWTObservables; | |
18 import org.eclipse.jface.internal.databinding.provisional.swt.TableUpdater; | |
19 import org.eclipse.jface.layout.GridLayoutFactory; | |
20 import org.eclipse.swt.SWT; | |
21 import org.eclipse.swt.widgets.Display; | |
22 import org.eclipse.swt.widgets.Shell; | |
23 import org.eclipse.swt.widgets.Table; | |
24 import org.eclipse.swt.widgets.TableItem; | |
25 | |
26 /** | |
27 * @since 3.2 | |
28 * | |
29 */ | |
30 public class Snippet016TableUpdater { | |
31 public static void main(String[] args) { | |
32 final Display display = new Display(); | |
33 | |
34 Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { | |
35 public void run() { | |
36 final Shell shell = createShell(display); | |
37 GridLayoutFactory.fillDefaults().generateLayout(shell); | |
38 shell.open(); | |
39 // The SWT event loop | |
40 while (!shell.isDisposed()) { | |
41 if (!display.readAndDispatch()) { | |
42 display.sleep(); | |
43 } | |
44 } | |
45 } | |
46 }); | |
47 } | |
48 | |
49 static class Stuff { | |
50 private WritableValue counter = new WritableValue(new Integer(1), Integer.class); | |
51 | |
52 public Stuff(final Display display) { | |
53 display.timerExec(1000, new Runnable() { | |
54 public void run() { | |
55 counter.setValue(new Integer(1 + ((Integer) counter | |
56 .getValue()).intValue())); | |
57 display.timerExec(1000, this); | |
58 } | |
59 }); | |
60 } | |
61 | |
62 public String toString() { | |
63 return counter.getValue().toString(); | |
64 } | |
65 } | |
66 | |
67 protected static Shell createShell(final Display display) { | |
68 Shell shell = new Shell(); | |
69 Table t = new Table(shell, SWT.VIRTUAL); | |
70 final WritableList list = new WritableList(); | |
71 new TableUpdater(t, list) { | |
72 | |
73 protected void updateItem(int index, TableItem item, Object element) { | |
74 item.setText(element.toString()); | |
75 } | |
76 }; | |
77 display.timerExec(2000, new Runnable() { | |
78 public void run() { | |
79 list.add(new Stuff(display)); | |
80 display.timerExec(2000, this); | |
81 } | |
82 }); | |
83 return shell; | |
84 } | |
85 | |
86 } |