Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Controlling fragment contributions(How to activate/deactivate contributions by different fragments on run time)
Controlling fragment contributions [message #1184271] Wed, 13 November 2013 10:40 Go to next message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Hi,

I have an e4 RCP application. There are multiple 'perspectives' in this application and each 'perspective' is contributed to the 'perspective stack' by a different 'fragment'.

I need to find answers to below questions before going any further with the design and I'd like to keep things as 'e4' as possible and also get benefit of the e4xmi's too.

Scneario 1;
User normally interacts through the 'handle tool items' sitting on a toolbar. There are some buttons which are visually common across all the perspectives (i.e. 'run') but they do different jobs depending on which perspective is active. So, I'm not sure how to achieve this cleanly without throwing 'if(perspective == ' checks all around.

I am thinking that each fragment can register a 'handler' for shared commands but is there a clean way to register/unregister handlers contributed by a fragment on a trigger? So the button will always send the same command but it will be handled by the appropriate handler. I wouldn't like to have multiple handlers registered for the same command either.

Having mentioned the trigger, does the framework emit any events on perspective change?

Scenario 2,
Some perspectives have their own buttons which need to be added/removed (or activated/deactivated) on perspective change similar to above. Again, what could be a neat solution to this?

Regards,

Ozgur.

[Updated on: Wed, 13 November 2013 17:43]

Report message to a moderator

Re: Controlling fragment contributions [message #1185801 is a reply to message #1184271] Thu, 14 November 2013 09:19 Go to previous messageGo to next message
Eclipse UserFriend
1. The handlers are executed on the active MPart's context so injecting MPerspective directly should give you the active perspective.

@Execute
public void ex(MPerspective p, blabla){...}
Re: Controlling fragment contributions [message #1187789 is a reply to message #1185801] Fri, 15 November 2013 09:30 Go to previous messageGo to next message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Thanks Sopot,

If I'm not missing anything, you are suggesting to check the active perspective against the desired one at the beginning of handlers which share the same command, so handler continues or terminates accordingly, am I right? If so, that's pretty much what I described as putting 'if(perspective == ' checks which I'd try to avoid if possible because other people are likely to contribute to this application I am working on by different fragments in the future. Therefore, I'd like to keep the complexity and dogmatic rules at minimum as much as possible if that makes sense.

Is there a way to get the list of 'elements' (in my case handlers and handled tool items) contributed by a fragment and enable/disable them programmatically?

Or once the e4xmis are all merged together during the start up, is the originating fragment information lost?

And is there an event emitted by the system when the active perspective is changed?

Regards,

O.
Re: Controlling fragment contributions [message #1196410 is a reply to message #1187789] Tue, 19 November 2013 11:59 Go to previous messageGo to next message
Eclipse UserFriend
Ozgur Cagdas wrote on Fri, 15 November 2013 10:30
Thanks Sopot,

If I'm not missing anything, you are suggesting to check the active perspective against the desired one at the beginning of handlers which share the same command, so handler continues or terminates accordingly, am I right? If so, that's pretty much what I described as putting 'if(perspective == ' checks which I'd try to avoid if possible because other people are likely to contribute to this application I am working on by different fragments in the future. Therefore, I'd like to keep the complexity and dogmatic rules at minimum as much as possible if that makes sense.

Is there a way to get the list of 'elements' (in my case handlers and handled tool items) contributed by a fragment and enable/disable them programmatically?

Or once the e4xmis are all merged together during the start up, is the originating fragment information lost?

Yes. You can always swap (extend) the merging mechanism to suit your needs but that's overkill. Why not prefix all your elments ID with the perspective ID (or a shorter version of it) and filter them this way?

And is there an event emitted by the system when the active perspective is changed?

Sure. Listen to UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT and check that the changed object is an MPerspectiveStack. New value contains the new selection. Old Value the old one. http://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/LazyStackRenderer.java - lazyLoader eventHandler.

Regards,

O.

Re: Controlling fragment contributions [message #1218673 is a reply to message #1196410] Fri, 29 November 2013 11:34 Go to previous message
Ozgur Cagdas is currently offline Ozgur CagdasFriend
Messages: 32
Registered: May 2013
Member
Thanks,

I've opted for setting up the handler you suggested on start up and pasted an example implementation below if somebody ever needs it.

EventHandler perspectiveSwitchHandler = new EventHandler() {
	public void handleEvent(Event event) {
		Object element = event.getProperty(UIEvents.EventTags.ELEMENT);

			if (!(element instanceof MPerspectiveStack))
				return;
							
			MUIElement newSel = (MUIElement) event.getProperty(UIEvents.EventTags.NEW_VALUE);
			if (newSel != null && newSel instanceof MPerspective) {
				MPerspective perspective = (MPerspective)newSel;
				String perspectiveId = perspective.getElementId();
								
				IEclipseContext context = application.getContext();
				ECommandService commandService = context.get(ECommandService.class);
				EHandlerService handlerService = context.get(EHandlerService.class);
													
				ParameterizedCommand procOptAddCommand = 
					commandService.createCommand("com.myorg.command.perspective_changed", null);
				handlerService.executeHandler(procOptAddCommand);
			}
		}
	};
	eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT, perspectiveSwitchHandler);

Previous Topic:Loading order of model fragment
Next Topic:Logger outside Application Model
Goto Forum:
  


Current Time: Tue Apr 16 17:06:02 GMT 2024

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

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

Back to the top