aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-04-24 11:07:16 (EDT)
committerOleg Besedin2012-04-24 11:07:48 (EDT)
commit571a10a64ba8c021d64d50a09407f9a90c2112ee (patch)
tree22300c7e6fbf00e5edfe39a08c8182e72676c237
parentc138e4e57079cc7015197ecf6621880e6f75b445 (diff)
downloadeclipse.platform.ui-571a10a64ba8c021d64d50a09407f9a90c2112ee.zip
eclipse.platform.ui-571a10a64ba8c021d64d50a09407f9a90c2112ee.tar.gz
eclipse.platform.ui-571a10a64ba8c021d64d50a09407f9a90c2112ee.tar.bz2
Bug 373529 - [Compatibility] IPageListener's pageOpened(*) is sent out
too early
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java65
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java3
2 files changed, 61 insertions, 7 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index eb0dd8d..fec944c 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -115,6 +115,7 @@ import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
@@ -420,6 +421,8 @@ public final class Workbench extends EventManager implements IWorkbench {
boolean initializationDone = false;
+ private WorkbenchWindow activatedWindow;
+
/**
* Creates a new workbench.
*
@@ -933,6 +936,10 @@ public final class Workbench extends EventManager implements IWorkbench {
* The window which just closed; should not be <code>null</code>.
*/
protected void fireWindowClosed(final IWorkbenchWindow window) {
+ if (activatedWindow == window) {
+ // Do not hang onto it so it can be GC'ed
+ activatedWindow = null;
+ }
Object list[] = getListeners();
for (int i = 0; i < list.length; i++) {
final IWindowListener l = (IWindowListener) list[i];
@@ -1202,14 +1209,60 @@ public final class Workbench extends EventManager implements IWorkbench {
return null;
}
- MWindow activeWindow = application.getSelectedElement();
- if (activeWindow == null && !application.getChildren().isEmpty()) {
- activeWindow = application.getChildren().get(0);
+ // Look at the current shell and up its parent
+ // hierarchy for a workbench window.
+ Control shell = display.getActiveShell();
+ while (shell != null) {
+ Object data = shell.getData();
+ if (data instanceof IWorkbenchWindow) {
+ return (IWorkbenchWindow) data;
+ }
+ shell = shell.getParent();
+ }
+
+ // Look for the window that was last known being
+ // the active one
+ WorkbenchWindow win = getActivatedWindow();
+ if (win != null) {
+ return win;
+ }
+
+ // Look at all the shells and pick the first one
+ // that is a workbench window.
+ Shell shells[] = display.getShells();
+ for (int i = 0; i < shells.length; i++) {
+ Object data = shells[i].getData();
+ if (data instanceof IWorkbenchWindow) {
+ return (IWorkbenchWindow) data;
+ }
+ }
+
+ // Can't find anything!
+ return null;
+ }
+
+ /*
+ * Returns the workbench window which was last known being the active one,
+ * or <code> null </code> .
+ */
+ private WorkbenchWindow getActivatedWindow() {
+ if (activatedWindow != null) {
+ Shell shell = activatedWindow.getShell();
+ if (shell != null && !shell.isDisposed()) {
+ return activatedWindow;
+ }
}
- return createWorkbenchWindow(getDefaultPageInput(), getPerspectiveRegistry()
- .findPerspectiveWithId(getPerspectiveRegistry().getDefaultPerspective()),
- activeWindow, false);
+ return null;
+ }
+
+ /*
+ * Sets the workbench window which was last known being the active one, or
+ * <code> null </code> .
+ */
+ /* package */
+ void setActivatedWindow(WorkbenchWindow window) {
+ activatedWindow = window;
}
IWorkbenchWindow createWorkbenchWindow(IAdaptable input, IPerspectiveDescriptor descriptor,
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index dd8b031..d0df087 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -515,13 +515,13 @@ public class WorkbenchWindow implements IWorkbenchWindow {
ContextInjectionFactory.inject(page, model.getContext());
windowContext.set(IWorkbenchPage.class, page);
- firePageOpened();
menuManager.setOverrides(menuOverride);
((CoolBarToTrimManager) getCoolBarManager2()).setOverrides(toolbarOverride);
// Fill the action bars
fillActionBars(FILL_ALL_ACTION_BARS);
+ firePageOpened();
List<MPerspectiveStack> ps = modelService.findElements(model, null,
MPerspectiveStack.class, null);
@@ -1766,6 +1766,7 @@ public class WorkbenchWindow implements IWorkbenchWindow {
public void shellActivated(ShellEvent event) {
shellActivated = true;
serviceLocator.activate();
+ getWorkbenchImpl().setActivatedWindow(WorkbenchWindow.this);
if (getActivePage() != null) {
getWorkbenchImpl().fireWindowActivated(WorkbenchWindow.this);
}