Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-15 14:57:58 +0000
committerAlexander Kurtakov2017-08-15 14:57:58 +0000
commit3c94ea4602f0eed8a014963709ceb2125cbbc49d (patch)
tree03c84896de4a18b20561e17edbad8a1b3b66d297 /bundles/org.eclipse.swt/Eclipse SWT
parent1ac198b83058d2b56c103500ee011c5757565191 (diff)
downloadeclipse.platform.swt-3c94ea4602f0eed8a014963709ceb2125cbbc49d.tar.gz
eclipse.platform.swt-3c94ea4602f0eed8a014963709ceb2125cbbc49d.tar.xz
eclipse.platform.swt-3c94ea4602f0eed8a014963709ceb2125cbbc49d.zip
Bug 520983 - [api] Provide helpers to use lambda expressions for
ShellListener Add helper methods. Change-Id: I076764d6261c4b6cbc5f301af4cdf4b262b71198 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/ShellAdapter.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java91
2 files changed, 95 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
index 508d29d712..f203a308c7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellAdapter.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
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.swt.events;
-
/**
* This adapter class provides default implementations for the
* methods described by the <code>ShellListener</code> interface.
@@ -19,6 +18,11 @@ 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 in
+ * {@link ShellListener},
+ * which accept a lambda expression or a method reference that implements the event consumer.
+ * </p>
*
* @see ShellListener
* @see ShellEvent
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
index 5e0a37d1d4..e44f3adf87 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ShellListener.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
@@ -64,4 +66,89 @@ public void shellDeiconified(ShellEvent e);
* @param e an event containing information about the minimization
*/
public void shellIconified(ShellEvent e);
+
+/**
+ * Static helper method to create a <code>ShellListener</code> for the
+ * {@link #shellActivated(ShellEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ShellListener
+ * @since 3.107
+ */
+public static ShellListener shellActivatedAdapter(Consumer<ShellEvent> c) {
+ return new ShellAdapter() {
+ @Override
+ public void shellActivated(ShellEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>ShellListener</code> for the
+ * {@link #shellClosed(ShellEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ShellListener
+ * @since 3.107
+ */
+public static ShellListener shellClosedAdapter(Consumer<ShellEvent> c) {
+ return new ShellAdapter() {
+ @Override
+ public void shellClosed(ShellEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>ShellListener</code> for the
+ * {@link #shellDeactivated(ShellEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ShellListener
+ * @since 3.107
+ */
+public static ShellListener shellDeactivatedAdapter(Consumer<ShellEvent> c) {
+ return new ShellAdapter() {
+ @Override
+ public void shellDeactivated(ShellEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>ShellListener</code> for the
+ * {@link #shellDeiconified(ShellEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ShellListener
+ * @since 3.107
+ */
+public static ShellListener shellDeiconifiedAdapter(Consumer<ShellEvent> c) {
+ return new ShellAdapter() {
+ @Override
+ public void shellDeiconified(ShellEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>ShellListener</code> for the
+ * {@link #shellIconified(ShellEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return ShellListener
+ * @since 3.107
+ */
+public static ShellListener shellIconifiedAdapter(Consumer<ShellEvent> c) {
+ return new ShellAdapter() {
+ @Override
+ public void shellIconified(ShellEvent e) {
+ c.accept(e);
+ }
+ };
+}
}

Back to the top