Removed some more warnings and cleaned more SWT listeners
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / util / DropDownMenu.java
index ffa1857..0e6b90a 100644 (file)
@@ -1,14 +1,10 @@
 package net.mograsim.plugin.util;
 
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
 
@@ -29,34 +25,17 @@ public class DropDownMenu
                for (DropDownEntry entry : entries)
                {
                        MenuItem item = new MenuItem(menu, SWT.PUSH);
-                       item.addSelectionListener(new SelectionListener()
-                       {
-                               @Override
-                               public void widgetSelected(SelectionEvent e)
-                               {
-                                       entry.listener.widgetSelected(e);
-                               }
-
-                               @Override
-                               public void widgetDefaultSelected(SelectionEvent e)
-                               {
-                                       widgetSelected(e);
-                               }
-                       });
+                       item.addListener(SWT.Selection, e -> entry.onSelected.run());
                        item.setText(entry.title);
                }
 
-               button.addListener(SWT.Selection, new Listener()
+               button.addListener(SWT.Selection, e ->
                {
-                       @Override
-                       public void handleEvent(Event event)
-                       {
-                               Rectangle rect = button.getBounds();
-                               Point pt = new Point(rect.x, rect.y + rect.height);
-                               pt = button.getParent().toDisplay(pt);
-                               menu.setLocation(pt.x, pt.y);
-                               menu.setVisible(true);
-                       }
+                       Rectangle rect = button.getBounds();
+                       Point pt = new Point(rect.x, rect.y + rect.height);
+                       pt = button.getParent().toDisplay(pt);
+                       menu.setLocation(pt.x, pt.y);
+                       menu.setVisible(true);
                });
        }
 
@@ -68,19 +47,12 @@ public class DropDownMenu
        public static class DropDownEntry
        {
                public final String title;
-               public final EntrySelectedListener listener;
+               public final Runnable onSelected;
 
-               public DropDownEntry(String title, EntrySelectedListener listener)
+               public DropDownEntry(String title, Runnable onSelected)
                {
-                       super();
                        this.title = title;
-                       this.listener = listener;
+                       this.onSelected = onSelected;
                }
        }
-
-       @FunctionalInterface
-       public static interface EntrySelectedListener
-       {
-               public void widgetSelected(SelectionEvent e);
-       }
 }