Bug 433188 - Release EPartService.switchPerspective() as API
Summary: Release EPartService.switchPerspective() as API
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.6 M4   Edit
Assignee: Lars Vogel CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks:
 
Reported: 2014-04-22 06:53 EDT by Tim Oswald CLA
Modified: 2015-11-20 01:47 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Oswald CLA 2014-04-22 06:53:54 EDT
Regarding the JAVADOC, the EPartService.switchPerpective() of org.eclipse.e4.ui.workbench.modeling is NOT intended to be referenced by clients

We use this function to switch between different perspectives from our code, i.e. we are referencing this function in our client code, because we havn't found any other function!

But the "API Use Report" flag it as illegal.

From my perspective either the JAVADOC needs to be changed that this function can be used from clients.
Comment 1 Dani Megert CLA 2014-04-22 08:38:17 EDT
(In reply to Tim Oswald from comment #0)
> Regarding the JAVADOC, the EPartService.switchPerpective() of
> org.eclipse.e4.ui.workbench.modeling is NOT intended to be referenced by
> clients
> 
> We use this function to switch between different perspectives from our code,
> i.e. we are referencing this function in our client code, because we havn't
> found any other function!

Did you try org.eclipse.ui.IWorkbenchPage.setPerspective(IPerspectiveDescriptor)?
Comment 2 Tim Oswald CLA 2014-04-22 09:29:58 EDT
Our application is a pure e4 application and in my understanding, the IWorkbenchPage is eclipse 3.x and can not be used in e4?! Please correct me if I', wrong.
Therefore I can not use this function in our environment.
Comment 3 Dani Megert CLA 2014-04-22 09:32:37 EDT
> Our application is a pure e4 application
Wasn't clear from your initial comment.

Paul, please advise.
Comment 4 Paul Webster CLA 2014-04-22 09:48:42 EDT
The javadoc [1] describes the method and then says:

Restriction:
    This method is not intended to be referenced by clients.

It seems pretty consistent to me, you *should* get an illegal use exception with the API tooling.

Or are you asking why can't you use that method, because you couldn't find any other method?

PW

[1] http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fe4%2Fui%2Fworkbench%2Fmodeling%2FEPartService.html&anchor=switchPerspective%28org.eclipse.e4.ui.model.application.ui.advanced.MPerspective%29
Comment 5 Thomas Schindl CLA 2014-04-22 09:50:46 EDT
So how would we want people to switch between perspectives?
Comment 6 Paul Webster CLA 2014-04-22 10:01:01 EDT
Perspectives are mainly a Workbench artifact.

What does it mean to even have a perspective in an Eclipse4 app?  We never defined the semantics of them without the compatibility layer (which is why although there is a method there, it's not API since we don't have a complete definition of what it will do).

PW
Comment 7 Thomas Schindl CLA 2014-04-22 10:03:43 EDT
of course they have meaning in e4 - perspectives are a valid but not mandatory concept in e4
Comment 8 Paul Webster CLA 2014-04-22 10:07:16 EDT
(In reply to Thomas Schindl from comment #7)
> of course they have meaning in e4 - perspectives are a valid but not
> mandatory concept in e4

I'm not saying they don't have meaning, I'm saying that meaning is not well defined.  i.e. can I find a wiki page that describes how to set up 2 perspectives in an Eclipse4 application?

And that still doesn't change the fact that switchPerspective(*) is not ready to be API because since I don't know the proper usecase to switch perspectives, I can't say what it'll do.

PW
Comment 9 Tim Oswald CLA 2014-04-22 10:13:41 EDT
(In reply to Paul Webster from comment #6)
> Perspectives are mainly a Workbench artifact.
> 
> What does it mean to even have a perspective in an Eclipse4 app?  We never
> defined the semantics of them without the compatibility layer (which is why
> although there is a method there, it's not API since we don't have a
> complete definition of what it will do).
> 
> PW

We're using the "Perspective Stack" and different "Perspectives" as childs in the e4xmi model and we need a method to switch between the different perspectives. The switchPerspective() method from the EPartService works fine just with the exception, that it should not be used from the JAVADOC.
Comment 10 Thomas Schindl CLA 2014-04-22 14:27:34 EDT
(In reply to Paul Webster from comment #8)
> (In reply to Thomas Schindl from comment #7)
> > of course they have meaning in e4 - perspectives are a valid but not
> > mandatory concept in e4
> 
> I'm not saying they don't have meaning, I'm saying that meaning is not well
> defined.  i.e. can I find a wiki page that describes how to set up 2
> perspectives in an Eclipse4 application?

I'm sorry but I can't follow this argumentation - there are many things in e4 that are not document completely - and I can/will fix that for MPerspective.

The MPerspective element is API and can & is be used - what do you see as not defined for it?

I don't see what is not defined for MPerspective/MPerspectiveStack it acts and works the same way it did in 3.x or the compat layer and most complex e4 apps make use of them including MPlaceholder.
Comment 11 Paul Webster CLA 2014-04-22 14:43:41 EDT
(In reply to Thomas Schindl from comment #10)
> (In reply to Paul Webster from comment #8)
> > (In reply to Thomas Schindl from comment #7)
> > > of course they have meaning in e4 - perspectives are a valid but not
> > > mandatory concept in e4
> > 
> > I'm not saying they don't have meaning, I'm saying that meaning is not well
> > defined.  i.e. can I find a wiki page that describes how to set up 2
> > perspectives in an Eclipse4 application?
> 
> I'm sorry but I can't follow this argumentation - there are many things in
> e4 that are not document completely - and I can/will fix that for
> MPerspective.
> 
> The MPerspective element is API and can & is be used - what do you see as
> not defined for it?

MPerspective is API, and of course people are free to use it.  switchPerspective(*) is not.  Right now, switchPerspective(*) sets up the model as we understand it to support switching perspectives for the Workbench, where the Workbench does work before and after that's called.

I'm not saying it can never be made API, if someone is willing to make it clean for Eclipse4 while supporting perspective switching in the Workbench, but that's definitely not its state right now.

And why is it being called now anyway?  When you set your MPerspective as selected in your MPerspectiveStack, you should get switchPerspective(*) called for free.

PW
Comment 12 Thomas Schindl CLA 2014-04-22 15:12:33 EDT
> MPerspective is API, and of course people are free to use it. 
> switchPerspective(*) is not.  Right now, switchPerspective(*) sets up the
> model as we understand it to support switching perspectives for the
> Workbench, where the Workbench does work before and after that's called.
> 

right and I don't see why that should be different on e4 - the workbench is simply a big e4 app - if someone is not happy in how we interpret perspective switching he can push his own EPartService

> I'm not saying it can never be made API, if someone is willing to make it
> clean for Eclipse4 while supporting perspective switching in the Workbench,
> but that's definitely not its state right now.
> 

Why is it not clean in Eclipse4 the current implementation works just fine and does what people expect.

> And why is it being called now anyway?  When you set your MPerspective as
> selected in your MPerspectiveStack, you should get switchPerspective(*)
> called for free.


right the PerspectiveStackRenderer calls it when the selectedElement is changed.
Comment 13 Tim Oswald CLA 2014-04-23 09:11:44 EDT
As we have migrated to e4, we have followed the samples from Lars Vogel, which were very helpul. In his sample below, he describes how to switch perspectives and that's the way we have implemented it.
http://www.vogella.com/tutorials/Eclipse4Services/article.html#selectedservices_partservice4
Comment 14 Paul Webster CLA 2014-04-23 09:28:00 EDT
(In reply to Tim Oswald from comment #13)
> As we have migrated to e4, we have followed the samples from Lars Vogel,
> which were very helpul. In his sample below, he describes how to switch
> perspectives 

That's not the way to do it.  Switching perspectives should use the model API, which means setting the selected element on the MPerspectiveStack.

PW
Comment 15 Thomas Schindl CLA 2014-04-23 09:31:02 EDT
I more and more doubt this method should be available at all - i think the renderers or an internal service would be the appropriate place then.

The compat layer would then simply do the same thing and set a new selectedElement in the model.
Comment 16 Thomas Schindl CLA 2014-04-23 09:33:57 EDT
Or let me put it differently:
a) we keep switchPerspective() but remove the logic in there all it does is check if the given MPerspective is a child of the stack
b) we move the logic to the renderer
Comment 17 Tim Oswald CLA 2014-04-23 10:03:49 EDT
(In reply to Paul Webster from comment #14)
> (In reply to Tim Oswald from comment #13)
> > As we have migrated to e4, we have followed the samples from Lars Vogel,
> > which were very helpul. In his sample below, he describes how to switch
> > perspectives 
> 
> That's not the way to do it.  Switching perspectives should use the model
> API, which means setting the selected element on the MPerspectiveStack.
> 
> PW

That's right - the following code works:

MPerspective element = .....
// Now switch perspective
if(element != null && element.getParent() != null){
    Object parent = element.getParent();
    if(parent instanceof MPerspectiveStack){
  	MPerspectiveStack mps = (MPerspectiveStack)parent;
        mps.setSelectedElement(element);
    }
}

In regards that all MPerspective objects in the model will be kept by a MPerspectiveStack, the stack can actually do the stuff
Comment 18 Lars Vogel CLA 2015-11-19 04:46:51 EST
Lots of my customers using the switchPerspective in their e4 RCP application. I agree with Tom that we should release the switchPerspective method as API.
Comment 19 Eclipse Genie CLA 2015-11-19 04:52:31 EST
New Gerrit change created: https://git.eclipse.org/r/60773
Comment 20 Thomas Schindl CLA 2015-11-19 06:15:59 EST
Well isn't there discussion in some thread that switchPerspective fails with shared-parts somehow. So why making it public when we maybe might Deprecate it?
Comment 21 Lars Vogel CLA 2015-11-19 06:51:01 EST
(In reply to Thomas Schindl from comment #20)
> Well isn't there discussion in some thread that switchPerspective fails with
> shared-parts somehow. So why making it public when we maybe might Deprecate
> it?

Switch perspective works fine with shared parts. I think you referencing to the cloneSnippet bug, which is completely unrelated to switchPerspective
Comment 22 Thomas Schindl CLA 2015-11-19 07:07:09 EST
Ah you are right
Comment 24 Lars Vogel CLA 2015-11-20 01:47:31 EST
.