| How can I prevent a part stack from switching view parts? [message #902285] |
Thu, 16 August 2012 14:25  |
Ulrich Obst Messages: 12 Registered: August 2012 |
Junior Member |
|
|
Hi everybody,
In my application I have a partstack containing some parts. If the user changes some data in a part and switches to another part, I would like to ask him in a dialog if he wants to save the data. The user can answer with Yes, No or Cancel.
Now I have two problems:
1. In order to display that dialog I must get informed *before* the part is switched. (Using the UILifeCycle Events it seems I get informed after the part has switched)
2. If the user chooses "Cancel" the active part should not switched. The part with the modified data should remain on top.
I have no idea how to implement such a behavior using e4. Any ideas?
Thanks
Ulli
|
|
|
|
|
| Re: How can I prevent a part stack from switching view parts? [message #902801 is a reply to message #902779] |
Mon, 20 August 2012 09:49   |
Joseph Carroll Messages: 156 Registered: May 2012 Location: Milwaukee, WI |
Senior Member |

|
|
It sounds like you would need to customize the PartService:
org.eclipse.e4.ui.internal.workbench.PartServiceImpl {
...
private void activate(MPart part, boolean requiresFocus, boolean activateBranch) {
if (windowContext.getParent().getActiveChild() == windowContext && part == activePart) {
// insert it in the beginning of the activation history, it may not have been inserted
// pending when this service was instantiated
partActivationHistory.prepend(part);
UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part);
return;
} /* NEW CODE: */
else {
UIEvents.publishEvent(UIEvents.UILifeCycle.DEACTIVATE, activePart);
}
The use of deactivate might be a little missleading, but it demonstrates the point (maybe something like LOSTACTIVEPART). Not sure how broad of an application this would have or if it would be a feature others would be intersted in, however, it seems as though it would be relatively straight forward to implement.
JD
|
|
|
|
|
| Re: How can I prevent a part stack from switching view parts? [message #902828 is a reply to message #902822] |
Mon, 20 August 2012 12:11  |
Thomas Schindl Messages: 4462 Registered: July 2009 |
Senior Member |
|
|
If the tab switching is done by the UI (user clicks on tab) the activate
is happening after the UI switched the Tab. You don't notice that
because all the stuff is done on the UI-Thread.
So that's not a bug in a of our code but works as designed. The only
possible solution is to cancel the mouse even like you've done.
Tom
Am 20.08.12 17:37, schrieb Joseph Carroll:
> Fair point... I would actually consider that a bug, but I don't know if
> switching the active part with the part service is considered API or not.
>
> Is the data lost immediately if the active part is switched? Or could
> you go back after the switch to save the data?
|
|
|
Powered by
FUDForum. Page generated in 0.02163 seconds