Home » Modeling » EMF » Control deletion
|
Re: Control deletion [message #418731 is a reply to message #418730] |
Fri, 25 April 2008 13:35 |
Ed Merks 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 |
Hugues Rérolle 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 |
Ed Merks 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 |
Eric Rizzo 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 |
Hugues Rérolle 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
>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 21:56:44 GMT 2024
Powered by FUDForum. Page generated in 0.03223 seconds
|