Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » overload add operation in EMF generated editor
overload add operation in EMF generated editor [message #485994] Tue, 15 September 2009 20:33 Go to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Hello

I'm in need of overloading add operation in my generated EMF editor. I
have pretty standard code generated from an ECore model. Without
modifications.

Generaly. I'd like to do some things upon the addition on objects to my
model. I traced the whole "add" process to AddCommand class and am
wondering if it is ok, to overload it. And if yes, how should I do it
correctly.

The same thinkg I'd like to do with other commands, like Delete, or Copy.
So I'm especially looking for more generic solutions.

Thanks in advance for any answers.

Marcin
Re: overload add operation in EMF generated editor [message #486002 is a reply to message #485994] Tue, 15 September 2009 20:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Marcin,

Comments.

Marcin Cylke wrote:
> Hello
>
> I'm in need of overloading add operation in my generated EMF editor. I
> have pretty standard code generated from an ECore model. Without
> modifications.
>
> Generaly. I'd like to do some things upon the addition on objects to
> my model. I traced the whole "add" process to AddCommand class and am
> wondering if it is ok, to overload it. And if yes, how should I do it
> correctly.
Yes. Just create a compound command that does the add and the other
stuff too.
>
> The same thinkg I'd like to do with other commands, like Delete, or
> Copy. So I'm especially looking for more generic solutions.
Item providers act like a factory for commands so specializing those
commands to do additional things is fine.
>
> Thanks in advance for any answers.
>
> Marcin
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: overload add operation in EMF generated editor [message #486865 is a reply to message #486002] Sun, 20 September 2009 10:52 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Hello
I'm having quite a problem with this thing.

I've added an ovveride of createAddCommand to my ObjectItemProvider. It executes, I can place a breakepoint in it, but with each addition to a model it executes n-times, where n is the current size of collection I'm adding it to. I don't understand this behavior.

I'd like to interact with the object that I'm currently adding, not with all the others. What am I doing wrong?

I also tried creating a command extension, but don't know how to use it in a generated emf editor to interact with generated model.

Help appreciated.

Marcin
Re: overload add operation in EMF generated editor [message #486872 is a reply to message #486865] Sun, 20 September 2009 14:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Hello
> I'm having quite a problem with this thing.
>
> I've added an ovveride of createAddCommand to my ObjectItemProvider.
> It executes, I can place a breakepoint in it, but with each addition
> to a model it executes n-times, where n is the current size of
> collection I'm adding it to. I don't understand this behavior.
You mean createAddCommand itself or the command that's created?
>
> I'd like to interact with the object that I'm currently adding, not
> with all the others. What am I doing wrong?
I'm not even sure what you're describing. Surely the debugger will
answer this faster than I can. Look closely at all the arguments to the
call, or all the fields of the command being executed to understand what
they're doing...
>
> I also tried creating a command extension, but don't know how to use
> it in a generated emf editor to interact with generated model.
I'm not sure what this means.
>
> Help appreciated.
>
> Marcin


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: overload add operation in EMF generated editor [message #486894 is a reply to message #486872] Sun, 20 September 2009 19:10 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Hi

Well, I've managed to fix my problems with that. I misinterpreted You first reply, did some errors by myself. But eventually more debugging of the EMF behavior helped.

However I have some other problem. I have a generated model. I have a collection of objectA in it. Now, I have to put an instance of PXModel into my EMF model, so that I can govern its objects from other places.

I'd like to have collection from innerModel synchronized with types from Model. That is why I'd like to return that collection when types == null. Like this:

public EList<ObjectA> getTypes() {
		if (types == null) {
			types = innerModel.getCollection();
		}
		return types;
	}


But doing this way my model isn't updated - lacks behavior of EObjectContainmentEList. Is there a way of "casting" EList to EObjectContainmentEList. Or maybe there is some other solution?

I've tried to use eInverseAdd - but that doesn't work for me.

Well, it may look ugly, but seems like the fastest solution to my problem.

Here is the concept of the situation:

class Model {

   private PXModel innerModel;

   protected EList<ObjectA> types;

   [...]

   public EList<ObjectA> getTypes() {
		if (types == null) {
			types = new EObjectContainmentEList<ObjectA>(ObjectA.class, this,
					ModelPackage.PX_MODEL__TYPES);
		}
		return types;
	}
}

and 

class PXModel {

   protected EList<ObjectA> collection;

   public EList<ObjectA> getCollection() {
      return collection;
   }
}

Re: overload add operation in EMF generated editor [message #486975 is a reply to message #486894] Mon, 21 September 2009 11:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Hi
>
> Well, I've managed to fix my problems with that. I misinterpreted You
> first reply, did some errors by myself. But eventually more debugging
> of the EMF behavior helped.
>
> However I have some other problem. I have a generated model. I have a
> collection of objectA in it. Now, I have to put an instance of PXModel
> into my EMF model, so that I can govern its objects from other places.
I'm not sure I follow what you're saying...
> I'd like to have collection from innerModel synchronized with types
> from Model. That is why I'd like to return that collection when types
> == null. Like this:
>
>
> public EList<ObjectA> getTypes() {
> if (types == null) {
> types = innerModel.getCollection();
> }
> return types;
> }
>
>
> But doing this way my model isn't updated - lacks behavior of
> EObjectContainmentEList.
Is this list supposed to be a read only view or can it be modified.
> Is there a way of "casting" EList to EObjectContainmentEList. Or maybe
> there is some other solution?
It sounds more like you should attach an adapter to the inner model and
as the feature changes, make corresponding changes here.
> I've tried to use eInverseAdd - but that doesn't work for me.
>
> Well, it may look ugly, but seems like the fastest solution to my
> problem.
>
> Here is the concept of the situation:
>
> class Model {
>
> private PXModel innerModel;
>
> protected EList<ObjectA> types;
>
> [...]
>
> public EList<ObjectA> getTypes() {
> if (types == null) {
> types = new
> EObjectContainmentEList<ObjectA>(ObjectA.class, this,
> ModelPackage.PX_MODEL__TYPES);
> }
> return types;
> }
> }
>
> and
> class PXModel {
>
> protected EList<ObjectA> collection;
>
> public EList<ObjectA> getCollection() {
> return collection;
> }
> }
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: overload add operation in EMF generated editor [message #487339 is a reply to message #486975] Tue, 22 September 2009 19:32 Go to previous messageGo to next message
Marcin Cylke is currently offline Marcin CylkeFriend
Messages: 61
Registered: July 2009
Member
Ed Merks wrote on Mon, 21 September 2009 07:16
Marcin,

> But doing this way my model isn't updated - lacks behavior of
> EObjectContainmentEList.
Is this list supposed to be a read only view or can it be modified.
> Is there a way of "casting" EList to EObjectContainmentEList. Or maybe
> there is some other solution?
It sounds more like you should attach an adapter to the inner model and
as the feature changes, make corresponding changes here.
>


This is supposed to be a modifiable list.

Well, incorporating changes to the embeded object through adapter - or anything else, as you've described, would surely suffice. But how can I notice when the change on the collection occures? Since there is only a getter for it I don't know how should I find out about its contents change.

Marcin
Re: overload add operation in EMF generated editor [message #487453 is a reply to message #487339] Wed, 23 September 2009 10:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Marcin,

Comments below.

Marcin Cylke wrote:
> Ed Merks wrote on Mon, 21 September 2009 07:16
>> Marcin,
>>
>> > But doing this way my model isn't updated - lacks behavior of >
>> EObjectContainmentEList. Is this list supposed to be a read only view
>> or can it be modified.
>> > Is there a way of "casting" EList to EObjectContainmentEList. Or
>> maybe > there is some other solution?
>> It sounds more like you should attach an adapter to the inner model
>> and as the feature changes, make corresponding changes here.
>> >
>
>
> This is supposed to be a modifiable list.
So the adapting/shadowing of changes needs to be in both directions?
>
> Well, incorporating changes to the embeded object through adapter - or
> anything else, as you've described, would surely suffice. But how can
> I notice when the change on the collection occures? Since there is
> only a getter for it I don't know how should I find out about its
> contents change.
All features notify of changes, not just single valued features. In the
case of multi-valued features, any change to the list produces
notifications, e.g., ADD, REMOVE, and SET.
>
> Marcin


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:XSD to XMI?
Next Topic:"Link" attribute in a model
Goto Forum:
  


Current Time: Thu Sep 26 10:18:37 GMT 2024

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

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

Back to the top