Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-10 11:29:27 +0000
committerAlexander Kurtakov2017-08-10 11:31:48 +0000
commit959f20ee87a9eac63d55f36dc390f04d5f5c1884 (patch)
treed94c533ebf1c8d3ba7861dce47d37e4e76de2eae /bundles/org.eclipse.swt/Eclipse SWT
parent9aa04869f7f7e4a3aba323ae438dd85d1b9b1b4e (diff)
downloadeclipse.platform.swt-959f20ee87a9eac63d55f36dc390f04d5f5c1884.tar.gz
eclipse.platform.swt-959f20ee87a9eac63d55f36dc390f04d5f5c1884.tar.xz
eclipse.platform.swt-959f20ee87a9eac63d55f36dc390f04d5f5c1884.zip
Bug 520831 - [api] Provide helpers to use lambda expressions for
TreeListener Add helper functions. Change-Id: Ieb78d950797dd187c65fed01fc334c43244c0ee5 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/TreeAdapter.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java40
2 files changed, 46 insertions, 3 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
index 6a580615a1..f231c57276 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeAdapter.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 TreeListener#treeCollapsedAdapter(java.util.function.Consumer)}
+ * and
+ * {@link TreeListener#treeExpandedAdapter(java.util.function.Consumer)},
+ * which accept a lambda expression or a method reference that implements the event consumer.
+ * </p>
*
* @see TreeListener
* @see TreeEvent
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
index 82b44ec34b..5347628e23 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/events/TreeListener.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
@@ -44,4 +46,38 @@ public void treeCollapsed(TreeEvent e);
* @param e an event containing information about the tree operation
*/
public void treeExpanded(TreeEvent e);
+
+/**
+ * Static helper method to create a <code>TreeListener</code> for the
+ * {@link #treeCollapsed(TreeEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return TreeListener
+ * @since 3.107
+ */
+public static TreeListener treeCollapsedAdapter(Consumer<TreeEvent> c) {
+ return new TreeAdapter() {
+ @Override
+ public void treeCollapsed(TreeEvent e) {
+ c.accept(e);
+ }
+ };
+}
+
+/**
+ * Static helper method to create a <code>TreeListener</code> for the
+ * {@link #treeExpanded(TreeEvent e)}) method, given a lambda expression or a method reference.
+ *
+ * @param c the consumer of the event
+ * @return TreeListener
+ * @since 3.107
+ */
+public static TreeListener treeExpandedAdapter(Consumer<TreeEvent> c) {
+ return new TreeAdapter() {
+ @Override
+ public void treeExpanded(TreeEvent e) {
+ c.accept(e);
+ }
+ };
+}
}

Back to the top