Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null?
Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null? [message #325914] Mon, 03 March 2008 08:01 Go to next message
Jasper is currently offline JasperFriend
Messages: 84
Registered: July 2009
Member
How is it possible that HandlerUtil.getActiveWorkbenchWindow
occasionally returns null? (Or equivalently that
getActiveWorkbenchWindowChecked throws an Exception?)

We've observed that this happens sometimes, but it's unpredictable. Best
shot at reproducing it is repetitive wild clicking such that command
handlers calling these methods are invoked.

Thanks all,
Jasper.
Re: Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null? [message #325930 is a reply to message #325914] Mon, 03 March 2008 14:28 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

HandlerUtil#getActiveWorkbenchWindow(*) will return null most
consistently when a dialog is up (the active Shell is a dialog).

What usecases are you seeing where that happens? Just opening or just
closing a dialog and then executing a command? Shell based popups (like
the F2 javadoc window)?

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null? [message #325950 is a reply to message #325930] Tue, 04 March 2008 03:54 Go to previous messageGo to next message
Jasper is currently offline JasperFriend
Messages: 84
Registered: July 2009
Member
Paul,

We've seen this happen when executing handlers for commands associated
with toolbar items. The code is typically something like:

public Object execute(ExecutionEvent event) throws ExecutionException {
try {
// Spawn a dialog
IWorkbenchWindow window =
HandlerUtil.getActiveWorkbenchWindowChecked(event);
SomeDialog dialog = new SomeDialog(window.getShell());
dialog.open();
// ...
}
catch (Throwable t) {
// ...
}
}

Is it possible that a user invokes the handler once, closes the spawned
dialog, and then invokes the handler a second time fast enough that the
framework didn't yet get around to re-assigning the active workbench
window to ISources.ACTIVE_WORKBENCH_WINDOW_NAME ?

Thanks,
Jasper.


Paul Webster wrote:
> HandlerUtil#getActiveWorkbenchWindow(*) will return null most
> consistently when a dialog is up (the active Shell is a dialog).
>
> What usecases are you seeing where that happens? Just opening or just
> closing a dialog and then executing a command? Shell based popups (like
> the F2 javadoc window)?
>
> Later,
> PW
>
>
Re: Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null? [message #325982 is a reply to message #325914] Wed, 05 March 2008 02:35 Go to previous messageGo to next message
Allan Ramirez is currently offline Allan RamirezFriend
Messages: 14
Registered: July 2009
Junior Member
In 3.3 I used this


PlatformUI.getWorkbench().getActiveWorkbenchWindow()
Re: Why does HandlerUtil.getActiveWorkbenchWindow sometimes return null? [message #326082 is a reply to message #325950] Fri, 07 March 2008 00:33 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Jasper wrote:
>
> Is it possible that a user invokes the handler once, closes the spawned
> dialog, and then invokes the handler a second time fast enough that the
> framework didn't yet get around to re-assigning the active workbench
> window to ISources.ACTIVE_WORKBENCH_WINDOW_NAME ?

That's entirely possible. Some of the work is driven by OS events and
some by asyncExec(*) calls ... but OS events are usually processed
before asyncExec(*) runnables.

It would be good to narrow it down to a specific use case (dialog closes
and then another dialog or window takes focus before the command can
work a second time).

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Help needed writing a custom expression for visibleWhen of a command menuContribution
Next Topic:Customizing cheat sheets
Goto Forum:
  


Current Time: Thu Jul 18 03:24:31 GMT 2024

Powered by FUDForum. Page generated in 0.04149 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top