diff options
author | Alexander Kurtakov | 2017-08-10 09:17:06 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2017-08-10 09:17:06 +0000 |
commit | c19e472cde1b3ff09f5e9a3c3e4ac956d70ad84d (patch) | |
tree | 067841616bd592b7b6cc3065c12187e9848da8dc /bundles/org.eclipse.swt/Eclipse SWT | |
parent | e74c957a5abab5816808d57ce3cfb44bd4d1d075 (diff) | |
download | eclipse.platform.swt-c19e472cde1b3ff09f5e9a3c3e4ac956d70ad84d.tar.gz eclipse.platform.swt-c19e472cde1b3ff09f5e9a3c3e4ac956d70ad84d.tar.xz eclipse.platform.swt-c19e472cde1b3ff09f5e9a3c3e4ac956d70ad84d.zip |
Bug 520806 - [api] Provide helpers to use lambda expressions for
ExpandListener
Add the helpers.
Change-Id: Idecdce77c3bdb786d05736b8270215b15823a09e
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/ExpandAdapter.java | 10 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java | 40 |
2 files changed, 46 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java index 074504391c..b0b7228b3d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandAdapter.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>ExpandListener</code> interface. @@ -19,6 +18,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 ExpandListener#itemCollapsedAdapter(java.util.function.Consumer)} + * and + * {@link ExpandListener#itemExpandedAdapter(java.util.function.Consumer)}, + * which accept a lambda expression or a method reference that implements the event consumer. + * </p> * * @see ExpandListener * @see ExpandEvent diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java index 175fe0e33e..fe43a98255 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/ExpandListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 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 @@ -46,4 +48,38 @@ public void itemCollapsed(ExpandEvent e); * @param e an event containing information about the operation */ public void itemExpanded(ExpandEvent e); + +/** + * Static helper method to create a <code>ExpandListener</code> for the + * {@link #itemCollapsed(ExpandEvent e)}) method, given a lambda expression or a method reference. + * + * @param c the consumer of the event + * @return ExpandListener + * @since 3.107 + */ +public static ExpandListener itemCollapsedAdapter(Consumer<ExpandEvent> c) { + return new ExpandAdapter() { + @Override + public void itemCollapsed(ExpandEvent e) { + c.accept(e); + } + }; +} + +/** + * Static helper method to create a <code>ExpandListener</code> for the + * {@link #itemExpanded(ExpandEvent e)}) method, given a lambda expression or a method reference. + * + * @param c the consumer of the event + * @return ExpandListener + * @since 3.107 + */ +public static ExpandListener itemExpandedAdapter(Consumer<ExpandEvent> c) { + return new ExpandAdapter() { + @Override + public void itemExpanded(ExpandEvent e) { + c.accept(e); + } + }; +} } |