Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-10 10:21:46 +0000
committerAlexander Kurtakov2017-08-10 10:21:46 +0000
commit9aa04869f7f7e4a3aba323ae438dd85d1b9b1b4e (patch)
treefeb2ea303d285a60cf2e794e6ef5077406e807f3 /bundles/org.eclipse.swt/Eclipse SWT
parentc19e472cde1b3ff09f5e9a3c3e4ac956d70ad84d (diff)
downloadeclipse.platform.swt-9aa04869f7f7e4a3aba323ae438dd85d1b9b1b4e.tar.gz
eclipse.platform.swt-9aa04869f7f7e4a3aba323ae438dd85d1b9b1b4e.tar.xz
eclipse.platform.swt-9aa04869f7f7e4a3aba323ae438dd85d1b9b1b4e.zip
Bug 520822 - [api] Provide helpers to use lambda expressions for
MenuListener Add helper methods. Change-Id: I356966cab8b5194658cb98ce65a55145413e197e Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java40
2 files changed, 46 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
index af21e45e6f..ec4cd23f98 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -19,6 +19,13 @@ package org.eclipse.swt.events;
* extend this class and override only the methods which they are
* interested in.
* </p>
+ * <p>
+ * An alternative to this class are the static helper methods
+ * {@link MenuListener#menuHiddenAdapter(java.util.function.Consumer)}
+ * and
+ * {@link MenuListener#menuShownAdapter(java.util.function.Consumer)},
+ * which accept a lambda expression or a method reference that implements the event consumer.
+ * </p>
*
* @see MenuListener
* @see MenuEvent
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
index 99fc2800bc..15d6f24baf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/MenuListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -11,7 +11,9 @@
package org.eclipse.swt.events;
-import org.eclipse.swt.internal.SWTEventListener;
+import java.util.function.*;
+
+import org.eclipse.swt.internal.*;
/**
* Classes which implement this interface provide methods
@@ -43,4 +45,38 @@ public void menuHidden(MenuEvent e);
* @param e an event containing information about the menu operation
*/
public void menuShown(MenuEvent e);
+
+/**
+ * Static helper method to create a <code>MenuListener</code> for the
+ * {@link #menuHidden(MenuEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return MenuListener
+ * @since 3.107
+ */
+public static MenuListener menuHiddenAdapter(Consumer<MenuEvent> c) {
+ return new MenuAdapter() {
+ @Override
+ public void menuHidden(MenuEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>MenuListener</code> for the
+ * {@link #menuShown(MenuEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return MenuListener
+ * @since 3.107
+ */
+public static MenuListener menuShownAdapter(Consumer<MenuEvent> c) {
+ return new MenuAdapter() {
+ @Override
+ public void menuShown(MenuEvent e) {
+ c.accept(e);
+ }
+ };
+}
}

Back to the top