aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeanderson Candido2014-05-06 11:03:51 (EDT)
committerJeanderson Candido2014-05-06 11:03:51 (EDT)
commitd8eeae022b7e7ada61ac7c54a61a837816193fae (patch)
tree9b1fe4b65d44c3a6f55f5c3ffa9cd1a33c2ad590
parenta2376cc939925ac38b1f5529fa1b9025b774a703 (diff)
downloadeclipse.platform.ui-d8eeae022b7e7ada61ac7c54a61a837816193fae.zip
eclipse.platform.ui-d8eeae022b7e7ada61ac7c54a61a837816193fae.tar.gz
eclipse.platform.ui-d8eeae022b7e7ada61ac7c54a61a837816193fae.tar.bz2
Bug 414565 - [JFace][snippets] Update JFace snippets general cleanuprefs/changes/58/26058/1
Performed some minor refactorings on Snippet 058 and 059. Change-Id: I34b532e16dbe7ca716a9a4f5abebc6f5a631075b Signed-off-by: Jeanderson Candido <jeandersonbc@gmail.com>
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java56
-rw-r--r--examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet059VistaProgressIndicator.java35
2 files changed, 54 insertions, 37 deletions
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
index 937dbb8..b20691a 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet058VistaProgressBars.java
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Jeanderson Candidi <http://jeandersonbc.github.io> - Bug 414565
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.dialogs;
@@ -33,31 +33,9 @@ public class Snippet058VistaProgressBars {
Display display = new Display();
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
-
+ IRunnableWithProgress runnable = createRunnableFor(dialog);
try {
- dialog.run(true, true, new IRunnableWithProgress() {
-
- @Override
- public void run(IProgressMonitor monitor)
- throws InvocationTargetException, InterruptedException {
-
- IProgressMonitorWithBlocking blocking = (IProgressMonitorWithBlocking) monitor;
-
- blocking.beginTask("Vista Coolness", 100);
- for (int i = 0; i < 10; i++) {
- blocking.setBlocked(new Status(IStatus.WARNING,
- "Blocked", "This is blocked on Vista"));
- blocking.worked(5);
- spin(dialog.getShell().getDisplay());
- blocking.clearBlocked();
- blocking.worked(5);
- spin(dialog.getShell().getDisplay());
- if (monitor.isCanceled())
- return;
- }
- blocking.done();
- }
- });
+ dialog.run(true, true, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
@@ -67,6 +45,34 @@ public class Snippet058VistaProgressBars {
display.dispose();
}
+ private static IRunnableWithProgress createRunnableFor(
+ final ProgressMonitorDialog dialog) {
+
+ return new IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+
+ IProgressMonitorWithBlocking blocking = (IProgressMonitorWithBlocking) monitor;
+
+ blocking.beginTask("Vista Coolness", 100);
+ for (int i = 0; i < 10; i++) {
+ blocking.setBlocked(new Status(IStatus.WARNING, "Blocked",
+ "This is blocked on Vista"));
+ blocking.worked(5);
+ spin(dialog.getShell().getDisplay());
+ blocking.clearBlocked();
+ blocking.worked(5);
+ spin(dialog.getShell().getDisplay());
+ if (monitor.isCanceled())
+ return;
+ }
+ blocking.done();
+ }
+ };
+ }
+
private static void spin(final Display display) {
display.syncExec(new Runnable() {
diff --git a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet059VistaProgressIndicator.java b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet059VistaProgressIndicator.java
index cfaa030..a505497 100644
--- a/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet059VistaProgressIndicator.java
+++ b/examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/dialogs/Snippet059VistaProgressIndicator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2014 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
@@ -7,11 +7,13 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Jeanderson Candido <http://jeandersonbc.github.io> - Bug 414565
*******************************************************************************/
package org.eclipse.jface.snippets.dialogs;
import org.eclipse.jface.dialogs.ProgressIndicator;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
@@ -20,7 +22,7 @@ import org.eclipse.swt.widgets.Shell;
/**
* A snippet to demonstrate the progress indicator on Vista showing paused and
* errors
- *
+ *
*/
public class Snippet059VistaProgressIndicator {
@@ -33,33 +35,42 @@ public class Snippet059VistaProgressIndicator {
ProgressIndicator indicator = new ProgressIndicator(shell,
SWT.HORIZONTAL);
- indicator.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
- indicator.setBackground(shell.getDisplay().getSystemColor(
- SWT.COLOR_CYAN));
+ Color backgroundColor = shell.getDisplay().getSystemColor(
+ SWT.COLOR_CYAN);
+
+ indicator.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ indicator.setBackground(backgroundColor);
shell.open();
+ performProgressOn(display, indicator);
+
+ indicator.done();
+ display.dispose();
+
+ }
+
+ private static void performProgressOn(Display display,
+ ProgressIndicator indicator) {
+
indicator.beginTask(200);
indicator.showNormal();
indicator.worked(50);
spin(display);
+
indicator.showPaused();
indicator.worked(50);
spin(display);
+
indicator.showError();
indicator.worked(50);
spin(display);
-
- indicator.done();
-
- display.dispose();
-
}
private static void spin(Display display) {
long endTime = System.currentTimeMillis() + 1000;
- while(System.currentTimeMillis() < endTime)
+ while (System.currentTimeMillis() < endTime)
display.readAndDispatch();
-
+
}
}