Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-08-15 15:32:52 +0000
committerAlexander Kurtakov2017-08-16 05:31:41 +0000
commit04fc2497ca4b5977671282c79f5c019d0c4c765b (patch)
tree1e5195d5a5146aa38f7af44705729ee87c974172 /examples
parent994a317015e269e276186e0681309f126c3b60e8 (diff)
downloadeclipse.platform.swt-04fc2497ca4b5977671282c79f5c019d0c4c765b.tar.gz
eclipse.platform.swt-04fc2497ca4b5977671282c79f5c019d0c4c765b.tar.xz
eclipse.platform.swt-04fc2497ca4b5977671282c79f5c019d0c4c765b.zip
Bug 520983 - [api] Provide helpers to use lambda expressions for
ShellListener Update examples to use it. Change-Id: I0cc8a41343cda757084f4d06e812fbda0dac53bf 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/addressbook/AddressBook.java10
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.java18
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java10
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java23
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java19
-rw-r--r--examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java20
6 files changed, 35 insertions, 65 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/AddressBook.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/AddressBook.java
index 769e1606cf..f82b89a84d 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/AddressBook.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/AddressBook.java
@@ -25,8 +25,7 @@ import java.util.Comparator;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
@@ -81,12 +80,7 @@ public static void main(String[] args) {
public Shell open(Display display) {
shell = new Shell(display);
shell.setLayout(new FillLayout());
- shell.addShellListener(new ShellAdapter() {
- @Override
- public void shellClosed(ShellEvent e) {
- e.doit = closeAddressBook();
- }
- });
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> e.doit = closeAddressBook()));
createMenuBar();
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.java
index d910c7c7e4..f38ba6eae1 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/addressbook/SearchDialog.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
@@ -17,8 +17,7 @@ import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -62,14 +61,11 @@ public SearchDialog(Shell parent) {
layout.numColumns = 2;
shell.setLayout(layout);
shell.setText(resAddressBook.getString("Search_dialog_title"));
- shell.addShellListener(new ShellAdapter(){
- @Override
- public void shellClosed(ShellEvent e) {
- // don't dispose of the shell, just hide it for later use
- e.doit = false;
- shell.setVisible(false);
- }
- });
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
+ // don't dispose of the shell, just hide it for later use
+ e.doit = false;
+ shell.setVisible(false);
+ }));
Label label = new Label(shell, SWT.LEFT);
label.setText(resAddressBook.getString("Dialog_find_what"));
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
index c830f4f33c..dcf79ea2bb 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/FileViewer.java
@@ -39,8 +39,7 @@ import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.events.TreeAdapter;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.graphics.Image;
@@ -1642,12 +1641,7 @@ public class FileViewer {
GridLayout gridLayout = new GridLayout();
shell.setLayout(gridLayout);
shell.setText(getResourceString("progressDialog." + operationKeyName[style] + ".title"));
- shell.addShellListener(new ShellAdapter() {
- @Override
- public void shellClosed(ShellEvent e) {
- isCancelled = true;
- }
- });
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> isCancelled = true));
messageLabel = new Label(shell, SWT.HORIZONTAL);
messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
index 7feb5d6f13..f5baaeae8b 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
@@ -31,8 +31,7 @@ import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
@@ -204,19 +203,17 @@ public class ImageAnalyzer {
// Hook resize and dispose listeners.
shell.addControlListener(ControlListener.controlResizedAdapter(e-> resizeShell(e)));
- shell.addShellListener(new ShellAdapter() {
- @Override
- public void shellClosed(ShellEvent e) {
- animate = false; // stop any animation in progress
- if (animateThread != null) {
- // wait for the thread to die before disposing the shell.
- while (animateThread.isAlive()) {
- if (!display.readAndDispatch()) display.sleep();
- }
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
+ animate = false; // stop any animation in progress
+ if (animateThread != null) {
+ // wait for the thread to die before disposing the shell.
+ while (animateThread.isAlive()) {
+ if (!display.readAndDispatch())
+ display.sleep();
}
- e.doit = true;
}
- });
+ e.doit = true;
+ }));
shell.addDisposeListener(e -> {
// Clean up.
if (image != null)
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java
index e43e5d0f44..6e994d1752 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/javaviewer/JavaViewer.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.examples.javaviewer;
-
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
import java.io.BufferedReader;
@@ -25,8 +24,7 @@ import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -37,8 +35,6 @@ import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
-/**
- */
public class JavaViewer {
Shell shell;
StyledText text;
@@ -80,13 +76,10 @@ void createShell (Display display) {
GridLayout layout = new GridLayout();
layout.numColumns = 1;
shell.setLayout(layout);
- shell.addShellListener (new ShellAdapter () {
- @Override
- public void shellClosed (ShellEvent e) {
- lineStyler.disposeColors();
- text.removeLineStyleListener(lineStyler);
- }
- });
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
+ lineStyler.disposeColors();
+ text.removeLineStyleListener(lineStyler);
+ }));
}
void createStyledText() {
text = new StyledText (shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java
index f9395dadca..a8fd0d0132 100644
--- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java
+++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/layoutexample/LayoutExample.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 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,14 +10,12 @@
*******************************************************************************/
package org.eclipse.swt.examples.layoutexample;
-
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
@@ -75,15 +73,13 @@ public class LayoutExample {
shell.setLayout(new FillLayout());
new LayoutExample(shell);
shell.setText(getResourceString("window.title"));
- shell.addShellListener (new ShellAdapter () {
- @Override
- public void shellClosed(ShellEvent e) {
- Shell [] shells = display.getShells();
- for (Shell currentShell : shells) {
- if (currentShell != shell) currentShell.close ();
- }
+ shell.addShellListener(ShellListener.shellClosedAdapter(e -> {
+ Shell[] shells = display.getShells();
+ for (Shell currentShell : shells) {
+ if (currentShell != shell)
+ currentShell.close();
}
- });
+ }));
shell.open();
while (! shell.isDisposed()) {
if (! display.readAndDispatch()) display.sleep();

Back to the top