|
Re: EMF.edit: Filtering list objects in the tree [message #427261 is a reply to message #427259] |
Mon, 09 February 2009 11:17 |
Ed Merks Messages: 33142 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 |
Anders Forsell 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 |
Ed Merks Messages: 33142 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/
|
|
|
Powered by
FUDForum. Page generated in 0.03297 seconds