Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Bokowski2006-10-26 18:49:51 +0000
committerBoris Bokowski2006-10-26 18:49:51 +0000
commit470c3de51d3a801998d1d4ce9c449755a17fac06 (patch)
tree75e04dcd991448ba85b24540ef96fa8700047652
parent532548c90f400af899590567267bd63755090cfa (diff)
downloadorg.eclipse.e4.databinding-470c3de51d3a801998d1d4ce9c449755a17fac06.tar.gz
org.eclipse.e4.databinding-470c3de51d3a801998d1d4ce9c449755a17fac06.tar.xz
org.eclipse.e4.databinding-470c3de51d3a801998d1d4ce9c449755a17fac06.zip
A little afternoon fun with MenusI20061030-0800
-rw-r--r--examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java
new file mode 100644
index 00000000..0040231d
--- /dev/null
+++ b/examples/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet005MenuUpdater.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.examples.databinding.snippets;
+
+import java.util.Date;
+import java.util.Iterator;
+
+import org.eclipse.jface.databinding.observable.list.WritableList;
+import org.eclipse.jface.internal.databinding.provisional.swt.MenuUpdater;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ */
+public class Snippet005MenuUpdater {
+ public static void main(String[] args) {
+ final Display display = new Display();
+ Shell shell = new Shell(display);
+
+ final WritableList menuItemStrings = new WritableList();
+ display.timerExec(5000, new Runnable() {
+ public void run() {
+ System.out.println("adding item");
+ menuItemStrings.add(new Date().toString());
+ display.timerExec(5000, this);
+ }
+ });
+
+ Menu bar = new Menu(shell, SWT.BAR);
+ shell.setMenuBar(bar);
+ MenuItem fileItem = new MenuItem(bar, SWT.CASCADE);
+ fileItem.setText("&Test Menu");
+ final Menu submenu = new Menu(shell, SWT.DROP_DOWN);
+ fileItem.setMenu(submenu);
+ new MenuUpdater(submenu) {
+ protected void updateMenu() {
+ System.out.println("updating menu");
+ MenuItem[] items = submenu.getItems();
+ int itemIndex = 0;
+ for (Iterator it = menuItemStrings.iterator(); it.hasNext();) {
+ MenuItem item;
+ if (itemIndex < items.length) {
+ item = items[itemIndex++];
+ } else {
+ item = new MenuItem(submenu, SWT.NONE);
+ }
+ String string = (String) it.next();
+ item.setText(string);
+ }
+ while (itemIndex < items.length) {
+ items[itemIndex++].dispose();
+ }
+ }
+ };
+
+ shell.open();
+
+ // The SWT event loop
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+}

Back to the top