Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How can I prevent a part stack from switching view parts?
How can I prevent a part stack from switching view parts? [message #902285] Thu, 16 August 2012 14:25 Go to next message
Ulrich Obst is currently offline 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 #902331 is a reply to message #902285] Fri, 17 August 2012 02:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5005
Registered: July 2009
Senior Member
I fear you need to role your own PartStackRenderer but even then I'm not
sure you can do what you want because the SWT.Selection event is fired
after the switch as well.

Tom

Am 16.08.12 20:25, schrieb Ulrich Obst:
> 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 #902779 is a reply to message #902285] Mon, 20 August 2012 07:57 Go to previous messageGo to next message
Ulrich Obst is currently offline Ulrich Obst
Messages: 12
Registered: August 2012
Junior Member
Hi,

thanks for the answer. I finally got a solution:
I installed an event filter in the SWT event queue, that checks if a mouse click in a CTabFolder occurs and the if the clicked CTabItem is associated with a ViewPart and if a dirty ViewPart exists in the same CTabFolder. In this case I can open a dialog and maybe cancel the events. This code works well but it smells not very good because I use the internal knowledge how to get from the CTabItem to the corresponding MPart.

Creating my own Renderer might be a better solution.

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 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
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 #902817 is a reply to message #902801] Mon, 20 August 2012 11:12 Go to previous messageGo to next message
Ulrich Obst is currently offline Ulrich Obst
Messages: 12
Registered: August 2012
Junior Member
This was my first approach but unfortunately it does not work. If the call to PartServiceImpl.activate(...) is ignored for some reason, the CTabFolder switches the part anyway. And after that the ui shows a part that is not activated by the part service and the whole thing is in an inconsistent state.
Re: How can I prevent a part stack from switching view parts? [message #902822 is a reply to message #902817] Mon, 20 August 2012 11:37 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

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?
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 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5005
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?
Previous Topic:ActionBarContributor
Next Topic:DeferredTreeContentManager & co.
Goto Forum:
  


Current Time: Thu Apr 17 00:06:22 EDT 2014

Powered by FUDForum. Page generated in 0.01654 seconds