Best practices: Where should I maintain my model status? [message #884838] |
Mon, 11 June 2012 19:25  |
Eclipse User |
|
|
|
I want to write a pure e4 application to edit and display in various
ways a single EMF model.
Only one model can be open at any given time in my app.
On the other hand I can have several ways to look at it and thus I have
a certain number (currently 4) of different perspectives.
My problem is to understand where I should make the link between the e4
"MPart"s and my EMF model.
I started writing a single perspective: a Master/details Overview of the
model.
I load my model in the OpenHandler and call a specific "setModel(Model
model)" API in my Master MPart.
This way Master MPart becomes the "owner of the Model and is responsible
to provide it to all the various "details" MParts.
Master MPart implements the MDirtyable interface.
I strongly doubt this is the "Right Way" to handle my needs.
Even forgetting I'm not decoupling the various MParts and that I do not
(currently) use DI to provide the model around, I now discovered that I
cannot get access to my Master MPart (and thus to the model!) form
MParts that are in "other" Perspectives.
I *think* I should add my model somehow to the IEclipseContext and rely
on the framework itself to re-inject it whenever it changes (i.e.: when
I close one model and open another one).
If I understand it correctly I can add my model to the context via:
@Execute
public void execute(IEclipseContext context,
@Optional Model model,
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell)
throws InvocationTargetException, InterruptedException {
if (model != null) {
// save and discard old model
}
FileDialog dialog = new FileDialog(shell);
String selected = dialog.open();
if (selected != null) {
model = new Model(selected);
context.set(Model.class, model);
}
}
Is this correct?
I would then need some @Inject-able method in my MParts that will be
called when the Model chenges (i.e.: when I call
"context.set(Model.class, model)").
I couldn't find out what kind of Annotation I should use to get this
behavior.
Using something like:
@Inject
public void setModel(@Optional Model model) {
...
}
is *almost* working, but sometimes I get "null" values for the model and
I don't understand exactly why.
Am I completely off-track?
Please comment.
TiA
Mauro
|
|
|
|
|
|
|
|
|
|
Re: Best practices: Where should I maintain my model status? [message #885364 is a reply to message #885350] |
Tue, 12 June 2012 17:55   |
Eclipse User |
|
|
|
On 12/06/2012 23:17, Sopot Cela wrote:
> Mauro,
>
> you are trying to do some really weird things.
I know ;)
Truth is I am unable to find instructions on how to do several things
and thus I resort to experimenting.
Sometimes the experiments get a little wild ;)
> First and foremost the MPart and MPerspective cannot be cast to each
> other. They are completely different interfaces. The method findPart
> will find a MPart for you and not a MPerspective and thus the p==null. I
> guess you can use the EModelService's find to find perspectives. p
> instanceof MPerspective will NEVER be true (will throw a CCE if you
> force the cast). Tell eclipse to do a type hierarchy on each of those
> (CTRL+T) and you will get the idea.
I am still more than a little confused abiut exactly which service I
should use to get the right "piece" (Mpart, MPerspective or whatever).
I hoped there's a unified interface using the id's, but that doesn't
seem true.
> Also DON'T use internals like PerspectiveStackImpl. Stick to interfaces.
My bad.
I debugged and found out that's the actual type returned.
I should have used the Interface, instead.
> The menu items are kept in sync with their command. If you create your
> command on the fly with the command and handler service you should take
> care to also link the menu items with the newly created commands in
> order to keep things synced.
Ok.
What is the magic spell to get the Command already linked with the menu,
instead of creating a new one?
Use EModelService, I presume, but how do I add the parameter?
Can You suggest some specific documentation?
I am mainly using Lars's excellent site, but even that is rather terse
on many subjects.
Wiki seems to be lagging way behind, or I'm unable to navigate it properly.
Thanks for Your time
Mauro
|
|
|
|
Powered by
FUDForum. Page generated in 0.08925 seconds