1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 02:05:39 +02:00

[fix] view handling must be force to run in UI thread

This commit is contained in:
Uwe Stieber 2007-01-05 13:16:46 +00:00
parent bfeb822919
commit bbd2e76c13

View file

@ -42,6 +42,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.tests.RSETestsPlugin; import org.eclipse.rse.tests.RSETestsPlugin;
import org.eclipse.rse.tests.core.RSEWaitAndDispatchUtil.IInterruptCondition; import org.eclipse.rse.tests.core.RSEWaitAndDispatchUtil.IInterruptCondition;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
@ -49,6 +50,7 @@ import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException; import org.eclipse.ui.WorkbenchException;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
@ -61,7 +63,7 @@ public class RSECoreTestCase extends TestCase {
private final Properties properties = new Properties(); private final Properties properties = new Properties();
// Internal. Used to remember view zoom state changes. // Internal. Used to remember view zoom state changes.
private boolean rseSystemsViewZoomStateChanged = false; private final String PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED = "rseSystemsViewZoomStateChanged"; //$NON-NLS-1$
/** /**
* Constructor. * Constructor.
@ -94,6 +96,7 @@ public class RSECoreTestCase extends TestCase {
setProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE, "org.eclipse.rse.ui.view.SystemPerspective"); //$NON-NLS-1$ setProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE, "org.eclipse.rse.ui.view.SystemPerspective"); //$NON-NLS-1$
setProperty(IRSECoreTestCaseProperties.PROP_FORCE_BACKGROUND_EXECUTION, false); setProperty(IRSECoreTestCaseProperties.PROP_FORCE_BACKGROUND_EXECUTION, false);
setProperty(IRSECoreTestCaseProperties.PROP_PERFORMANCE_TIMING_INCLUDE_SETUP_TEARDOWN, false); setProperty(IRSECoreTestCaseProperties.PROP_PERFORMANCE_TIMING_INCLUDE_SETUP_TEARDOWN, false);
setProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, false);
} }
/** /**
@ -348,32 +351,37 @@ public class RSECoreTestCase extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
String perspectiveId = getProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE); final String perspectiveId = getProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE);
assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$ assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$
// in case the test case is launched within a new workspace, the eclipse intro // all view managment must happen in the UI thread!
// view is hiding everything else. Find the intro page and hide it. PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
hideView("org.eclipse.ui.internal.introview", perspectiveId); //$NON-NLS-1$ public void run() {
// in case the test case is launched within a new workspace, the eclipse intro
// view is hiding everything else. Find the intro page and hide it.
hideView("org.eclipse.ui.internal.introview", perspectiveId); //$NON-NLS-1$
// toggle the Remote Systems View zoom state. // toggle the Remote Systems View zoom state.
rseSystemsViewZoomStateChanged = false; setProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, false);
IViewPart part = showView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId); IViewPart part = showView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId);
assertNotNull("RSE Remote System View is not available!", part); //$NON-NLS-1$ assertNotNull("RSE Remote System View is not available!", part); //$NON-NLS-1$
// Unfortunately, for the zooming, we needs the view reference and not the view part :-( // Unfortunately, for the zooming, we needs the view reference and not the view part :-(
IViewReference reference = findView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId); IViewReference reference = findView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId);
assertNotNull("Failed to lookup view reference for RSE Remote Systems View!", reference); //$NON-NLS-1$ assertNotNull("Failed to lookup view reference for RSE Remote Systems View!", reference); //$NON-NLS-1$
if (reference.getPage().getPartState(reference) != IWorkbenchPage.STATE_MAXIMIZED if (reference.getPage().getPartState(reference) != IWorkbenchPage.STATE_MAXIMIZED
&& isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, true)) { && isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, true)) {
reference.getPage().toggleZoom(reference); reference.getPage().toggleZoom(reference);
rseSystemsViewZoomStateChanged = true; setProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, true);
} else if (reference.getPage().getPartState(reference) == IWorkbenchPage.STATE_MAXIMIZED } else if (reference.getPage().getPartState(reference) == IWorkbenchPage.STATE_MAXIMIZED
&& isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, false)) { && isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, false)) {
reference.getPage().toggleZoom(reference); reference.getPage().toggleZoom(reference);
rseSystemsViewZoomStateChanged = true; setProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, true);
} }
}
});
// Give the UI a chance to repaint if the view zoom state changed // Give the UI a chance to repaint if the view zoom state changed
if (rseSystemsViewZoomStateChanged) RSEWaitAndDispatchUtil.waitAndDispatch(1000); if (isProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, true)) RSEWaitAndDispatchUtil.waitAndDispatch(1000);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -381,20 +389,25 @@ public class RSECoreTestCase extends TestCase {
*/ */
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
// restore the original view zoom state // restore the original view zoom state
if (rseSystemsViewZoomStateChanged) { if (isProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, true)) {
String perspectiveId = getProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE); final String perspectiveId = getProperty(IRSECoreTestCaseProperties.PROP_SWITCH_TO_PERSPECTIVE);
assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$ assertNotNull("Invalid null-value for test case perspective id!", perspectiveId); //$NON-NLS-1$
IViewReference reference = findView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId); // all view managment must happen in the UI thread!
assertNotNull("Failed to lookup view reference for RSE Remote Systems View!", reference); //$NON-NLS-1$ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
if (reference.getPage().getPartState(reference) == IWorkbenchPage.STATE_MAXIMIZED public void run() {
&& isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, true)) { IViewReference reference = findView(IRSEViews.RSE_REMOTE_SYSTEMS_VIEW_ID, perspectiveId);
reference.getPage().toggleZoom(reference); assertNotNull("Failed to lookup view reference for RSE Remote Systems View!", reference); //$NON-NLS-1$
} else if (reference.getPage().getPartState(reference) != IWorkbenchPage.STATE_MAXIMIZED if (reference.getPage().getPartState(reference) == IWorkbenchPage.STATE_MAXIMIZED
&& isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, false)) { && isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, true)) {
reference.getPage().toggleZoom(reference); reference.getPage().toggleZoom(reference);
} } else if (reference.getPage().getPartState(reference) != IWorkbenchPage.STATE_MAXIMIZED
rseSystemsViewZoomStateChanged = false; && isProperty(IRSECoreTestCaseProperties.PROP_MAXIMIZE_REMOTE_SYSTEMS_VIEW, false)) {
reference.getPage().toggleZoom(reference);
}
setProperty(PROP_RSE_SYSTEMS_VIEW_ZOOM_STATE_CHANGED, false);
}
});
} }
super.tearDown(); super.tearDown();
@ -408,9 +421,8 @@ public class RSECoreTestCase extends TestCase {
* @param viewId The unique view id. Must be not <code>null</code>. * @param viewId The unique view id. Must be not <code>null</code>.
* @param perspectiveId The unique perspective id within the view should be searched. Must be not <code>null</code>. * @param perspectiveId The unique perspective id within the view should be searched. Must be not <code>null</code>.
* @return The view reference instance to the view or <code>null</code> if not available. * @return The view reference instance to the view or <code>null</code> if not available.
* @throws WorkbenchException If the specified perspective could not be shown.
*/ */
protected final IViewReference findView(String viewId, String perspectiveId) throws WorkbenchException { protected final IViewReference findView(String viewId, String perspectiveId) {
assert viewId != null && perspectiveId != null; assert viewId != null && perspectiveId != null;
if (viewId == null || perspectiveId == null) return null; if (viewId == null || perspectiveId == null) return null;
@ -419,11 +431,15 @@ public class RSECoreTestCase extends TestCase {
IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbench workbench = PlatformUI.getWorkbench();
assertNotNull("Failed to query current workbench instance!", workbench); //$NON-NLS-1$ assertNotNull("Failed to query current workbench instance!", workbench); //$NON-NLS-1$
// and the corresponding currently active workbench window. // and the corresponding currently active workbench window.
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
assertNotNull("Failed to query currently active workbench window!", window); //$NON-NLS-1$ assertNotNull("Failed to query currently active workbench window!", window); //$NON-NLS-1$
// Now we have to switch to the specified perspecitve // Now we have to switch to the specified perspecitve
workbench.showPerspective(perspectiveId, window); try {
workbench.showPerspective(perspectiveId, window);
} catch (WorkbenchException e) {
SystemBasePlugin.logError("Failed to switch to requested perspective (id = " + perspectiveId + ")!", e); //$NON-NLS-1$ //$NON-NLS-2$
}
// From the active workbench window, we need the active workbench page // From the active workbench window, we need the active workbench page
IWorkbenchPage page = window.getActivePage(); IWorkbenchPage page = window.getActivePage();
@ -438,9 +454,8 @@ public class RSECoreTestCase extends TestCase {
* @param viewId The unique view id. Must be not <code>null</code>. * @param viewId The unique view id. Must be not <code>null</code>.
* @param perspectiveId The unique perspective id within the view should be activated. Must be not <code>null</code>. * @param perspectiveId The unique perspective id within the view should be activated. Must be not <code>null</code>.
* @return The view part instance to the view or <code>null</code> if it cannot be shown. * @return The view part instance to the view or <code>null</code> if it cannot be shown.
* @throws WorkbenchException If the specified perspective could not be shown.
*/ */
protected final IViewPart showView(String viewId, String perspectiveId) throws WorkbenchException { protected final IViewPart showView(String viewId, String perspectiveId) {
assert viewId != null && perspectiveId != null; assert viewId != null && perspectiveId != null;
if (viewId == null || perspectiveId == null) return null; if (viewId == null || perspectiveId == null) return null;
@ -453,13 +468,24 @@ public class RSECoreTestCase extends TestCase {
assertNotNull("Failed to query currently active workbench window!", window); //$NON-NLS-1$ assertNotNull("Failed to query currently active workbench window!", window); //$NON-NLS-1$
// Now we have to switch to the specified perspecitve // Now we have to switch to the specified perspecitve
workbench.showPerspective(perspectiveId, window); try {
workbench.showPerspective(perspectiveId, window);
} catch (WorkbenchException e) {
SystemBasePlugin.logError("Failed to switch to requested perspective (id = " + perspectiveId + ")!", e); //$NON-NLS-1$ //$NON-NLS-2$
}
// From the active workbench window, we need the active workbench page // From the active workbench window, we need the active workbench page
IWorkbenchPage page = window.getActivePage(); IWorkbenchPage page = window.getActivePage();
assertNotNull("Failed to query currently active workbench page!", page); //$NON-NLS-1$ assertNotNull("Failed to query currently active workbench page!", page); //$NON-NLS-1$
return page.showView(viewId); IViewPart part = null;
try {
part = page.showView(viewId);
} catch (PartInitException e) {
SystemBasePlugin.logError("Failed to show view (id = " + viewId + ")!", e); //$NON-NLS-1$ //$NON-NLS-2$
}
return part;
} }
/** /**
@ -467,9 +493,8 @@ public class RSECoreTestCase extends TestCase {
* *
* @param viewId The unique view id. Must be not <code>null</code>. * @param viewId The unique view id. Must be not <code>null</code>.
* @param perspectiveId The unique perspective id the view should be hidden from. Must be not <code>null</code>. * @param perspectiveId The unique perspective id the view should be hidden from. Must be not <code>null</code>.
* @throws WorkbenchException If the specified perspective could not be shown.
*/ */
protected final void hideView(String viewId, String perspectiveId) throws WorkbenchException { protected final void hideView(String viewId, String perspectiveId) {
assert viewId != null && perspectiveId != null; assert viewId != null && perspectiveId != null;
if (viewId == null || perspectiveId == null) return; if (viewId == null || perspectiveId == null) return;