|Controlling fragment contributions [message #1184271]
||Wed, 13 November 2013 10:40
| Ozgur Cagdas
Registered: May 2013
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.
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?
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?
[Updated on: Wed, 13 November 2013 17:43]
Report message to a moderator
|Re: Controlling fragment contributions [message #1196410 is a reply to message #1187789]
||Tue, 19 November 2013 11:59
| Sopot Cela
Registered: December 2010
Ozgur Cagdas wrote on Fri, 15 November 2013 10:30|
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.
Powered by FUDForum
. Page generated in 0.32216 seconds