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.
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
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.
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.
Paul Webster Messages: 6813 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
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
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.
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