Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Command: hook in before OpenWorkspaceAction is called(I execute some custom behaviour befor the Switch-Workspace-Action is triggered)
icon4.gif  Command: hook in before OpenWorkspaceAction is called [message #668580] Fri, 06 May 2011 10:20 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Hello everyone

I am dealing with some Legacy-Code regarding the OpenWorkspaceAction. I want to execute some code, showing a message, before the actual Action is triggered.

The reason is that we provide a additional command for creating a new workspace that prepares a default-setup for our team. Anyway I already found this thread which makes me thing that I dont have a chance in hooking in before this action because it is registered directly in the MenuManager.

I was hoping that there is any way that I just didnt see to achieve this with Eclipse 3.6.2.

Thanks in advance
Marc

EDIT: damn...just found PWs reply on a recent thread Sad

[Updated on: Fri, 06 May 2011 10:24]

Report message to a moderator

Re: Command: hook in before OpenWorkspaceAction is called [message #668602 is a reply to message #668580] Fri, 06 May 2011 11:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If it is an action that is registered (so it would work with a
keybinding) you can always register an execution listener in the
ICommandService. Looks like the ID is org.eclipse.ui.file.openWorkspace

PW


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


Re: Command: hook in before OpenWorkspaceAction is called [message #669468 is a reply to message #668602] Tue, 10 May 2011 12:52 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Thanks for your reply Paul.

We tried your solution yesterday and unfortunately the open-workspace-action did not trigger the ExecutionListener. Other actions (like save-all) did.

I debuged into the workbench and saw that the OpenWorkspaceAction has no actionDefinitionId set. I was then trying to get a hold on the ActionRegistry but I couldnt find a way. It seems this is only accessible via a View which I don't have (its all done in the Activator).

Also withing the ActionFactory, which seems to me like a bridge between oldschool Actions and the new Commands, the OpenWorkspaceAction was one of the few that isn't handled.

Is there maybe any other Service that I could use to hook in?
Thanks
Re: Command: hook in before OpenWorkspaceAction is called [message #669489 is a reply to message #669468] Tue, 10 May 2011 13:55 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 05/10/2011 08:52 AM, Marc Schlegel wrote:
>
> Is there maybe any other Service that I could use to hook
> in?

What version of eclipse are you based on? My
org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction.Open WorkspaceAction(IWorkbenchWindow)
sets the action definition Id

PW


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


Re: Command: hook in before OpenWorkspaceAction is called [message #669498 is a reply to message #669489] Tue, 10 May 2011 14:21 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Strange...I am on 3.6.2
Re: Command: hook in before OpenWorkspaceAction is called [message #669516 is a reply to message #669498] Tue, 10 May 2011 14:51 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hmmm, maybe mine was changed in 3.7.

PW


Re: Command: hook in before OpenWorkspaceAction is called [message #669522 is a reply to message #669516] Tue, 10 May 2011 15:01 Go to previous messageGo to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
I looked it up again and you were right...the actionDefinitionId gets set within the Constructor. But when I was debugging into the Action when it was called the id was null and this caused the ExecutionListener not being triggered. I dont have the class open where this was checked so I will debug this again.

Thanks for your patience.

[Updated on: Wed, 11 May 2011 06:17]

Report message to a moderator

Re: Command: hook in before OpenWorkspaceAction is called [message #669669 is a reply to message #668580] Wed, 11 May 2011 06:17 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Found it again

In ActionContributionItem (line 552 in 3.6.2) there's following code-block
ExternalActionManager.IExecuteCallback callback = null;
String actionDefinitionId = action.getActionDefinitionId();
if (actionDefinitionId != null) {
	Object obj = ExternalActionManager.getInstance()
		.getCallback();
	if (obj instanceof ExternalActionManager.IExecuteCallback) {
		callback = (ExternalActionManager.IExecuteCallback) obj;
	}
}


For the OpenWorkspaceAction the actionDefinitionId is definately NULL at this point. For all other actions from the File-Menu the ID is available an the if-block is entered thus triggering the callback which leads to the ExecutionListener.

So it looks like this is a little bug. But we can live without hooking into this Action...it would just be about displaying a message anyway Wink
Previous Topic:Delete project contents on disk (cannot be undone).
Next Topic:Durable folder
Goto Forum:
  


Current Time: Tue Apr 16 15:56:43 GMT 2024

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

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

Back to the top