Skip to main content



      Home
Home » Modeling » EMF » Saving a program-generated model
Saving a program-generated model [message #389433] Tue, 23 November 2004 18:05 Go to next message
Eclipse UserFriend
Originally posted by: gkarcher.sjm.com

Hello,

I'm a relative newbie to Eclipse and EMF, but I have started by jumping
into EMF with at least two feet.

I have constructed an Ecore model and created the model, edit, and editor
projects successfully, including creating XMI files with model instance
data. Now, I am attempting to create an Eclipse plugin that will allow
construction of model instance data from an input XML file. At present,
the plugin recognizes the base model object and provides a menu item from
which I start the model construction. I am successfully parsing the XML
data and creating the model objects. In fact, they are shown in the
editor view of the model.

Now for the problem... After creating the objects, I can't save them.
What needs to be done to force the "dirty bit" to be set so that the
editor recognizes that the resource has changes and thus enables the save
command?

Here is a short (abstract) excerpt from my code:

public void transform(MyBaseObject baseObject)
{
// modify an attribute
baseObject.setDescription("my comment");
// create a referenced object
ChildObject child =
MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
child.setName("joe");
// add the chile to the base object
baseObject.getMyChildren().add(child);
// the following doesn't seem to set the editor's changed status
baseObject.eResource().setModified(true);
}

Any help that can be offered will be greatly appreciated.
Thanks in advance,
--Glenn
Re: Saving a program-generated model [message #389436 is a reply to message #389433] Tue, 23 November 2004 18:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi Glenn,

If you look at the way the editor works, you will see an object there
called the "EditingDomain". Rather than playing with the domain model
directly, if you use the editing domain to create and execute the proper
commands for model modification, you should be in business. These commands
go onto a command stack managed by the editing domain, and it is the
presence of items on the stack that triggers the dirty flag. Furthermore,
using the command-based approach will give you undo-redo type capabilities
out of the box.

I hope this helps,
amin


Glenn Karcher wrote:

> Hello,

> I'm a relative newbie to Eclipse and EMF, but I have started by jumping
> into EMF with at least two feet.

> I have constructed an Ecore model and created the model, edit, and editor
> projects successfully, including creating XMI files with model instance
> data. Now, I am attempting to create an Eclipse plugin that will allow
> construction of model instance data from an input XML file. At present,
> the plugin recognizes the base model object and provides a menu item from
> which I start the model construction. I am successfully parsing the XML
> data and creating the model objects. In fact, they are shown in the
> editor view of the model.

> Now for the problem... After creating the objects, I can't save them.
> What needs to be done to force the "dirty bit" to be set so that the
> editor recognizes that the resource has changes and thus enables the save
> command?

> Here is a short (abstract) excerpt from my code:

> public void transform(MyBaseObject baseObject)
> {
> // modify an attribute
> baseObject.setDescription("my comment");
> // create a referenced object
> ChildObject child =
> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
> child.setName("joe");
> // add the chile to the base object
> baseObject.getMyChildren().add(child);
> // the following doesn't seem to set the editor's changed status
> baseObject.eResource().setModified(true);
> }

> Any help that can be offered will be greatly appreciated.
> Thanks in advance,
> --Glenn
Re: Saving a program-generated model [message #389458 is a reply to message #389433] Wed, 24 November 2004 07:11 Go to previous messageGo to next message
Eclipse UserFriend
Glenn,

As Amin explained, you should execute commands to modify your objects.
The editor detects dirtiness using the command stack, so bypassing that
will cause you problems beyond just breaking undo. Even if you don't
care about undo, at a minimum, you need to create a command that isn't
undoable and then perform all you changes within that command's execute...


Glenn Karcher wrote:

> Hello,
>
> I'm a relative newbie to Eclipse and EMF, but I have started by
> jumping into EMF with at least two feet.
>
> I have constructed an Ecore model and created the model, edit, and
> editor projects successfully, including creating XMI files with model
> instance data. Now, I am attempting to create an Eclipse plugin that
> will allow construction of model instance data from an input XML
> file. At present, the plugin recognizes the base model object and
> provides a menu item from which I start the model construction. I am
> successfully parsing the XML data and creating the model objects. In
> fact, they are shown in the editor view of the model.
>
> Now for the problem... After creating the objects, I can't save them.
> What needs to be done to force the "dirty bit" to be set so that the
> editor recognizes that the resource has changes and thus enables the
> save command?
>
> Here is a short (abstract) excerpt from my code:
>
> public void transform(MyBaseObject baseObject)
> {
> // modify an attribute
> baseObject.setDescription("my comment");
> // create a referenced object
> ChildObject child =
> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
> child.setName("joe");
> // add the chile to the base object
> baseObject.getMyChildren().add(child);
> // the following doesn't seem to set the editor's changed
> status baseObject.eResource().setModified(true);
> }
>
> Any help that can be offered will be greatly appreciated.
> Thanks in advance,
> --Glenn
>
Re: Saving a program-generated model [message #389567 is a reply to message #389458] Sat, 27 November 2004 16:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gkarcher.sjm.com

Ed and Amin,

Many thanks. After figuring out how to access the editor (i.e., casting
the 'targetPart' in the SetActivePart() method of the action class), I was
able to access the EditingDomain and execute the SetCommand() and
AddCommand as suggested.

Now I have a question on performance of these commands. Since I need to
perform several thousand commands in my import function, what kind of a
performance penalty will have to pay. Since I really won't care about
undo (except for possibly backing out all imported objects as a whole, is
it possible to define a scope for a single undo that covers all of those
objects?

--Glenn

>Ed Merks wrote:

>> Glenn,

>> As Amin explained, you should execute commands to modify your objects.
>> The editor detects dirtiness using the command stack, so bypassing that
>> will cause you problems beyond just breaking undo. Even if you don't
>> care about undo, at a minimum, you need to create a command that isn't
>> undoable and then perform all you changes within that command's execute...


>> Glenn Karcher wrote:

>>> Hello,
>>>
>>> I'm a relative newbie to Eclipse and EMF, but I have started by
>>> jumping into EMF with at least two feet.
>>>
>>> I have constructed an Ecore model and created the model, edit, and
>>> editor projects successfully, including creating XMI files with model
>>> instance data. Now, I am attempting to create an Eclipse plugin that
>>> will allow construction of model instance data from an input XML
>>> file. At present, the plugin recognizes the base model object and
>>> provides a menu item from which I start the model construction. I am
>>> successfully parsing the XML data and creating the model objects. In
>>> fact, they are shown in the editor view of the model.
>>>
>>> Now for the problem... After creating the objects, I can't save them.
>>> What needs to be done to force the "dirty bit" to be set so that the
>>> editor recognizes that the resource has changes and thus enables the
>>> save command?
>>>
>>> Here is a short (abstract) excerpt from my code:
>>>
>>> public void transform(MyBaseObject baseObject)
>>> {
>>> // modify an attribute
>>> baseObject.setDescription("my comment");
>>> // create a referenced object
>>> ChildObject child =
>>> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
>>> child.setName("joe");
>>> // add the chile to the base object
>>> baseObject.getMyChildren().add(child);
>>> // the following doesn't seem to set the editor's changed
>>> status baseObject.eResource().setModified(true);
>>> }
>>>
>>> Any help that can be offered will be greatly appreciated.
>>> Thanks in advance,
>>> --Glenn
>>>
Re: Saving a program-generated model [message #389570 is a reply to message #389567] Sun, 28 November 2004 15:10 Go to previous messageGo to next message
Eclipse UserFriend
Hi Glenn,

My guess is that performance for a multi-thousand item import will *not*
be acceptable so long as the editor is open and has to update itself
visually for every item imported into the model. Is keeping the editor in
sync, blow-by-blow so to speak, a requirement for your project? If not,
I'm thinking that you should perform the import into your existing model
and then instruct the editor to completely refresh itself when the import
completes. In that case, I don't think it would be important to use the
editing commands at all.

amin

Glenn Karcher wrote:

> Ed and Amin,

> Many thanks. After figuring out how to access the editor (i.e., casting
> the 'targetPart' in the SetActivePart() method of the action class), I was
> able to access the EditingDomain and execute the SetCommand() and
> AddCommand as suggested.

> Now I have a question on performance of these commands. Since I need to
> perform several thousand commands in my import function, what kind of a
> performance penalty will have to pay. Since I really won't care about
> undo (except for possibly backing out all imported objects as a whole, is
> it possible to define a scope for a single undo that covers all of those
> objects?

> --Glenn

>>Ed Merks wrote:

>>> Glenn,

>>> As Amin explained, you should execute commands to modify your objects.
>>> The editor detects dirtiness using the command stack, so bypassing that
>>> will cause you problems beyond just breaking undo. Even if you don't
>>> care about undo, at a minimum, you need to create a command that isn't
>>> undoable and then perform all you changes within that command's execute...


>>> Glenn Karcher wrote:

>>>> Hello,
>>>>
>>>> I'm a relative newbie to Eclipse and EMF, but I have started by
>>>> jumping into EMF with at least two feet.
>>>>
>>>> I have constructed an Ecore model and created the model, edit, and
>>>> editor projects successfully, including creating XMI files with model
>>>> instance data. Now, I am attempting to create an Eclipse plugin that
>>>> will allow construction of model instance data from an input XML
>>>> file. At present, the plugin recognizes the base model object and
>>>> provides a menu item from which I start the model construction. I am
>>>> successfully parsing the XML data and creating the model objects. In
>>>> fact, they are shown in the editor view of the model.
>>>>
>>>> Now for the problem... After creating the objects, I can't save them.
>>>> What needs to be done to force the "dirty bit" to be set so that the
>>>> editor recognizes that the resource has changes and thus enables the
>>>> save command?
>>>>
>>>> Here is a short (abstract) excerpt from my code:
>>>>
>>>> public void transform(MyBaseObject baseObject)
>>>> {
>>>> // modify an attribute
>>>> baseObject.setDescription("my comment");
>>>> // create a referenced object
>>>> ChildObject child =
>>>> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
>>>> child.setName("joe");
>>>> // add the chile to the base object
>>>> baseObject.getMyChildren().add(child);
>>>> // the following doesn't seem to set the editor's changed
>>>> status baseObject.eResource().setModified(true);
>>>> }
>>>>
>>>> Any help that can be offered will be greatly appreciated.
>>>> Thanks in advance,
>>>> --Glenn
>>>>
Re: Saving a program-generated model [message #389575 is a reply to message #389567] Mon, 29 November 2004 06:55 Go to previous messageGo to next message
Eclipse UserFriend
Glenn,

I suspect that performance won't be a big issue, but definitely creating
a command to do something that's extremely cheap to do on its own will
be a significant overhead. Whether it's a unacceptable overhead isn't
clear. It's certainly reasonable to do all your work without commands
inside of a command that is not undoable. If you want to do (and undo)
a whole bunch of things "as a unit", you can use a CompoundCommand for that.


Glenn Karcher wrote:

> Ed and Amin,
>
> Many thanks. After figuring out how to access the editor (i.e.,
> casting the 'targetPart' in the SetActivePart() method of the action
> class), I was able to access the EditingDomain and execute the
> SetCommand() and AddCommand as suggested.
>
> Now I have a question on performance of these commands. Since I need
> to perform several thousand commands in my import function, what kind
> of a performance penalty will have to pay. Since I really won't care
> about undo (except for possibly backing out all imported objects as a
> whole, is it possible to define a scope for a single undo that covers
> all of those objects?
> --Glenn
>
>> Ed Merks wrote:
>
>
>>> Glenn,
>>
>
>>> As Amin explained, you should execute commands to modify your
>>> objects. The editor detects dirtiness using the command stack, so
>>> bypassing that will cause you problems beyond just breaking undo.
>>> Even if you don't care about undo, at a minimum, you need to create
>>> a command that isn't undoable and then perform all you changes
>>> within that command's execute...
>>
>
>
>>> Glenn Karcher wrote:
>>
>
>>>> Hello,
>>>>
>>>> I'm a relative newbie to Eclipse and EMF, but I have started by
>>>> jumping into EMF with at least two feet.
>>>>
>>>> I have constructed an Ecore model and created the model, edit, and
>>>> editor projects successfully, including creating XMI files with
>>>> model instance data. Now, I am attempting to create an Eclipse
>>>> plugin that will allow construction of model instance data from an
>>>> input XML file. At present, the plugin recognizes the base model
>>>> object and provides a menu item from which I start the model
>>>> construction. I am successfully parsing the XML data and creating
>>>> the model objects. In fact, they are shown in the editor view of
>>>> the model.
>>>>
>>>> Now for the problem... After creating the objects, I can't save
>>>> them. What needs to be done to force the "dirty bit" to be set so
>>>> that the editor recognizes that the resource has changes and thus
>>>> enables the save command?
>>>>
>>>> Here is a short (abstract) excerpt from my code:
>>>>
>>>> public void transform(MyBaseObject baseObject)
>>>> {
>>>> // modify an attribute
>>>> baseObject.setDescription("my comment");
>>>> // create a referenced object
>>>> ChildObject child =
>>>> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
>>>> child.setName("joe");
>>>> // add the chile to the base object
>>>> baseObject.getMyChildren().add(child);
>>>> // the following doesn't seem to set the editor's changed
>>>> status baseObject.eResource().setModified(true);
>>>> }
>>>>
>>>> Any help that can be offered will be greatly appreciated.
>>>> Thanks in advance,
>>>> --Glenn
>>>>
>
>
Re: Saving a program-generated model [message #389576 is a reply to message #389570] Mon, 29 November 2004 07:02 Go to previous message
Eclipse UserFriend
Amin,

Whether commands are doing the work or not, the UI will still get
notifications for the things that happen, so the issue of updating is
not directly related to the issue of using commands to update the model
verses direct updates to the model. As you point out, when doing
massive updates, it is most efficient to disable incremental
notification and just do a complete refresh. It's possible to override
AdapterFactoryContentProvider.notifyChanged to control refresh behavior,
i.e., you might disable it when a command starts to execute and do a
full refresh after.


Amin Ahmad wrote:

> Hi Glenn,
>
> My guess is that performance for a multi-thousand item import will
> *not* be acceptable so long as the editor is open and has to update
> itself visually for every item imported into the model. Is keeping the
> editor in sync, blow-by-blow so to speak, a requirement for your
> project? If not, I'm thinking that you should perform the import into
> your existing model and then instruct the editor to completely refresh
> itself when the import completes. In that case, I don't think it would
> be important to use the editing commands at all.
>
> amin
>
> Glenn Karcher wrote:
>
>> Ed and Amin,
>
>
>> Many thanks. After figuring out how to access the editor (i.e.,
>> casting the 'targetPart' in the SetActivePart() method of the action
>> class), I was able to access the EditingDomain and execute the
>> SetCommand() and AddCommand as suggested.
>
>
>> Now I have a question on performance of these commands. Since I need
>> to perform several thousand commands in my import function, what kind
>> of a performance penalty will have to pay. Since I really won't care
>> about undo (except for possibly backing out all imported objects as a
>> whole, is it possible to define a scope for a single undo that covers
>> all of those objects?
>
>
>> --Glenn
>
>
>>> Ed Merks wrote:
>>
>
>>>> Glenn,
>>>
>
>>>> As Amin explained, you should execute commands to modify your
>>>> objects. The editor detects dirtiness using the command stack, so
>>>> bypassing that will cause you problems beyond just breaking undo.
>>>> Even if you don't care about undo, at a minimum, you need to create
>>>> a command that isn't undoable and then perform all you changes
>>>> within that command's execute...
>>>
>
>
>>>> Glenn Karcher wrote:
>>>
>
>>>>> Hello,
>>>>>
>>>>> I'm a relative newbie to Eclipse and EMF, but I have started by
>>>>> jumping into EMF with at least two feet.
>>>>>
>>>>> I have constructed an Ecore model and created the model, edit, and
>>>>> editor projects successfully, including creating XMI files with
>>>>> model instance data. Now, I am attempting to create an Eclipse
>>>>> plugin that will allow construction of model instance data from an
>>>>> input XML file. At present, the plugin recognizes the base model
>>>>> object and provides a menu item from which I start the model
>>>>> construction. I am successfully parsing the XML data and creating
>>>>> the model objects. In fact, they are shown in the editor view of
>>>>> the model.
>>>>>
>>>>> Now for the problem... After creating the objects, I can't save
>>>>> them. What needs to be done to force the "dirty bit" to be set so
>>>>> that the editor recognizes that the resource has changes and thus
>>>>> enables the save command?
>>>>>
>>>>> Here is a short (abstract) excerpt from my code:
>>>>>
>>>>> public void transform(MyBaseObject baseObject)
>>>>> {
>>>>> // modify an attribute
>>>>> baseObject.setDescription("my comment");
>>>>> // create a referenced object
>>>>> ChildObject child =
>>>>> MyBaseObjectGroupFactory.eINSTANCE.createChildObject();
>>>>> child.setName("joe");
>>>>> // add the chile to the base object
>>>>> baseObject.getMyChildren().add(child);
>>>>> // the following doesn't seem to set the editor's changed
>>>>> status baseObject.eResource().setModified(true);
>>>>> }
>>>>>
>>>>> Any help that can be offered will be greatly appreciated.
>>>>> Thanks in advance,
>>>>> --Glenn
>>>>>
>
>
Previous Topic:import generation for primitive types
Next Topic:export jar
Goto Forum:
  


Current Time: Mon Sep 15 08:04:43 EDT 2025

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

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

Back to the top