Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF.edit: Filtering list objects in the tree
EMF.edit: Filtering list objects in the tree [message #427259] Mon, 09 February 2009 10:53 Go to next message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
I am using list objects in my model, for example:

Model --> mylist: MyList (multiplicity 1) --> children : Child
(multiplicity *)

.... i.e., from the model you can access the children through
model.getMylist().getChildren()

In my model editor I don't want to display the list object (MyList) in
the tree, but rather the children objects (Child) directly under the Model.

I have tried to override the ModelItemProvider::getChildren() so that it
delegates and returns the MyListItemProvider::getChildren() result:

public Collection<?> getChildren(Object object) {
Model model = (Model)object;
MyList mylist = model.getMylist();
ITreeItemContentProvider treeItemContentProvider =
(ITreeItemContentProvider) adapterFactory.adapt(mylist,
ITreeItemContentProvider.class);
return treeItemContentProvider.getChildren(mylist);
}

I also changed the ChildItemProvider::getParent() so that it returns the
Model as parent (walking the hierarchy two levels up instead of one).
It seems to work ok, but the DeleteCommand is disabled for the children
objects, so I am guessing I have missed something.
If I remove the getParent() specialization in ChildItemProvider, the
DeleteCommand is enabled but when run does not remove the child.

What am I missing? Maybe there is a better way to do this...

---
Anders
Re: EMF.edit: Filtering list objects in the tree [message #427261 is a reply to message #427259] Mon, 09 February 2009 11:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Anders,

Comments below.


Anders Forsell wrote:
> I am using list objects in my model, for example:
>
> Model --> mylist: MyList (multiplicity 1) --> children : Child
> (multiplicity *)
>
> ... i.e., from the model you can access the children through
> model.getMylist().getChildren()
>
> In my model editor I don't want to display the list object (MyList) in
> the tree, but rather the children objects (Child) directly under the
> Model.
>
> I have tried to override the ModelItemProvider::getChildren() so that
> it delegates and returns the MyListItemProvider::getChildren() result:
>
> public Collection<?> getChildren(Object object) {
> Model model = (Model)object;
> MyList mylist = model.getMylist();
> ITreeItemContentProvider treeItemContentProvider =
> (ITreeItemContentProvider) adapterFactory.adapt(mylist,
> ITreeItemContentProvider.class);
> return treeItemContentProvider.getChildren(mylist);
> }
>
> I also changed the ChildItemProvider::getParent() so that it returns
> the Model as parent (walking the hierarchy two levels up instead of one).
> It seems to work ok, but the DeleteCommand is disabled for the
> children objects, so I am guessing I have missed something.
This is similar to19.2.1 from the EMF book. Things like
factorRemoveCommand need to be specialized so that a remove of the child
of the Model becomes a remove from the MyList.
> If I remove the getParent() specialization in ChildItemProvider, the
> DeleteCommand is enabled but when run does not remove the child.
Probably it's removed, but the Model gets no notification.
>
> What am I missing? Maybe there is a better way to do this...
>
> ---
> Anders
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF.edit: Filtering list objects in the tree [message #427290 is a reply to message #427261] Wed, 11 February 2009 09:20 Go to previous messageGo to next message
Anders Forsell is currently offline Anders ForsellFriend
Messages: 127
Registered: July 2009
Senior Member
You were correct that the delete command did everything correct when
getParent() is not overridden. If I change the list notification to do a
fireNotifyChanged with a ViewerNotification to the list.eContainer() the
tree is updated correctly.

According to the EMF book the getParent() should return the container of
the object, and the list is still the container even though it is not
visible in the tree. Am I right that I don't have to specialize
ChildItemProvider::getParent(), or is there some other scenario that
will be broken?

---
Anders

Ed Merks wrote:
> Anders,
>
> Comments below.
>
>
> Anders Forsell wrote:
>> I am using list objects in my model, for example:
>>
>> Model --> mylist: MyList (multiplicity 1) --> children : Child
>> (multiplicity *)
>>
>> ... i.e., from the model you can access the children through
>> model.getMylist().getChildren()
>>
>> In my model editor I don't want to display the list object (MyList) in
>> the tree, but rather the children objects (Child) directly under the
>> Model.
>>
>> I have tried to override the ModelItemProvider::getChildren() so that
>> it delegates and returns the MyListItemProvider::getChildren() result:
>>
>> public Collection<?> getChildren(Object object) {
>> Model model = (Model)object;
>> MyList mylist = model.getMylist();
>> ITreeItemContentProvider treeItemContentProvider =
>> (ITreeItemContentProvider) adapterFactory.adapt(mylist,
>> ITreeItemContentProvider.class);
>> return treeItemContentProvider.getChildren(mylist);
>> }
>>
>> I also changed the ChildItemProvider::getParent() so that it returns
>> the Model as parent (walking the hierarchy two levels up instead of one).
>> It seems to work ok, but the DeleteCommand is disabled for the
>> children objects, so I am guessing I have missed something.
> This is similar to19.2.1 from the EMF book. Things like
> factorRemoveCommand need to be specialized so that a remove of the child
> of the Model becomes a remove from the MyList.
>> If I remove the getParent() specialization in ChildItemProvider, the
>> DeleteCommand is enabled but when run does not remove the child.
> Probably it's removed, but the Model gets no notification.
>>
>> What am I missing? Maybe there is a better way to do this...
>>
>> ---
>> Anders
>>
Re: EMF.edit: Filtering list objects in the tree [message #427293 is a reply to message #427290] Wed, 11 February 2009 12:47 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Anders,

Comments below.

Anders Forsell wrote:
> You were correct that the delete command did everything correct when
> getParent() is not overridden.
Yes because that way it delegates all the commands to the actual
container object.
> If I change the list notification to do a fireNotifyChanged with a
> ViewerNotification to the list.eContainer() the tree is updated
> correctly.
Yes because that way the container in the view will get a notification
up update.
>
> According to the EMF book the getParent() should return the container
> of the object,
Yes.
> and the list is still the container even though it is not visible in
> the tree.
In the model sense that's true, but in the view it's not; the item
providers should reflect what's in the view.
> Am I right that I don't have to specialize
> ChildItemProvider::getParent(), or is there some other scenario that
> will be broken?
Yes, you'll find that if you try to select the child before the tree has
been expanded that it won't be able to find it. I.e., the only time
getParent is used is when you need to find an object in the tree. In
that case, parent it called until you get to the root object of the
view, and then the JFace mechanisms know to expand that branch of the
tree. So it's best to override getParent, and to delegate command
creation much like you did the getChildren method...
>
> ---
> Anders
>
> Ed Merks wrote:
>> Anders,
>>
>> Comments below.
>>
>>
>> Anders Forsell wrote:
>>> I am using list objects in my model, for example:
>>>
>>> Model --> mylist: MyList (multiplicity 1) --> children : Child
>>> (multiplicity *)
>>>
>>> ... i.e., from the model you can access the children through
>>> model.getMylist().getChildren()
>>>
>>> In my model editor I don't want to display the list object (MyList)
>>> in the tree, but rather the children objects (Child) directly under
>>> the Model.
>>>
>>> I have tried to override the ModelItemProvider::getChildren() so
>>> that it delegates and returns the MyListItemProvider::getChildren()
>>> result:
>>>
>>> public Collection<?> getChildren(Object object) {
>>> Model model = (Model)object;
>>> MyList mylist = model.getMylist();
>>> ITreeItemContentProvider treeItemContentProvider =
>>> (ITreeItemContentProvider) adapterFactory.adapt(mylist,
>>> ITreeItemContentProvider.class);
>>> return treeItemContentProvider.getChildren(mylist);
>>> }
>>>
>>> I also changed the ChildItemProvider::getParent() so that it returns
>>> the Model as parent (walking the hierarchy two levels up instead of
>>> one).
>>> It seems to work ok, but the DeleteCommand is disabled for the
>>> children objects, so I am guessing I have missed something.
>> This is similar to19.2.1 from the EMF book. Things like
>> factorRemoveCommand need to be specialized so that a remove of the
>> child of the Model becomes a remove from the MyList.
>>> If I remove the getParent() specialization in ChildItemProvider, the
>>> DeleteCommand is enabled but when run does not remove the child.
>> Probably it's removed, but the Model gets no notification.
>>>
>>> What am I missing? Maybe there is a better way to do this...
>>>
>>> ---
>>> Anders
>>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Teneo Parent/Child fetching
Next Topic:XSD to Ecore <xsd:choise> management
Goto Forum:
  


Current Time: Fri Mar 29 04:53:13 GMT 2024

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

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

Back to the top