Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-09 12:37:34 +0000
committerAlexander Kurtakov2017-08-09 12:37:34 +0000
commit03e7b0da1065f87694229435a12258c3431f4dca (patch)
treef4fab6f8abf81a0ee2d2c400a741d31a600f6d58 /bundles/org.eclipse.swt/Eclipse SWT
parenta3ffb152c005b14af78dbeb2418309d647a196ba (diff)
downloadeclipse.platform.swt-03e7b0da1065f87694229435a12258c3431f4dca.tar.gz
eclipse.platform.swt-03e7b0da1065f87694229435a12258c3431f4dca.tar.xz
eclipse.platform.swt-03e7b0da1065f87694229435a12258c3431f4dca.zip
Bug 512342 - [api] Provide helper methods to use lambda expressions for
ControlListener Helper methods added and version bumped for the new API. Change-Id: I71017db6a8ec2963a1d436236f8ea8e741312943 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/ControlAdapter.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java38
2 files changed, 45 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
index 1f5211de99..73267ca91b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlAdapter.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 ControlListener#controlMovedAdapter(java.util.function.Consumer)}
+ * and
+ * {@link ControlListener#controlResizedAdapter(java.util.function.Consumer)},
+ * which accept a lambda expression or a method reference that implements the event consumer.
+ * </p>
*
* @see ControlListener
* @see ControlEvent
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
index 214ae80641..c77aff377c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ControlListener.java
@@ -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
@@ -45,4 +47,38 @@ public void controlMoved(ControlEvent e);
* @param e an event containing information about the resize
*/
public void controlResized(ControlEvent e);
+
+/**
+ * Static helper method to create a <code>ControlListener</code> for the
+ * {@link #controlMoved(ControlEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ControlListener
+ * @since 3.107
+ */
+public static ControlListener controlMovedAdapter(Consumer<ControlEvent> c) {
+ return new ControlAdapter() {
+ @Override
+ public void controlMoved(ControlEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>ControlListener</code> for the
+ * {@link #controlResized(ControlEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ControlListener
+ * @since 3.107
+ */
+public static ControlListener controlResizedAdapter(Consumer<ControlEvent> c) {
+ return new ControlAdapter() {
+ @Override
+ public void controlResized(ControlEvent e) {
+ c.accept(e);
+ }
+ };
+}
}

Back to the top