Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-17 06:23:53 +0000
committerAlexander Kurtakov2017-08-17 06:23:53 +0000
commit284e39fd409be84523685929cdae22f81604ddb0 (patch)
treeba0814377591197a4b447202155fc8d8a6513ab4 /examples
parent7e29860b827a20adaf0deda18aeae2aecb0d3233 (diff)
downloadeclipse.platform.swt-284e39fd409be84523685929cdae22f81604ddb0.tar.gz
eclipse.platform.swt-284e39fd409be84523685929cdae22f81604ddb0.tar.xz
eclipse.platform.swt-284e39fd409be84523685929cdae22f81604ddb0.zip
Bug 521024 - [api] Provide helpers to use lambda expressions for Browser
listeners Adapt tests and examples. Change-Id: I49288d44f25ec2c7f370bc1481f5dd09a35c31a4 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java30
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java30
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java22
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java41
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet303.java9
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet308.java16
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet327.java25
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet362.java27
9 files changed, 91 insertions, 134 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java
index 834d0410bd..842520b801 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.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
@@ -18,12 +18,10 @@ import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.browser.VisibilityWindowListener;
-import org.eclipse.swt.browser.WindowEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
@@ -95,17 +93,12 @@ public class BrowserExample {
browser.setUrl(getResourceString("Startup"));
show(false, null, null, true, true, true, true);
} else {
- browser.addVisibilityWindowListener(new VisibilityWindowListener() {
- @Override
- public void hide(WindowEvent e) {
- }
- @Override
- public void show(WindowEvent e) {
- Browser browser = (Browser)e.widget;
- BrowserExample app = (BrowserExample)browser.getData("org.eclipse.swt.examples.browserexample.BrowserApplication");
- app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar);
- }
- });
+ browser.addVisibilityWindowListener(VisibilityWindowListener.showAdapter(e -> {
+ Browser browser = (Browser) e.widget;
+ BrowserExample app = (BrowserExample) browser
+ .getData("org.eclipse.swt.examples.browserexample.BrowserApplication");
+ app.show(true, e.location, e.size, e.addressBar, e.menuBar, e.statusBar, e.toolBar);
+ }));
browser.addCloseWindowListener(event -> {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
@@ -283,16 +276,11 @@ public class BrowserExample {
});
}
if (addressBar || statusBar || toolBar) {
- browser.addLocationListener(new LocationListener() {
- @Override
- public void changed(LocationEvent event) {
+ browser.addLocationListener(LocationListener.changedAdapter(event -> {
busy = true;
if (event.top && locationBar != null) locationBar.setText(event.location);
}
- @Override
- public void changing(LocationEvent event) {
- }
- });
+ ));
}
if (title) {
browser.addTitleListener(event -> shell.setText(event.title+" - "+getResourceString("window.title")));
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java
index 16a4b267fd..0585f938ae 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet128.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
@@ -84,14 +84,19 @@ public class Snippet128 {
/* event handling */
Listener listener = event -> {
- ToolItem item = (ToolItem)event.widget;
+ ToolItem item = (ToolItem) event.widget;
String string = item.getText();
- if (string.equals("Back")) browser.back();
- else if (string.equals("Forward")) browser.forward();
- else if (string.equals("Stop")) browser.stop();
- else if (string.equals("Refresh")) browser.refresh();
- else if (string.equals("Go")) browser.setUrl(location.getText());
- };
+ if (string.equals("Back"))
+ browser.back();
+ else if (string.equals("Forward"))
+ browser.forward();
+ else if (string.equals("Stop"))
+ browser.stop();
+ else if (string.equals("Refresh"))
+ browser.refresh();
+ else if (string.equals("Go"))
+ browser.setUrl(location.getText());
+ };
browser.addProgressListener(new ProgressListener() {
@Override
public void changed(ProgressEvent event) {
@@ -105,15 +110,10 @@ public class Snippet128 {
}
});
browser.addStatusTextListener(event -> status.setText(event.text));
- browser.addLocationListener(new LocationListener() {
- @Override
- public void changed(LocationEvent event) {
+ browser.addLocationListener(LocationListener.changedAdapter(event -> {
if (event.top) location.setText(event.location);
}
- @Override
- public void changing(LocationEvent event) {
- }
- });
+ ));
itemBack.addListener(SWT.Selection, listener);
itemForward.addListener(SWT.Selection, listener);
itemStop.addListener(SWT.Selection, listener);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java
index 94e478e862..92b023ed46 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet159.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
@@ -41,20 +41,14 @@ public class Snippet159 {
System.out.println("TitleEvent: "+event.title);
shell.setText(event.title);
});
- browser.addProgressListener(new ProgressListener() {
- @Override
- public void changed(ProgressEvent event) {
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> {
+ /* Set HTML title tag using JavaScript and DOM when page has been loaded */
+ boolean result = browser.execute("document.title='" + newTitle + "'");
+ if (!result) {
+ /* Script may fail or may not be supported on certain platforms. */
+ System.out.println("Script was not executed.");
}
- @Override
- public void completed(ProgressEvent event) {
- /* Set HTML title tag using JavaScript and DOM when page has been loaded */
- boolean result = browser.execute("document.title='"+newTitle+"'");
- if (!result) {
- /* Script may fail or may not be supported on certain platforms. */
- System.out.println("Script was not executed.");
- }
- }
- });
+ }));
/* Load an HTML document */
browser.setUrl("http://www.eclipse.org");
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java
index 3488a68b7d..107353cc93 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.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
@@ -40,29 +40,24 @@ public class Snippet160 {
return;
}
browser.addStatusTextListener(event -> browser.setData("query", event.text));
- browser.addProgressListener(new ProgressListener() {
- @Override
- public void changed(ProgressEvent event) {
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> {
+ /*
+ * Use JavaScript to query the desired node content through the Document Object
+ * Model
+ *
+ * Assign result to the window property status to pass the result to the
+ * StatusTextListener This trick is required since <code>execute</code> does not
+ * return the <code>String</code> directly.
+ */
+ boolean result = browser.execute("window.status=document.getElementById('myid').childNodes[0].nodeValue;");
+ if (!result) {
+ /* Script may fail or may not be supported on certain platforms. */
+ System.out.println("Script was not executed.");
+ return;
}
- @Override
- public void completed(ProgressEvent event) {
- /*
- * Use JavaScript to query the desired node content through the Document Object Model
- *
- * Assign result to the window property status to pass the result to the StatusTextListener
- * This trick is required since <code>execute</code> does not return the <code>String</code>
- * directly.
- */
- boolean result = browser.execute("window.status=document.getElementById('myid').childNodes[0].nodeValue;");
- if (!result) {
- /* Script may fail or may not be supported on certain platforms. */
- System.out.println("Script was not executed.");
- return;
- }
- String value = (String)browser.getData("query");
- System.out.println("Node value: "+value);
- }
- });
+ String value = (String) browser.getData("query");
+ System.out.println("Node value: " + value);
+ }));
/* Load an HTML document */
browser.setText(html);
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet303.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet303.java
index 62c205d560..724c007985 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet303.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet303.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
@@ -43,12 +43,7 @@ public static void main(String [] args) {
display.dispose();
return;
}
- browser.addProgressListener(new ProgressAdapter() {
- @Override
- public void completed(ProgressEvent event) {
- browser.execute(SCRIPT);
- }
- });
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> browser.execute(SCRIPT)));
browser.addStatusTextListener(event -> {
if (event.text.startsWith("MOUSEDOWN: ")) {
System.out.println(event.text);
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java
index 572896379c..9a7d1c51e5 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 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
@@ -42,19 +42,16 @@ public static void main (String [] args) {
browser.setText (createHTML ());
final BrowserFunction function = new CustomFunction (browser, "theJavaFunction");
- browser.addProgressListener (new ProgressAdapter () {
- @Override
- public void completed (ProgressEvent event) {
- browser.addLocationListener (new LocationAdapter () {
- @Override
- public void changed (LocationEvent event) {
- browser.removeLocationListener (this);
- System.out.println ("left java function-aware page, so disposed CustomFunction");
- function.dispose ();
- }
- });
- }
- });
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> {
+ browser.addLocationListener(new LocationAdapter() {
+ @Override
+ public void changed(LocationEvent event) {
+ browser.removeLocationListener(this);
+ System.out.println("left java function-aware page, so disposed CustomFunction");
+ function.dispose();
+ }
+ });
+ }));
shell.open ();
while (!shell.isDisposed ()) {
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet308.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet308.java
index ebeccba31c..855e3f2489 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet308.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet308.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 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
@@ -37,16 +37,10 @@ public class Snippet308 {
display.dispose();
return;
}
- browser.addProgressListener(new ProgressListener() {
- @Override
- public void changed(ProgressEvent event) {
- }
- @Override
- public void completed(ProgressEvent event) {
- String value = (String)browser.evaluate("return document.getElementById('myid').childNodes[0].nodeValue;");
- System.out.println("Node value: "+value);
- }
- });
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> {
+ String value = (String) browser.evaluate("return document.getElementById('myid').childNodes[0].nodeValue;");
+ System.out.println("Node value: " + value);
+ }));
/* Load an HTML document */
browser.setText(html);
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet327.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet327.java
index 16557fceb4..c3b4ab5467 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet327.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet327.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2013 IBM Corporation and others.
+ * Copyright (c) 2009, 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
@@ -18,8 +18,8 @@ package org.eclipse.swt.snippets;
*/
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
-import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
public class Snippet327 {
@@ -39,18 +39,15 @@ public static void main(String[] args) {
return;
}
browser.setText(createPage(0));
- browser.addLocationListener(new LocationAdapter() {
- @Override
- public void changing(LocationEvent event) {
- String location = event.location;
- int index = location.indexOf(PREAMBLE);
- if (index != -1) {
- int pageNumber = Integer.valueOf(location.substring(index + PREAMBLE.length())).intValue();
- browser.setText(createPage(pageNumber));
- event.doit = false;
- }
- }
- });
+ browser.addLocationListener(LocationListener.changingAdapter(event -> {
+ String location = event.location;
+ int index = location.indexOf(PREAMBLE);
+ if (index != -1) {
+ int pageNumber = Integer.valueOf(location.substring(index + PREAMBLE.length())).intValue();
+ browser.setText(createPage(pageNumber));
+ event.doit = false;
+ }
+ }));
shell.setBounds(10,10,200,200);
shell.open();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet362.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet362.java
index 00b3d1dfe4..3e30d124dc 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet362.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet362.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 IBM Corporation and others.
+ * Copyright (c) 2012, 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
@@ -37,20 +37,17 @@ public static void main(String [] args) {
display.dispose();
return;
}
- browser.addProgressListener (new ProgressAdapter () {
- @Override
- public void completed (ProgressEvent event) {
- final BrowserFunction function = new CustomFunction (browser, "mouseDownHappened");
- browser.execute(SCRIPT);
- browser.addLocationListener (new LocationAdapter () {
- @Override
- public void changed (LocationEvent event) {
- browser.removeLocationListener (this);
- function.dispose ();
- }
- });
- }
- });
+ browser.addProgressListener(ProgressListener.completedAdapter(event -> {
+ final BrowserFunction function = new CustomFunction(browser, "mouseDownHappened");
+ browser.execute(SCRIPT);
+ browser.addLocationListener(new LocationAdapter() {
+ @Override
+ public void changed(LocationEvent event) {
+ browser.removeLocationListener(this);
+ function.dispose();
+ }
+ });
+ }));
browser.setUrl("eclipse.org");
shell.open();

Back to the top