Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 113964 Details for
Bug 247818
[StatusHandling] WorkbenchStatusDialogManager should inform of dialog closure
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Updated Fix
listenerDialogRC1.txt (text/plain), 12.95 KB, created by
Krzysztof Daniel
on 2008-10-01 04:58:12 EDT
(
hide
)
Description:
Updated Fix
Filename:
MIME Type:
Creator:
Krzysztof Daniel
Created:
2008-10-01 04:58:12 EDT
Size:
12.95 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java,v >retrieving revision 1.16 >diff -u -r1.16 WorkbenchStatusDialogManager.java >--- Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java 22 Sep 2008 10:26:37 -0000 1.16 >+++ Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java 1 Oct 2008 08:55:27 -0000 >@@ -222,6 +222,17 @@ > */ > private class InternalDialog extends TrayDialog { > >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.TrayDialog#close() >+ */ >+ public boolean close() { >+ boolean result = super.close(); >+ if (listener != null && !modalitySwitch) { >+ listener.statusDialogClosed(); >+ } >+ return result; >+ } >+ > private WorkbenchStatusDialogManager statusDialog; > > /** >@@ -1006,6 +1017,8 @@ > */ > private Composite titleArea; > >+ private IStatusDialogListener listener; >+ > /** > * Creates workbench status dialog. > * >@@ -1659,7 +1672,7 @@ > /** > * Returns the shell of the dialog. > */ >- Shell getShell() { >+ private Shell getShell() { > if (this.dialog == null) return null; > return this.dialog.getShell(); > } >@@ -2196,4 +2209,24 @@ > } > titleArea.layout(); > } >+ >+ /** >+ * This method adds a listener to the dialog. Listener will be notified >+ * about dialog state changes. There can be only one listener set. >+ * <p> >+ * <strong>EXPERIMENTAL</strong>. This class or interface has been added as >+ * part of a work in progress. There is a guarantee neither that this API >+ * will work nor that it will remain the same. Please do not use this API >+ * without consulting with the Platform/UI team. >+ * </p> >+ * >+ * @see IStatusDialogListener >+ * @param listener >+ * A listener to be set. <code>null</code> can be used to clear >+ * the listener. >+ * @since 3.5 >+ */ >+ public void setStatusDialogListener(IStatusDialogListener listener) { >+ this.listener = listener; >+ } > } >Index: Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java,v >retrieving revision 1.22 >diff -u -r1.22 WorkbenchErrorHandler.java >--- Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java 26 Sep 2008 15:48:09 -0000 1.22 >+++ Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchErrorHandler.java 1 Oct 2008 08:55:26 -0000 >@@ -14,7 +14,6 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.swt.widgets.Display; >-import org.eclipse.swt.widgets.Shell; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.application.WorkbenchAdvisor; > import org.eclipse.ui.internal.WorkbenchPlugin; >@@ -26,6 +25,15 @@ > * @since 3.3 > */ > public class WorkbenchErrorHandler extends AbstractStatusHandler { >+ >+ private boolean dialogClosed = false; >+ private IStatusDialogListener listener = new IStatusDialogListener(){ >+ >+ public void statusDialogClosed() { >+ dialogClosed = true; >+ } >+ >+ }; > > private WorkbenchStatusDialogManager statusDialog; > >@@ -110,10 +118,11 @@ > getStatusDialogManager().addStatusAdapter(statusAdapter, block); > > if (block) { >- Shell shell; >- while ((shell = getStatusDialogManager().getShell()) != null >- && !getStatusDialogManager().getShell().isDisposed()) { >- if (!shell.getDisplay().readAndDispatch()) { >+ // this variable will be set to true if and only if user closes the >+ // dialog >+ dialogClosed = false; >+ while (!dialogClosed) { >+ if (!Display.getDefault().readAndDispatch()) { > Thread.yield(); > } > } >@@ -159,5 +168,6 @@ > private void initStatusDialogManager() { > statusDialog = new WorkbenchStatusDialogManager(null); > configureStatusDialog(statusDialog); >+ statusDialog.setStatusDialogListener(listener); > } > } >Index: Eclipse UI/org/eclipse/ui/statushandlers/IStatusDialogListener.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/statushandlers/IStatusDialogListener.java >diff -N Eclipse UI/org/eclipse/ui/statushandlers/IStatusDialogListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/statushandlers/IStatusDialogListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.statushandlers; >+ >+/** >+ * This interface allows for listening to dialog state changes. The dialog is >+ * managed by {@link WorkbenchStatusDialogManager}. >+ * >+ * <p> >+ * <strong>EXPERIMENTAL</strong>. This class or interface has been added as part >+ * of a work in progress. There is a guarantee neither that this API will work >+ * nor that it will remain the same. Please do not use this API without >+ * consulting with the Platform/UI team. >+ * </p> >+ * >+ * @since 3.5 >+ */ >+public interface IStatusDialogListener { >+ /** >+ * This method is called when the status dialog is closed by user. >+ */ >+ public void statusDialogClosed(); >+} >#P org.eclipse.ui.tests >Index: Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java,v >retrieving revision 1.5 >diff -u -r1.5 StatusDialogManagerTest.java >--- Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java 22 Sep 2008 10:26:39 -0000 1.5 >+++ Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java 1 Oct 2008 08:55:28 -0000 >@@ -31,6 +31,7 @@ > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Shell; >@@ -41,7 +42,10 @@ > import org.eclipse.ui.progress.IProgressConstants; > import org.eclipse.ui.statushandlers.AbstractStatusAreaProvider; > import org.eclipse.ui.statushandlers.IStatusAdapterConstants; >+import org.eclipse.ui.statushandlers.IStatusDialogListener; > import org.eclipse.ui.statushandlers.StatusAdapter; >+import org.eclipse.ui.statushandlers.StatusManager; >+import org.eclipse.ui.statushandlers.WorkbenchErrorHandler; > import org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager; > > public class StatusDialogManagerTest extends TestCase { >@@ -51,6 +55,7 @@ > private static final String THROWABLE = "throwable"; > private final static String MESSAGE_1 = "TEST_MESSAGE_1"; > private final static String MESSAGE_2 = "TEST_MESSAGE_2"; >+ private final static String MESSAGE_3 = "TEST_MESSAGE_2"; > private final static String TITLE = "TEST_TITLE"; > private final static NullPointerException NPE = new NullPointerException(); > private final static NullPointerException NPE_WITH_MESSAGE = new NullPointerException( >@@ -73,6 +78,112 @@ > assertNotNull(shell); > assertTrue((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); > } >+ >+ /** >+ * This test checks if the calling thread is really blocked. It opens a >+ * dialog with the BLOCK flag in UI thread, and then monitors in the >+ * background thread that the dialog really appears (in 50 tries, 50 >+ * milliseconds each). After the dialog appears, "OK" selection is emulated, >+ * the dialog is closed and the handle method returns. At this point there >+ * can be no shell. >+ */ >+ public void testBlockingBehavior1() { >+ WorkbenchErrorHandler weh = new WorkbenchErrorHandler(); >+ Thread thread = new Thread(new Runnable(){ >+ public void run() { >+ int count = 50; >+ final boolean opened[] = new boolean[]{false}; >+ while (!opened[0] && count-- != 0) { >+ try { >+ Thread.sleep(50); >+ } catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ opened[0] = StatusDialogUtil.getStatusShell() != null; >+ if(opened[0]){ >+ selectWidget(StatusDialogUtil.getOkButton()); >+ } >+ } >+ }); >+ } >+ assertTrue("Dialog should appear!", count > 0); >+ >+ } >+ }); >+ thread.start(); >+ weh.handle(createStatusAdapter(MESSAGE_1), StatusManager.BLOCK); >+ assertNull("Dialog should block the calling thread!", StatusDialogUtil >+ .getStatusShell()); >+ } >+ >+ /** >+ * This is more advanced version of testBlockingBehavior1. We have 2 >+ * background threads that raise statuses. UI thread also raises one. No >+ * thread can proceed until "OK" is emulated (and this will happen if the >+ * dialog is opened and three statuses were reported). >+ */ >+ public void testBlockingBehavior2() { >+ final WorkbenchErrorHandler weh = new WorkbenchErrorHandler(); >+ Thread thread1 = new Thread(new Runnable() { >+ public void run() { >+ weh.handle(createStatusAdapter(MESSAGE_1), StatusManager.BLOCK); >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ assertNull("Dialog should block the calling thread!", >+ StatusDialogUtil.getStatusShell()); >+ } >+ }); >+ } >+ >+ }); >+ thread1.start(); >+ Thread thread2 = new Thread(new Runnable() { >+ public void run() { >+ weh.handle(createStatusAdapter(MESSAGE_2), StatusManager.BLOCK); >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ assertNull("Dialog should block the calling thread!", >+ StatusDialogUtil.getStatusShell()); >+ } >+ }); >+ } >+ }); >+ thread2.start(); >+ Thread checker = new Thread(new Runnable() { >+ public void run() { >+ int count = 50; >+ final boolean statusesShown[] = new boolean[] { false }; >+ while (!statusesShown[0] && count-- != 0) { >+ try { >+ Thread.sleep(50); >+ } catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ Display.getDefault().syncExec(new Runnable() { >+ public void run() { >+ boolean dialogVisible = StatusDialogUtil >+ .getStatusShell() != null; >+ statusesShown[0] = dialogVisible >+ && StatusDialogUtil.getTable() >+ .getItemCount() == 3; >+ if (statusesShown[0]) { >+ selectWidget(StatusDialogUtil.getOkButton()); >+ } >+ } >+ }); >+ } >+ assertTrue( >+ "Dialog should appear and all statuses should be shown", >+ count > 0); >+ } >+ }); >+ checker.start(); >+ weh.handle(createStatusAdapter(MESSAGE_3), StatusManager.BLOCK); >+ assertNull("Dialog should block the calling thread!", StatusDialogUtil >+ .getStatusShell()); >+ } > > public void testNonBlockingAppearance() { > wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); >@@ -80,6 +191,41 @@ > assertNotNull(shell); > assertFalse((shell.getStyle() & SWT.APPLICATION_MODAL) == SWT.APPLICATION_MODAL); > } >+ >+ /** >+ * Check that listener is notified about dialog closure when the dialog is >+ * closed by the user. >+ */ >+ public void testListener1(){ >+ final boolean[] dialogClosedInvoked = new boolean[]{false}; >+ wsdm.setStatusDialogListener(new IStatusDialogListener(){ >+ public void statusDialogClosed() { >+ dialogClosedInvoked[0] = true; >+ } >+ }); >+ wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); >+ selectWidget(StatusDialogUtil.getOkButton()); >+ assertTrue(dialogClosedInvoked[0]); >+ } >+ >+ /** >+ * Check that listener is not notified about dialog closure when the >+ * modality is switched. >+ */ >+ public void testListener2(){ >+ final boolean[] dialogClosedInvoked = new boolean[]{false}; >+ wsdm.setStatusDialogListener(new IStatusDialogListener(){ >+ public void statusDialogClosed() { >+ dialogClosedInvoked[0] = true; >+ } >+ }); >+ wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false); >+ wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), true); >+ assertFalse(dialogClosedInvoked[0]); >+ selectWidget(StatusDialogUtil.getOkButton()); >+ // now should be notified >+ assertTrue(dialogClosedInvoked[0]); >+ } > > public void testModalitySwitch1() { > wsdm.addStatusAdapter(createStatusAdapter(MESSAGE_1), false);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 247818
:
113730
|
113856
|
113857
|
113964
|
114310
|
114311
|
114933
|
115700
|
115714