Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to create an View with parameters
How to create an View with parameters [message #1442934] Sat, 11 October 2014 23:02 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
i do know how i can create a view and generate contents on it.
simply by injecting a Composite...

but how can i create a View (MPart) with parameters?

I do know i can create a MPart from its Factory
MPart mPart = MBasicFactory.INSTANCE.createPart();


but with this instance i cannot add anything to it (right?)

i succeeded creating a predefined view with the injection mentioned before.
but i do want/need to generate the view by code and inject/pass parameters to it on construction time or @PostConstruct

any ideas how i can work that out?

PS: i googled and searched here but was not able to find a solution...
Re: How to create an View with parameters [message #1443398 is a reply to message #1442934] Sun, 12 October 2014 17:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
That's not really as simple - the only way to pass parameters is to put
them as strings into the persistedState. This might at first look odd
but there's a good reason for that.

On the next launch the framework has to have the possibility to restore
the state without you stepping in.

Tom

On 12.10.14 01:02, Ludwig Moser wrote:
> i do know how i can create a view and generate contents on it.
> simply by injecting a Composite...
>
> but how can i create a View (MPart) with parameters?
>
> I do know i can create a MPart from its Factory
>
> MPart mPart = MBasicFactory.INSTANCE.createPart();
>
>
> but with this instance i cannot add anything to it (right?)
>
> i succeeded creating a predefined view with the injection mentioned before.
> but i do want/need to generate the view by code and inject/pass
> parameters to it on construction time or @PostConstruct
>
> any ideas how i can work that out?
>
> PS: i googled and searched here but was not able to find a solution...
Re: How to create an View with parameters [message #1443435 is a reply to message #1443398] Sun, 12 October 2014 18:53 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
what i did now is:
define the MPart in the e4xmi which reads the parameters from an @Creatable
when i create the MPart then in code i set its ContributionURI to this predefined MPart.
this works, but i do not know if this is acceptable.
with your hint to put strings into the persistedState, how can i access it in the Part processor (the part processor is only a pojo it does not know about the persistedstate method)

FYI i'd recreate the views/perspectives on each launch, that would not be a problem.
Re: How to create an View with parameters [message #1443447 is a reply to message #1443435] Sun, 12 October 2014 19:11 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 12.10.14 20:53, Ludwig Moser wrote:
> what i did now is:
> define the MPart in the e4xmi which reads the parameters from an @Creatable
> when i create the MPart then in code i set its ContributionURI to this
> predefined MPart.

Why do you define this as an @Createable? The value provided through
contributionURI is always created through DI (in the end through
ContextInjectionFactory.make)

> this works, but i do not know if this is acceptable.

You really don't need any @Createable annotation.

> with your hint to put strings into the persistedState, how can i access
> it in the Part processor (the part processor is only a pojo it does not
> know about the persistedstate method)


You can get access in your part to the model by simply letting container
inject it.

class MyPart {

@Inject
MPart part;

@PostConstruct
void init(Composite parent) {
part.getPersistedState().get("myspecialdata");
}
}

>
> FYI i'd recreate the views/perspectives on each launch, that would not
> be a problem.

The framework don't know about that and needs to be able to handle any
situation.

Tom
Re: How to create an View with parameters [message #1443470 is a reply to message #1443447] Sun, 12 October 2014 20:10 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
note: the @Createable was on my Class which got injected to hold the parameters i needed to pass, so no createable annotation on the part itself!
thanks for this hint, i did not know i can inject the mpart (parent/itself)

just tested and works like charm.
thanks a lot!

Ludwig
Previous Topic:Creating a Perspective with a Processor
Next Topic:How to consume/reference context functions
Goto Forum:
  


Current Time: Fri Apr 19 15:41:04 GMT 2024

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

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

Back to the top