Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How open EMF generated editor when model is not in a file?
How open EMF generated editor when model is not in a file? [message #987844] Wed, 28 November 2012 11:16 Go to next message
Fredrik Attebrant is currently offline Fredrik AttebrantFriend
Messages: 34
Registered: June 2012
Member

Hi,

We're working with a editor for a configuration of a running system. For this we have an Ecore model and are basing the editor on the generated editor project. The model is populated by reading information from an executing system.

How can we open the editor, since we don't have any file representation of the model?

At least at a first glance, the EMF generated editor seems to require a resource which have a file representation.

Appreciate any pointers on how to replace the file depencency, to be able to work purely in memory.

Thanks,
--Fredrik
Re: How open EMF generated editor when model is not in a file? [message #987847 is a reply to message #987844] Wed, 28 November 2012 11:34 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
The generated editor expects an IEditorInput which could be a URIEditorInput.
From this, you can generated your model, if the URI is a file or something else. In your case, the "executing system" should deliver a model which can de-serialize
into a Resource the editor can handle. For remote Systems, there are CDOResource, HibernateResource etc... If your system doesn't use any of these technologies,
you would need a ResourceFactory to produce the resource.

An alternative, is to skip resources and feed your editor with EObjects which could be results of a query of some sort.
The JFace viewers used by the editor, can be fed with an EObject and show the containment. (So not necessarly a Resource).

Hope this helps.
Christophe



Re: How open EMF generated editor when model is not in a file? [message #987858 is a reply to message #987844] Wed, 28 November 2012 12:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Fredrik,

Comments below.

On 28/11/2012 12:16 PM, Fredrik Attebrant wrote:
> Hi,
>
> We're working with a editor for a configuration of a running system.
> For this we have an Ecore model and are basing the editor on the
> generated editor project. The model is populated by reading
> information from an executing system.
>
> How can we open the editor, since we don't have any file
> representation of the model?
You don't necessarily need one...
>
> At least at a first glance, the EMF generated editor seems to require
> a resource which have a file representation.
It does require a resource in its resource set.
>
> Appreciate any pointers on how to replace the file depencency, to be
> able to work purely in memory.
One approach to take is use a specialized URI syntax. For example,
foo:/ and define a specialized URIHandlerImpl that overrides canHandle
to recognize the "foo" scheme as its own. You'd specialize the
generated editor to add that to the
resourceSet.getURIConverter().getURIHandlers().add(0, new
FooURIHandlerImpl()). You'd also specialize the URI handler's
createInputStream to create a derived InputStream that overrides read to
return -1 (the stream is always empty); that derived input stream should
also implement URIConverter.Loadable so you'd specialize its
loadResource method to create the EObjects and place them in the
resource's contents (keeping in mind that they should be a copy because
they will be moved to be contained by that resource). You'll probably
need to fuss with some additional things, like the getAttributes so that
the resource is considered read only.

That should allow you to open your editor and display the objects you
want to view...

>
> Thanks,
> --Fredrik
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How open EMF generated editor when model is not in a file? [message #1003743 is a reply to message #987858] Mon, 21 January 2013 23:01 Go to previous messageGo to next message
freiric Barral is currently offline freiric BarralFriend
Messages: 2
Registered: September 2010
Junior Member
Hi,

I am also interested in this question. I found a quick and surely dirty solution, and I would like to know what may be wrong with it (as I do not have much experience with EMF). At least it provides a quick way to see if your in-memory model can be displayed in the editor.

1. Comment out the createModel() call in createPages() in the generated editor:
public void createPages() {
	// Creates the model from the editor input
	//
	// createModel();
...
}
...


2. Add your resourceSet as argument to the AdapterFactoryEditingDomain constructor:
protected void initializeEditingDomain() {
  ...
	// Create the editing domain with a special command stack.
	//
        //   editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
        //		commandStack, new HashMap<Resource, Boolean>());
	editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
			commandStack, yourResourceSetHere);
}


I have constructed the ResourceSet from my model by using a ResourceSetImpl, and constructing Resource with resourceSet.createResource("someRandomUri").
I guess you do not need to use a specialised Uri handler in this case because the ResourceSet is already loaded.

What would be the drawbacks of this approach?
Re: How open EMF generated editor when model is not in a file? [message #1004057 is a reply to message #1003743] Tue, 22 January 2013 14:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 22/01/2013 2:35 PM, fre Mising name wrote:
> Hi,
>
> I am also interested in this question. I found a quick and surely
> dirty solution, and I would like to know what may be wrong with it (as
> I do not have much experience with EMF). At least it provides a quick
> way to see if your in-memory model can be displayed in the editor.
>
> 1. Comment out the createModel() call in createPages() in the
> generated editor:
>
> public void createPages() {
> // Creates the model from the editor input
> //
> // createModel();
> ..
> }
Or empty out the createModel method itself...
> ..
>
>
> 2. Add your resourceSet as argument to the AdapterFactoryEditingDomain
> constructor:
>
> protected void initializeEditingDomain() {
> ...
> // Create the editing domain with a special command stack.
> //
> // editingDomain = new
> AdapterFactoryEditingDomain(adapterFactory,
> // commandStack, new HashMap<Resource, Boolean>());
> editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> commandStack, yourResourceSetHere);
> }
>
>
> I have constructed the ResourceSet from my model by using a
> ResourceSetImpl, and constructing Resource with
> resourceSet.createResource("someRandomUri").
Why not use the editing domain's resource set? I.e., why do you need to
create a different one? The problem here is that
org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(EObject),
which is used to determine the editing domain from the resource set,
won't be able to find it unless you add the appropriate adapter to your
resource set...

Why not populate the resource set in the createModel method?
> I guess you do not need to use a specialised Uri handler in this case
> because the ResourceSet is already loaded.
>
> What would be the drawbacks of this approach?
What editor input do you use to open the editor?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How open EMF generated editor when model is not in a file? [message #1004449 is a reply to message #1004057] Wed, 23 January 2013 09:06 Go to previous messageGo to next message
freiric Barral is currently offline freiric BarralFriend
Messages: 2
Registered: September 2010
Junior Member
Comments below.

> > Hi,
> >
> > I am also interested in this question. I found a quick and surely
> > dirty solution, and I would like to know what may be wrong with it (as
> > I do not have much experience with EMF). At least it provides a quick
> > way to see if your in-memory model can be displayed in the editor.
> >
> > 1. Comment out the createModel() call in createPages() in the
> > generated editor:
> >
> > public void createPages() {
> > // Creates the model from the editor input
> > //
> > // createModel();
> > ..
> > }
> Or empty out the createModel method itself...
> > ..
> >
> >
> > 2. Add your resourceSet as argument to the AdapterFactoryEditingDomain
> > constructor:
> >
> > protected void initializeEditingDomain() {
> > ...
> > // Create the editing domain with a special command stack.
> > //
> > // editingDomain = new
> > AdapterFactoryEditingDomain(adapterFactory,
> > // commandStack, new HashMap<Resource, Boolean>());
> > editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
> > commandStack, yourResourceSetHere);
> > }
> >
> >
> > I have constructed the ResourceSet from my model by using a
> > ResourceSetImpl, and constructing Resource with
> > resourceSet.createResource("someRandomUri").
> Why not use the editing domain's resource set? I.e., why do you need to
> create a different one? The problem here is that
> org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(EObject),
> which is used to determine the editing domain from the resource set,
> won't be able to find it unless you add the appropriate adapter to your
> resource set...
>
> Why not populate the resource set in the createModel method?
Thanks. I initially provided a ResourceSet because I have two editor working on the same resource (showing different subtree of the selection in the ContentOutline), so it seemed natural to provide a ResourceSet from the outside. I now use the one from the EditingDomain, and check that the resource have not already been created in the second editor.

> > I guess you do not need to use a specialised Uri handler in this case
> > because the ResourceSet is already loaded.
> >
> > What would be the drawbacks of this approach?
> What editor input do you use to open the editor?

I haven't work on this yet, for the moment I just use the one in the generated editor (URIEditorInput(uri) in the EditorAdvisor))... I first wanted to know if there was something fundamentally wrong with my approach before going further. I guess I'll have to implement an editor input representing my in-memory object. Do you mean I would be better off using the URIEditorInput with a custom scheme?
Re: How open EMF generated editor when model is not in a file? [message #1004468 is a reply to message #1004449] Wed, 23 January 2013 09:56 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Comments below.

On 23/01/2013 10:06 AM, fre Mising name wrote:
> Comments below.
>
>> > Hi,
>> >
>> > I am also interested in this question. I found a quick and surely
>> > dirty solution, and I would like to know what may be wrong with it (as
>> > I do not have much experience with EMF). At least it provides a quick
>> > way to see if your in-memory model can be displayed in the editor.
>> >
>> > 1. Comment out the createModel() call in createPages() in the
>> > generated editor:
>> >
>> > public void createPages() {
>> > // Creates the model from the editor input
>> > //
>> > // createModel();
>> > ..
>> > }
>> Or empty out the createModel method itself...
>> > ..
>> >
>> >
>> > 2. Add your resourceSet as argument to the AdapterFactoryEditingDomain
>> > constructor:
>> >
>> > protected void initializeEditingDomain() {
>> > ...
>> > // Create the editing domain with a special command stack.
>> > //
>> > // editingDomain = new
>> > AdapterFactoryEditingDomain(adapterFactory,
>> > // commandStack, new HashMap<Resource, Boolean>());
>> > editingDomain = new AdapterFactoryEditingDomain(adapterFactory,
>> > commandStack, yourResourceSetHere);
>> > }
>> >
>> >
>> > I have constructed the ResourceSet from my model by using a
>> > ResourceSetImpl, and constructing Resource with
>> > resourceSet.createResource("someRandomUri").
>> Why not use the editing domain's resource set? I.e., why do you need to
>> create a different one? The problem here is that
>> org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.getEditingDomainFor(EObject),
>>
>> which is used to determine the editing domain from the resource set,
>> won't be able to find it unless you add the appropriate adapter to your
>> resource set...
>>
>> Why not populate the resource set in the createModel method?
> Thanks. I initially provided a ResourceSet because I have two editor
> working on the same resource (showing different subtree of the
> selection in the ContentOutline), so it seemed natural to provide a
> ResourceSet from the outside. I now use the one from the
> EditingDomain, and check that the resource have not already been
> created in the second editor.
It sounds like they should share the editing domain itself. Otherwise
they're likely to have problems with the two separate command stacks...
>
>> > I guess you do not need to use a specialised Uri handler in this case
>> > because the ResourceSet is already loaded.
>> >
>> > What would be the drawbacks of this approach?
>> What editor input do you use to open the editor?
>
> I haven't work on this yet, for the moment I just use the one in the
> generated editor (URIEditorInput(uri) in the EditorAdvisor))... I
> first wanted to know if there was something fundamentally wrong with
> my approach before going further.
It's generally the way to pass in the information you want the editor to
use...
> I guess I'll have to implement an editor input representing my
> in-memory object.
Yes, I think it should pass in the shared editing domain and the object
you want it to focus on. One problem I can foresee is how closing and
reopening the workbench will preserve this open editor...
> Do you mean I would be better off using the URIEditorInput with a
> custom scheme?
Not necessarily no. If the two editor are going to share the same
in-memory objects they really must share the editing domain (along with
its command stack and resource set)...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[xcore/xbase] Referencing operation parameters from inside lambda expressions
Next Topic:EMF Compare bugzilla change
Goto Forum:
  


Current Time: Thu Mar 28 15:43:57 GMT 2024

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

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

Back to the top