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 113856 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]
Fix with tests
dialogListener.txt (text/plain), 11.63 KB, created by
Krzysztof Daniel
on 2008-09-30 08:11:36 EDT
(
hide
)
Description:
Fix with tests
Filename:
MIME Type:
Creator:
Krzysztof Daniel
Created:
2008-09-30 08:11:36 EDT
Size:
11.63 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 30 Sep 2008 12:09:14 -0000 >@@ -92,6 +92,7 @@ > import org.eclipse.ui.internal.progress.ProgressManagerUtil; > import org.eclipse.ui.internal.progress.ProgressMessages; > import org.eclipse.ui.internal.statushandlers.DefaultDetailsArea; >+import org.eclipse.ui.internal.statushandlers.IStatusDialogListener; > import org.eclipse.ui.internal.statushandlers.StackTraceSupportArea; > import org.eclipse.ui.progress.IProgressConstants; > >@@ -222,6 +223,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 +1018,8 @@ > */ > private Composite titleArea; > >+ private IStatusDialogListener listener; >+ > /** > * Creates workbench status dialog. > * >@@ -1659,7 +1673,7 @@ > /** > * Returns the shell of the dialog. > */ >- Shell getShell() { >+ private Shell getShell() { > if (this.dialog == null) return null; > return this.dialog.getShell(); > } >@@ -2196,4 +2210,8 @@ > } > titleArea.layout(); > } >+ >+ 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 30 Sep 2008 12:09:14 -0000 >@@ -14,10 +14,10 @@ > 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; >+import org.eclipse.ui.internal.statushandlers.IStatusDialogListener; > > /** > * This is a default workbench error handler. >@@ -26,6 +26,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 +119,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(); > } > } >@@ -124,8 +134,9 @@ > * This method returns current {@link WorkbenchStatusDialogManager}. > * > * @return current {@link WorkbenchStatusDialogManager} >+ * @noreference This method is not intended to be referenced by clients. > */ >- private WorkbenchStatusDialogManager getStatusDialogManager() { >+ public WorkbenchStatusDialogManager getStatusDialogManager() { > if (statusDialog == null) { > initStatusDialogManager(); > } >@@ -159,5 +170,6 @@ > private void initStatusDialogManager() { > statusDialog = new WorkbenchStatusDialogManager(null); > configureStatusDialog(statusDialog); >+ statusDialog.setStatusDialogListener(listener); > } > } >Index: Eclipse UI/org/eclipse/ui/internal/statushandlers/IStatusDialogListener.java >=================================================================== >RCS file: Eclipse UI/org/eclipse/ui/internal/statushandlers/IStatusDialogListener.java >diff -N Eclipse UI/org/eclipse/ui/internal/statushandlers/IStatusDialogListener.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI/org/eclipse/ui/internal/statushandlers/IStatusDialogListener.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,20 @@ >+/******************************************************************************* >+ * 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.internal.statushandlers; >+ >+/** >+ * This interface allows for listening to dialog state changes. >+ * @since 3.4 >+ */ >+public interface IStatusDialogListener { >+ 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 30 Sep 2008 12:09:16 -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; >@@ -42,6 +43,8 @@ > import org.eclipse.ui.statushandlers.AbstractStatusAreaProvider; > import org.eclipse.ui.statushandlers.IStatusAdapterConstants; > 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 +54,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( >@@ -59,10 +63,12 @@ > > private boolean automatedMode; > WorkbenchStatusDialogManager wsdm; >+ WorkbenchErrorHandler weh; > > protected void setUp() throws Exception { > automatedMode = ErrorDialog.AUTOMATED_MODE; >- wsdm = new WorkbenchStatusDialogManager(null, null); >+ weh = new WorkbenchErrorHandler(); >+ wsdm = weh.getStatusDialogManager(); > ErrorDialog.AUTOMATED_MODE = false; > super.setUp(); > } >@@ -73,6 +79,110 @@ > 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() { >+ wsdm = weh.getStatusDialogManager(); >+ 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() { >+ 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 >+ && wsdm.getStatusAdapters().size() == 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);
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