[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / provisional / tmf / ui / views / timegraph2 / swtjfx / examples / SwtToobar2.java
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swtjfx/examples/SwtToobar2.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/provisional/tmf/ui/views/timegraph2/swtjfx/examples/SwtToobar2.java
new file mode 100644 (file)
index 0000000..a010e50
--- /dev/null
@@ -0,0 +1,78 @@
+package org.eclipse.tracecompass.internal.provisional.tmf.ui.views.timegraph2.swtjfx.examples;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+
+@NonNullByDefault({})
+public class SwtToobar2 {
+
+    private Shell shell;
+
+    public SwtToobar2() {
+        Display display = new Display();
+        shell = new Shell(display, SWT.SHELL_TRIM);
+        shell.setLayout(new FillLayout(SWT.VERTICAL));
+        shell.setSize(50, 100);
+
+        ToolBar toolbar = new ToolBar(shell, SWT.FLAT);
+        ToolItem itemDrop = new ToolItem(toolbar, SWT.DROP_DOWN);
+        itemDrop.setText("drop menu");
+
+        itemDrop.addSelectionListener(new SelectionAdapter() {
+
+            Menu dropMenu = null;
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (dropMenu == null) {
+                    dropMenu = new Menu(shell, SWT.POP_UP);
+                    shell.setMenu(dropMenu);
+                    MenuItem itemCheck = new MenuItem(dropMenu, SWT.CHECK);
+                    itemCheck.setText("checkbox");
+                    MenuItem itemRadio = new MenuItem(dropMenu, SWT.RADIO);
+                    itemRadio.setText("radio1");
+                    MenuItem itemRadio2 = new MenuItem(dropMenu, SWT.RADIO);
+                    itemRadio2.setText("radio2");
+                }
+
+                if (e.detail == SWT.ARROW) {
+                    // Position the menu below and vertically aligned with the
+                    // the drop down tool button.
+                    final ToolItem toolItem = (ToolItem) e.widget;
+                    final ToolBar toolBar = toolItem.getParent();
+
+                    Point point = toolBar.toDisplay(new Point(e.x, e.y));
+                    dropMenu.setLocation(point.x, point.y);
+                    dropMenu.setVisible(true);
+                }
+
+            }
+
+        });
+
+        shell.open();
+
+        while (!shell.isDisposed()) {
+            if (!display.readAndDispatch()) {
+                display.sleep();
+            }
+        }
+
+        display.dispose();
+    }
+
+    public static void main(String[] args) {
+        new SwtToobar2();
+    }
+
+}
\ No newline at end of file
This page took 0.023959 seconds and 5 git commands to generate.