Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Creating a Perspective with a Processor
Creating a Perspective with a Processor [message #1442888] Sat, 11 October 2014 21:24 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
I created a little sample application, which got a Perspective Stack and two Perspectives defined via the Application.e4xmi

i added handlers to switch between those perspectives via menu.

now I'm trying to create Perspectives dynamically with a Processor.
this should be possible via the MPerspectiveStack iff one exists.

1) as i defined one in my Application.e4.xmi i think one should exist.
2) when i execute my Handler below nothing (not even an Exception) happens

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.core.di.annotations.Execute;

public class CreatePerspectiveHandler {

	@Execute
	public void execute(MPerspectiveStack perspectiveStack) {
		System.out.println("perspectiveStack -> "+ perspectiveStack);
	}
}

i expected it to either log an Exception to the Console or the sysout i entered.

it seems i cannot inject it this way.
therefore i tried to go another way:
@Execute
	public void execute(MPerspective perspective) {
		System.out.println("MPerspective -> "+ perspective);
		MElementContainer<MUIElement> pStack = perspective.getParent();
		System.out.println("parent: "+pStack);
		if (pStack instanceof MPerspectiveStack) {
			System.out.println("yay!");
		}
	}


log say pStack is instance of PerspectiveStackImpl, which implements MPartStack, but i cannot cast it to this interface...
Quote:
Type mismatch: cannot convert from MElementContainer<MUIElement> to MPerspectiveStack


so whats the correct way to create a perspective programmatically?
Re: Creating a Perspective with a Processor [message #1443397 is a reply to message #1442888] Sun, 12 October 2014 17:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6580
Registered: July 2009
Senior Member
the compiler simply is too dumb - cast it intermediately to an
MUIElement and then to MPerspectiveStack

Tom

On 11.10.14 23:24, Ludwig Moser wrote:
> I created a little sample application, which got a Perspective Stack and
> two Perspectives defined via the Application.e4xmi
>
> i added handlers to switch between those perspectives via menu.
>
> now I'm trying to create Perspectives dynamically with a Processor.
> this should be possible via the MPerspectiveStack iff one exists.
>
> 1) as i defined one in my Application.e4.xmi i think one should exist.
> 2) when i execute my Handler below nothing (not even an Exception) happens
>
>
> import org.eclipse.core.commands.ExecutionException;
> import org.eclipse.e4.core.di.annotations.Execute;
>
> public class CreatePerspectiveHandler {
>
> @Execute
> public void execute(MPerspectiveStack perspectiveStack) {
> System.out.println("perspectiveStack -> "+ perspectiveStack);
> }
> }
>
> i expected it to either log an Exception to the Console or the sysout i
> entered.
>
> it seems i cannot inject it this way.
> therefore i tried to go another way:
>
> @Execute
> public void execute(MPerspective perspective) {
> System.out.println("MPerspective -> "+ perspective);
> MElementContainer<MUIElement> pStack = perspective.getParent();
> System.out.println("parent: "+pStack);
> if (pStack instanceof MPerspectiveStack) {
> System.out.println("yay!");
> }
> }
>
>
> log say pStack is instance of PerspectiveStackImpl, which implements
> MPartStack, but i cannot cast it to this interface...
> Quote:
>> Type mismatch: cannot convert from MElementContainer<MUIElement> to
>> MPerspectiveStack
>
>
> so whats the correct way to create a perspective programmatically?
Re: Creating a Perspective with a Processor [message #1443430 is a reply to message #1443397] Sun, 12 October 2014 18:44 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
after posting this last night i found a another way to get it...

@Execute
	public void execute(MPerspective perspective) {
		MUIElement muiElement = perspective.getParent();
		MPerspectiveStack pStack = (MPerspectiveStack) muiElement ;
		if (pStack instanceof MPerspectiveStack) {
			System.out.println("yay!");
		}
	}

@Execute
	public void execute(MApplication app) {
			MWindow l = app.getChildren().get(0);
			MPerspectiveStack pStack = (MPerspectiveStack) l.getChildren().get(0);
	}


which one do you suggest/prefer?
Re: Creating a Perspective with a Processor [message #1443442 is a reply to message #1443430] Sun, 12 October 2014 19:06 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6580
Registered: July 2009
Senior Member
On 12.10.14 20:44, Ludwig Moser wrote:
> after posting this last night i found a another way to get it...
>
>
> @Execute
> public void execute(MPerspective perspective) {
> MUIElement muiElement = perspective.getParent();
> MPerspectiveStack pStack = (MPerspectiveStack) muiElement ;
> if (pStack instanceof MPerspectiveStack) {
> System.out.println("yay!");
> }
> }
>
>
> @Execute
> public void execute(MApplication app) {
> MWindow l = app.getChildren().get(0);
> MPerspectiveStack pStack = (MPerspectiveStack)
> l.getChildren().get(0);
> }
>
>
> which one do you suggest/prefer?

the 2nd is better, there's a chance that there's no perspective available!

Tom
Previous Topic:[DELETE ME] E4 getting started problem
Next Topic:How to create an View with parameters
Goto Forum:
  


Current Time: Tue Jan 19 19:45:19 GMT 2021

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

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

Back to the top