Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Swiching perspectives
Swiching perspectives [message #559272] Thu, 16 September 2010 08:49 Go to next message
Christian Sorensen is currently offline Christian Sorensen
Messages: 8
Registered: September 2010
Junior Member
Hi all

I can't seem to figure out how to change perspectives in the new 4.0 framework. I have created two different perspectives in the e4xmi file and would like to be able to switch between them dynamically.

Could somebody please point me in the right direction or maybe even provide example code.

Best regards
Christian
Re: Swiching perspectives [message #559297 is a reply to message #559272] Thu, 16 September 2010 10:04 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
You need to set the selectedElement in the PerspectiveStack.

Tom

Am 16.09.10 10:49, schrieb Christian Sorensen:
> Hi all
>
> I can't seem to figure out how to change perspectives in the new 4.0
> framework. I have created two different perspectives in the e4xmi file
> and would like to be able to switch between them dynamically.
>
> Could somebody please point me in the right direction or maybe even
> provide example code.
>
> Best regards Christian
Re: Swiching perspectives [message #559298 is a reply to message #559272] Thu, 16 September 2010 10:13 Go to previous messageGo to next message
Christian Sorensen is currently offline Christian Sorensen
Messages: 8
Registered: September 2010
Junior Member
Thanks for your reply Tom.

I now how to do that in the e4xmi file. But how do I do it in code? For instance if something is selected (by the user) in my application that makes me want to display another perspective.
Re: Swiching perspectives [message #559316 is a reply to message #559298] Thu, 16 September 2010 11:02 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
Well something like this:

---------8<---------
public class MyPart {
@Inject
private PerspectiveStack stack;

public void switch(String id) {
for( Perspective p : stack.getChildren() ) {
if( id.equals(p.getElementId()) ) {
stack.setSelectedElement(p);
break;
}
}
}
}
---------8<---------

For a Handler it should be similar which gets invoked through a
ParameterizedCommand (with parameter perspectiveId)

---------8<---------
public class MyHandler {
@Execute
public void execute(PerspectiveStack stack, @Named("perspectiveId")
String id) {
for( Perspective p : stack.getChildren() ) {
if( id.equals(p.getElementId()) ) {
stack.setSelectedElement(p);
break;
}
}
}
}
---------8<---------

Tom

Am 16.09.10 12:13, schrieb Christian Sorensen:
> Thanks for your reply Tom.
>
> I now how to do that in the e4xmi file. But how do I do it in code? For
> instance if something is selected (by the user) in my application that
> makes me want to display another perspective.
Re: Swiching perspectives [message #559327 is a reply to message #559272] Thu, 16 September 2010 11:58 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

You can have a look at
/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/u i/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.j ava
and that bundle's extensions to see how we do it in the compatibility layer

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Swiching perspectives [message #559342 is a reply to message #559272] Thu, 16 September 2010 12:30 Go to previous messageGo to next message
Christian Sorensen is currently offline Christian Sorensen
Messages: 8
Registered: September 2010
Junior Member
Thanks to both of you for helping. I tried to work with the example Tom provided and ended up with something like this:

@Inject private MPerspective perspective;

MElementContainer<MUIElement> stack = (MElementContainer<MUIElement>) perspective.getParent();
for( MUIElement p : stack.getChildren() ) {
System.out.println("PER: " + ((MPerspective)p).getLabel());
if (((MPerspective)p).getLabel().equals("Tokens")) {
stack.setSelectedElement(p);
}
}

I couldn't get the perspective stack injected for some reason.

\Christian
Re: Swiching perspectives [message #559349 is a reply to message #559342] Thu, 16 September 2010 12:47 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
Hm probably we are not adding it to the context in the renderer. You
could also use MWindow and use its 1st child.

Tom

Am 16.09.10 14:30, schrieb Christian Sorensen:
> Thanks to both of you for helping. I tried to work with the example Tom
> provided and ended up with something like this:
>
> @Inject private MPerspective perspective;
>
> MElementContainer<MUIElement> stack = (MElementContainer<MUIElement>)
> perspective.getParent();
> for( MUIElement p : stack.getChildren() ) {
> System.out.println("PER: " +
> ((MPerspective)p).getLabel());
> if (((MPerspective)p).getLabel().equals("Tokens")) {
> stack.setSelectedElement(p);
> }
> }
>
> I couldn't get the perspective stack injected for some reason.
>
> \Christian
Re: Swiching perspectives [message #581941 is a reply to message #559298] Thu, 16 September 2010 11:02 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
Well something like this:

---------8<---------
public class MyPart {
@Inject
private PerspectiveStack stack;

public void switch(String id) {
for( Perspective p : stack.getChildren() ) {
if( id.equals(p.getElementId()) ) {
stack.setSelectedElement(p);
break;
}
}
}
}
---------8<---------

For a Handler it should be similar which gets invoked through a
ParameterizedCommand (with parameter perspectiveId)

---------8<---------
public class MyHandler {
@Execute
public void execute(PerspectiveStack stack, @Named("perspectiveId")
String id) {
for( Perspective p : stack.getChildren() ) {
if( id.equals(p.getElementId()) ) {
stack.setSelectedElement(p);
break;
}
}
}
}
---------8<---------

Tom

Am 16.09.10 12:13, schrieb Christian Sorensen:
> Thanks for your reply Tom.
>
> I now how to do that in the e4xmi file. But how do I do it in code? For
> instance if something is selected (by the user) in my application that
> makes me want to display another perspective.
Re: Swiching perspectives [message #581992 is a reply to message #559342] Thu, 16 September 2010 12:47 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
Hm probably we are not adding it to the context in the renderer. You
could also use MWindow and use its 1st child.

Tom

Am 16.09.10 14:30, schrieb Christian Sorensen:
> Thanks to both of you for helping. I tried to work with the example Tom
> provided and ended up with something like this:
>
> @Inject private MPerspective perspective;
>
> MElementContainer<MUIElement> stack = (MElementContainer<MUIElement>)
> perspective.getParent();
> for( MUIElement p : stack.getChildren() ) {
> System.out.println("PER: " +
> ((MPerspective)p).getLabel());
> if (((MPerspective)p).getLabel().equals("Tokens")) {
> stack.setSelectedElement(p);
> }
> }
>
> I couldn't get the perspective stack injected for some reason.
>
> \Christian
Previous Topic:Swiching perspectives
Next Topic:Consistent duplication of custom xwt UI
Goto Forum:
  


Current Time: Fri Oct 24 18:51:21 GMT 2014

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

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