Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Control deletion
Control deletion [message #418730] Fri, 25 April 2008 13:32 Go to next message
Hugues Rérolle is currently offline Hugues RérolleFriend
Messages: 60
Registered: July 2009
Member
Hi all,

I want to prevent deletion of element with children.

I've overridden createRemoveCommand, I be able to detect if the element
would be removed or not. But I don't know how to forbid it ? I tried to
return null but it didn't work.


@Override
protected Command createRemoveCommand(EditingDomain domain, EObject owner,
EStructuralFeature feature, Collection<?> collection) {
Category category = (Category) owner;
if (category.getRefModel().size() > 0) {
System.out.println("deletion forbidden");
return null;
}
return super.createRemoveCommand(domain, owner, feature, collection);
}

Anybody has an idea to solve my problem?

Hugues
Re: Control deletion [message #418731 is a reply to message #418730] Fri, 25 April 2008 13:35 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Hugues,

Try returning UnexecutableCommand.INSTANCE. Note that sequential access
lists, !isEmpty() is more efficient that size() > 0.


Hugues Rérolle wrote:
> Hi all,
>
> I want to prevent deletion of element with children.
>
> I've overridden createRemoveCommand, I be able to detect if the
> element would be removed or not. But I don't know how to forbid it ? I
> tried to return null but it didn't work.
>
>
> @Override
> protected Command createRemoveCommand(EditingDomain domain, EObject
> owner,
> EStructuralFeature feature, Collection<?> collection) {
> Category category = (Category) owner;
> if (category.getRefModel().size() > 0) {
> System.out.println("deletion forbidden");
> return null;
> }
> return super.createRemoveCommand(domain, owner, feature, collection);
> }
>
> Anybody has an idea to solve my problem?
>
> Hugues


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Control deletion [message #418736 is a reply to message #418731] Fri, 25 April 2008 14:19 Go to previous messageGo to next message
Hugues Rérolle is currently offline Hugues RérolleFriend
Messages: 60
Registered: July 2009
Member
Thanks a lot Ed it's working :o)

Do you know which is the best way (compatible with GMF) to inform the
user properly (when deletion is impossible)?

Thanks again,

Hugues



Ed Merks wrote:
> Hugues,
>
> Try returning UnexecutableCommand.INSTANCE. Note that sequential access
> lists, !isEmpty() is more efficient that size() > 0.
>
>
> Hugues Rérolle wrote:
>> Hi all,
>>
>> I want to prevent deletion of element with children.
>>
>> I've overridden createRemoveCommand, I be able to detect if the
>> element would be removed or not. But I don't know how to forbid it ? I
>> tried to return null but it didn't work.
>>
>>
>> @Override
>> protected Command createRemoveCommand(EditingDomain domain, EObject
>> owner,
>> EStructuralFeature feature, Collection<?> collection) {
>> Category category = (Category) owner;
>> if (category.getRefModel().size() > 0) {
>> System.out.println("deletion forbidden");
>> return null;
>> }
>> return super.createRemoveCommand(domain, owner, feature, collection);
>> }
>>
>> Anybody has an idea to solve my problem?
>>
>> Hugues
Re: Control deletion [message #418737 is a reply to message #418736] Fri, 25 April 2008 14:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Hugues,

No. I would have thought it being disabled would be sufficient. What do
I know...


Hugues Rérolle wrote:
> Thanks a lot Ed it's working :o)
>
> Do you know which is the best way (compatible with GMF) to inform the
> user properly (when deletion is impossible)?
>
> Thanks again,
>
> Hugues
>
>
>
> Ed Merks wrote:
>> Hugues,
>>
>> Try returning UnexecutableCommand.INSTANCE. Note that sequential
>> access lists, !isEmpty() is more efficient that size() > 0.
>>
>>
>> Hugues Rérolle wrote:
>>> Hi all,
>>>
>>> I want to prevent deletion of element with children.
>>>
>>> I've overridden createRemoveCommand, I be able to detect if the
>>> element would be removed or not. But I don't know how to forbid it ?
>>> I tried to return null but it didn't work.
>>>
>>>
>>> @Override
>>> protected Command createRemoveCommand(EditingDomain domain, EObject
>>> owner,
>>> EStructuralFeature feature, Collection<?> collection) {
>>> Category category = (Category) owner;
>>> if (category.getRefModel().size() > 0) {
>>> System.out.println("deletion forbidden");
>>> return null;
>>> }
>>> return super.createRemoveCommand(domain, owner, feature,
>>> collection);
>>> }
>>>
>>> Anybody has an idea to solve my problem?
>>>
>>> Hugues


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Control deletion [message #418746 is a reply to message #418736] Fri, 25 April 2008 18:34 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
Hugues Rérolle wrote:
> Thanks a lot Ed it's working :o)
>
> Do you know which is the best way (compatible with GMF) to inform the
> user properly (when deletion is impossible)?

I agree with Ed that just simply disabling the Delete action would be
the most intuitive UI.
However, if you really want to notify the user you could provide an
override command for the delete command that does the user notification
(a MessageDialog, perhaps?) in the prepare() method and then returns
false. Or instead of using the override command mechanism you could just
subclass RemoveCommand ( are you using DeleteCommand?) directly.

Hope this helps,
Eric


> Ed Merks wrote:
>> Hugues,
>>
>> Try returning UnexecutableCommand.INSTANCE. Note that sequential
>> access lists, !isEmpty() is more efficient that size() > 0.
>>
>>
>> Hugues Rérolle wrote:
>>> Hi all,
>>>
>>> I want to prevent deletion of element with children.
>>>
>>> I've overridden createRemoveCommand, I be able to detect if the
>>> element would be removed or not. But I don't know how to forbid it ?
>>> I tried to return null but it didn't work.
>>>
>>>
>>> @Override
>>> protected Command createRemoveCommand(EditingDomain domain, EObject
>>> owner,
>>> EStructuralFeature feature, Collection<?> collection) {
>>> Category category = (Category) owner;
>>> if (category.getRefModel().size() > 0) {
>>> System.out.println("deletion forbidden");
>>> return null;
>>> }
>>> return super.createRemoveCommand(domain, owner, feature,
>>> collection);
>>> }
>>>
>>> Anybody has an idea to solve my problem?
>>>
>>> Hugues
Re: Control deletion [message #418753 is a reply to message #418746] Mon, 28 April 2008 07:53 Go to previous message
Hugues Rérolle is currently offline Hugues RérolleFriend
Messages: 60
Registered: July 2009
Member
Eric Rizzo wrote:
> Hugues Rérolle wrote:
>> Thanks a lot Ed it's working :o)
>>
>> Do you know which is the best way (compatible with GMF) to inform the
>> user properly (when deletion is impossible)?
>
> I agree with Ed that just simply disabling the Delete action would be
> the most intuitive UI.
> However, if you really want to notify the user you could provide an
> override command for the delete command that does the user notification
> (a MessageDialog, perhaps?) in the prepare() method and then returns
> false. Or instead of using the override command mechanism you could just
> subclass RemoveCommand ( are you using DeleteCommand?) directly.
>
> Hope this helps,
> Eric
>

I tried your tip by overriding "prepare" method (of removeCommand), it's
working, Thanks!

Hugues


>
>> Ed Merks wrote:
>>> Hugues,
>>>
>>> Try returning UnexecutableCommand.INSTANCE. Note that sequential
>>> access lists, !isEmpty() is more efficient that size() > 0.
>>>
>>>
>>> Hugues Rérolle wrote:
>>>> Hi all,
>>>>
>>>> I want to prevent deletion of element with children.
>>>>
>>>> I've overridden createRemoveCommand, I be able to detect if the
>>>> element would be removed or not. But I don't know how to forbid it ?
>>>> I tried to return null but it didn't work.
>>>>
>>>>
>>>> @Override
>>>> protected Command createRemoveCommand(EditingDomain domain, EObject
>>>> owner,
>>>> EStructuralFeature feature, Collection<?> collection) {
>>>> Category category = (Category) owner;
>>>> if (category.getRefModel().size() > 0) {
>>>> System.out.println("deletion forbidden");
>>>> return null;
>>>> }
>>>> return super.createRemoveCommand(domain, owner, feature,
>>>> collection);
>>>> }
>>>>
>>>> Anybody has an idea to solve my problem?
>>>>
>>>> Hugues
>
Previous Topic:loading resource without displaying it in editor
Next Topic:AdapterFactories
Goto Forum:
  


Current Time: Fri Apr 26 21:56:44 GMT 2024

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

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

Back to the top