Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Combine Validation and Transaction together?
Combine Validation and Transaction together? [message #34075] Mon, 15 May 2006 05:45 Go to next message
Eclipse UserFriend
Originally posted by: hocnt.cybersoft-vn.com

Dear ALL,

I want to combine EMFT Validation and Transaction in this scenario:

In my (example) application which manages a book store, there is a rule:
a book may have one or more than chapters. So, if user tries to delete
the last chapter of a book, he will get an error message to inform him
that he can not do that. The last chapter of the book won't be deleted.

I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
wish I can define a validation rule that will be triggered when user
tries to delete the last chapter of a book and I can prevent that action.

Ideally, the validation shall be triggerred BEFORE user has performed
the delete action, but this seems impossible.

Less ideally, the validation shall be triggerred in the MIDDLE of the
deleting process, that means in context of a transaction (during the
deleting action). In the validation code, I wish to be able to get the
current transaction and rollback it, but once again, this seems impossible.

Well, the reality is, the validation is triggerred right AFTER the
delete action has been performed. So, I guess that I have to get the
last command in the command stack and undo it. This is not an optimized way.

(Of course, I know that I can write some code to check the constraint
before proceeding the delete action just in the RemoveCommand but I want
to concentrate on the validation in one place)

I'm new with EMFT framework, so please enlighten me about it.

Thanks,
Hoc Nguyen
Re: Combine Validation and Transaction together? [message #34108 is a reply to message #34075] Mon, 15 May 2006 17:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Hoc,

See some replies in-line, below.

HTH,

Christian


Hoc Nguyen wrote:

> Dear ALL,
>
> I want to combine EMFT Validation and Transaction in this scenario:
>
> In my (example) application which manages a book store, there is a rule:
> a book may have one or more than chapters. So, if user tries to delete
> the last chapter of a book, he will get an error message to inform him
> that he can not do that. The last chapter of the book won't be deleted.
>
> I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
> wish I can define a validation rule that will be triggered when user
> tries to delete the last chapter of a book and I can prevent that action.
>
> Ideally, the validation shall be triggerred BEFORE user has performed
> the delete action, but this seems impossible.

Why is this impossible? Just add an enablement condition to your Delete
action that disables the action if the selection includes a chapter in a
book that contains only one chapter.


> Less ideally, the validation shall be triggerred in the MIDDLE of the
> deleting process, that means in context of a transaction (during the
> deleting action). In the validation code, I wish to be able to get the
> current transaction and rollback it, but once again, this seems
> impossible.

You could actually do this, if you attach an adapter to the book (probably
an EContentAdapter) that, upon receiving a REMOVE or REMOVE_MANY event from
a book's chapters feature, checks the number of chapters remaining. If
none remain, the currently active transaction can be aborted by:

- get the active transaction by calling
InternalTransactionalEditingDomain.getActiveTransaction()
- abort it by calling InternalTransaction.abort(IStatus)

This will ensure that the transaction does not commit, but will instead roll
back. However, you should not need to do it this way (see below).


> Well, the reality is, the validation is triggerred right AFTER the
> delete action has been performed. So, I guess that I have to get the
> last command in the command stack and undo it. This is not an optimized
> way.

No, the validation automatically undoes the changes performed by the command
when it rolls back the transaction. The command stack will ensure that the
rolled-back command is not appended to it, so the user will not see any
change in the Undo menu. You need only to ensure that your constraint has
Error severity and Live mode (see the plugin.xml in the validation example
plug-in to see how this works).


> (Of course, I know that I can write some code to check the constraint
> before proceeding the delete action just in the RemoveCommand but I want
> to concentrate on the validation in one place)
>
> I'm new with EMFT framework, so please enlighten me about it.
>
> Thanks,
> Hoc Nguyen
Re: Combine Validation and Transaction together? [message #34588 is a reply to message #34108] Mon, 22 May 2006 09:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hocnt.cybersoft-vn.com

Christian, thank you very much for your support.

The enablement condition seems so interesting. Could you please tell me
how to perform that? I've tried but still don't know how to add an
enablement condition to the delete action.

About the validation and rollback transaction, I can do it now but it
user deletes many objects at a time, these objects are deleted and
restored if at least one of them is not allowed to be deleled. This way
of validation makes the GUI flashed and not user-friendly.

Regards,
Hoc Nguyen


Christian W. Damus wrote:
> Hi, Hoc,
>
> See some replies in-line, below.
>
> HTH,
>
> Christian
>
>
> Hoc Nguyen wrote:
>
>
>>Dear ALL,
>>
>>I want to combine EMFT Validation and Transaction in this scenario:
>>
>>In my (example) application which manages a book store, there is a rule:
>>a book may have one or more than chapters. So, if user tries to delete
>>the last chapter of a book, he will get an error message to inform him
>>that he can not do that. The last chapter of the book won't be deleted.
>>
>>I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>wish I can define a validation rule that will be triggered when user
>>tries to delete the last chapter of a book and I can prevent that action.
>>
>>Ideally, the validation shall be triggerred BEFORE user has performed
>>the delete action, but this seems impossible.
>
>
> Why is this impossible? Just add an enablement condition to your Delete
> action that disables the action if the selection includes a chapter in a
> book that contains only one chapter.
>
>
>
>>Less ideally, the validation shall be triggerred in the MIDDLE of the
>>deleting process, that means in context of a transaction (during the
>>deleting action). In the validation code, I wish to be able to get the
>>current transaction and rollback it, but once again, this seems
>>impossible.
>
>
> You could actually do this, if you attach an adapter to the book (probably
> an EContentAdapter) that, upon receiving a REMOVE or REMOVE_MANY event from
> a book's chapters feature, checks the number of chapters remaining. If
> none remain, the currently active transaction can be aborted by:
>
> - get the active transaction by calling
> InternalTransactionalEditingDomain.getActiveTransaction()
> - abort it by calling InternalTransaction.abort(IStatus)
>
> This will ensure that the transaction does not commit, but will instead roll
> back. However, you should not need to do it this way (see below).
>
>
>
>>Well, the reality is, the validation is triggerred right AFTER the
>>delete action has been performed. So, I guess that I have to get the
>>last command in the command stack and undo it. This is not an optimized
>>way.
>
>
> No, the validation automatically undoes the changes performed by the command
> when it rolls back the transaction. The command stack will ensure that the
> rolled-back command is not appended to it, so the user will not see any
> change in the Undo menu. You need only to ensure that your constraint has
> Error severity and Live mode (see the plugin.xml in the validation example
> plug-in to see how this works).
>
>
>
>>(Of course, I know that I can write some code to check the constraint
>>before proceeding the delete action just in the RemoveCommand but I want
>>to concentrate on the validation in one place)
>>
>>I'm new with EMFT framework, so please enlighten me about it.
>>
>>Thanks,
>>Hoc Nguyen
>
>
Re: Combine Validation and Transaction together? [message #34723 is a reply to message #34588] Tue, 23 May 2006 14:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi,Hoc,

For the enablement condition, you simply need to add an <enablement> element
to your action contribution in the plugin.xml. Eclipse has plenty of
examples of enablement expressions. If necessary, your action delegate can
even implement the selectionChanged() method to introspect the new
selection and disable itself if it contains any elements that should not be
deleted.

Regarding the flashing of the UI: this should only happen if your UI
refreshes immediately upon every dispatch of a Notification from a model
element. That is the main benefit of the Transaction API's post-commit
listeners (ResourceSetChangedListener): if you trigger a UI refresh only
in a post-commit listener, then the refresh is performed at most once. If
the transaction rolls back, then the post-commit listener is not invoked
and your UI will not refresh at all (which is good, because rollback
ensures that the model is not changed, either). This prevents the UI from
removing a bunch of tree nodes (or whatever) only to put them back again
when rollback occurs.

Cheers,

Christian

Hoc Nguyen wrote:

> Christian, thank you very much for your support.
>
> The enablement condition seems so interesting. Could you please tell me
> how to perform that? I've tried but still don't know how to add an
> enablement condition to the delete action.
>
> About the validation and rollback transaction, I can do it now but it
> user deletes many objects at a time, these objects are deleted and
> restored if at least one of them is not allowed to be deleled. This way
> of validation makes the GUI flashed and not user-friendly.
>
> Regards,
> Hoc Nguyen
>
>
> Christian W. Damus wrote:
>> Hi, Hoc,
>>
>> See some replies in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Hoc Nguyen wrote:
>>
>>
>>>Dear ALL,
>>>
>>>I want to combine EMFT Validation and Transaction in this scenario:
>>>
>>>In my (example) application which manages a book store, there is a rule:
>>>a book may have one or more than chapters. So, if user tries to delete
>>>the last chapter of a book, he will get an error message to inform him
>>>that he can not do that. The last chapter of the book won't be deleted.
>>>
>>>I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>>wish I can define a validation rule that will be triggered when user
>>>tries to delete the last chapter of a book and I can prevent that action.
>>>
>>>Ideally, the validation shall be triggerred BEFORE user has performed
>>>the delete action, but this seems impossible.
>>
>>
>> Why is this impossible? Just add an enablement condition to your Delete
>> action that disables the action if the selection includes a chapter in a
>> book that contains only one chapter.
>>
>>
>>
>>>Less ideally, the validation shall be triggerred in the MIDDLE of the
>>>deleting process, that means in context of a transaction (during the
>>>deleting action). In the validation code, I wish to be able to get the
>>>current transaction and rollback it, but once again, this seems
>>>impossible.
>>
>>
>> You could actually do this, if you attach an adapter to the book
>> (probably an EContentAdapter) that, upon receiving a REMOVE or
>> REMOVE_MANY event from
>> a book's chapters feature, checks the number of chapters remaining. If
>> none remain, the currently active transaction can be aborted by:
>>
>> - get the active transaction by calling
>> InternalTransactionalEditingDomain.getActiveTransaction()
>> - abort it by calling InternalTransaction.abort(IStatus)
>>
>> This will ensure that the transaction does not commit, but will instead
>> roll
>> back. However, you should not need to do it this way (see below).
>>
>>
>>
>>>Well, the reality is, the validation is triggerred right AFTER the
>>>delete action has been performed. So, I guess that I have to get the
>>>last command in the command stack and undo it. This is not an optimized
>>>way.
>>
>>
>> No, the validation automatically undoes the changes performed by the
>> command
>> when it rolls back the transaction. The command stack will ensure that
>> the rolled-back command is not appended to it, so the user will not see
>> any
>> change in the Undo menu. You need only to ensure that your constraint
>> has Error severity and Live mode (see the plugin.xml in the validation
>> example plug-in to see how this works).
>>
>>
>>
>>>(Of course, I know that I can write some code to check the constraint
>>>before proceeding the delete action just in the RemoveCommand but I want
>>>to concentrate on the validation in one place)
>>>
>>>I'm new with EMFT framework, so please enlighten me about it.
>>>
>>>Thanks,
>>>Hoc Nguyen
>>
>>
Re: Combine Validation and Transaction together? [message #34794 is a reply to message #34723] Wed, 24 May 2006 09:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: binhduong.cybersoft-vn.com

Hi Christian,

Your recommendation is so useful for us:-)!. Actually we are new in the
EMF and EMFT technology. So could you please explain more about how to
using the post-commit listener (ResourceSetListener) instead of
immediately refresh the UI upon every dispatch of a Notification from a
model element.

Thank you very much for your support!!!

Binh Duong


Christian W. Damus wrote:
> Hi,Hoc,
>
> For the enablement condition, you simply need to add an <enablement> element
> to your action contribution in the plugin.xml. Eclipse has plenty of
> examples of enablement expressions. If necessary, your action delegate can
> even implement the selectionChanged() method to introspect the new
> selection and disable itself if it contains any elements that should not be
> deleted.
>
> Regarding the flashing of the UI: this should only happen if your UI
> refreshes immediately upon every dispatch of a Notification from a model
> element. That is the main benefit of the Transaction API's post-commit
> listeners (ResourceSetChangedListener): if you trigger a UI refresh only
> in a post-commit listener, then the refresh is performed at most once. If
> the transaction rolls back, then the post-commit listener is not invoked
> and your UI will not refresh at all (which is good, because rollback
> ensures that the model is not changed, either). This prevents the UI from
> removing a bunch of tree nodes (or whatever) only to put them back again
> when rollback occurs.
>
> Cheers,
>
> Christian
>
> Hoc Nguyen wrote:
>
>> Christian, thank you very much for your support.
>>
>> The enablement condition seems so interesting. Could you please tell me
>> how to perform that? I've tried but still don't know how to add an
>> enablement condition to the delete action.
>>
>> About the validation and rollback transaction, I can do it now but it
>> user deletes many objects at a time, these objects are deleted and
>> restored if at least one of them is not allowed to be deleled. This way
>> of validation makes the GUI flashed and not user-friendly.
>>
>> Regards,
>> Hoc Nguyen
>>
>>
>> Christian W. Damus wrote:
>>> Hi, Hoc,
>>>
>>> See some replies in-line, below.
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> Hoc Nguyen wrote:
>>>
>>>
>>>> Dear ALL,
>>>>
>>>> I want to combine EMFT Validation and Transaction in this scenario:
>>>>
>>>> In my (example) application which manages a book store, there is a rule:
>>>> a book may have one or more than chapters. So, if user tries to delete
>>>> the last chapter of a book, he will get an error message to inform him
>>>> that he can not do that. The last chapter of the book won't be deleted.
>>>>
>>>> I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>>> wish I can define a validation rule that will be triggered when user
>>>> tries to delete the last chapter of a book and I can prevent that action.
>>>>
>>>> Ideally, the validation shall be triggerred BEFORE user has performed
>>>> the delete action, but this seems impossible.
>>>
>>> Why is this impossible? Just add an enablement condition to your Delete
>>> action that disables the action if the selection includes a chapter in a
>>> book that contains only one chapter.
>>>
>>>
>>>
>>>> Less ideally, the validation shall be triggerred in the MIDDLE of the
>>>> deleting process, that means in context of a transaction (during the
>>>> deleting action). In the validation code, I wish to be able to get the
>>>> current transaction and rollback it, but once again, this seems
>>>> impossible.
>>>
>>> You could actually do this, if you attach an adapter to the book
>>> (probably an EContentAdapter) that, upon receiving a REMOVE or
>>> REMOVE_MANY event from
>>> a book's chapters feature, checks the number of chapters remaining. If
>>> none remain, the currently active transaction can be aborted by:
>>>
>>> - get the active transaction by calling
>>> InternalTransactionalEditingDomain.getActiveTransaction()
>>> - abort it by calling InternalTransaction.abort(IStatus)
>>>
>>> This will ensure that the transaction does not commit, but will instead
>>> roll
>>> back. However, you should not need to do it this way (see below).
>>>
>>>
>>>
>>>> Well, the reality is, the validation is triggerred right AFTER the
>>>> delete action has been performed. So, I guess that I have to get the
>>>> last command in the command stack and undo it. This is not an optimized
>>>> way.
>>>
>>> No, the validation automatically undoes the changes performed by the
>>> command
>>> when it rolls back the transaction. The command stack will ensure that
>>> the rolled-back command is not appended to it, so the user will not see
>>> any
>>> change in the Undo menu. You need only to ensure that your constraint
>>> has Error severity and Live mode (see the plugin.xml in the validation
>>> example plug-in to see how this works).
>>>
>>>
>>>
>>>> (Of course, I know that I can write some code to check the constraint
>>>> before proceeding the delete action just in the RemoveCommand but I want
>>>> to concentrate on the validation in one place)
>>>>
>>>> I'm new with EMFT framework, so please enlighten me about it.
>>>>
>>>> Thanks,
>>>> Hoc Nguyen
>>>
>
Re: Combine Validation and Transaction together? [message #34828 is a reply to message #34794] Wed, 24 May 2006 16:04 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Binh,

That's a rather large question. The answer could be as simple as:

domain.addResourceSetChangeListener(
new ResourceSetChangedListenerImpl() {
public boolean isPostCommitOnly() { return true; }
public void resourceSetChanged(ResourceSetChangeEvent event) {
Display.getDefault().asyncExec(refreshTheUI());
}
});

or as complicated as the DiagramEventBroker class in the GMF diagramming
run-time, which analyzes the Notifications in the ResourceSetChangeEvent
and passes them along to registered GEF EditParts for them to update
themselves.

It really depends on your application. The Notifications in the
ResourceSetChangeEvent may give you a hint as to what portion of the UI
needs to be updated to avoid unnecessarily refreshing content that hasn't
changed. That's really about it.

HTH,

Christian


Binh DUONG wrote:

> Hi Christian,
>
> Your recommendation is so useful for us:-)!. Actually we are new in the
> EMF and EMFT technology. So could you please explain more about how to
> using the post-commit listener (ResourceSetListener) instead of
> immediately refresh the UI upon every dispatch of a Notification from a
> model element.
>
> Thank you very much for your support!!!
>
> Binh Duong
>

<snip>
Re: Combine Validation and Transaction together? [message #577572 is a reply to message #34075] Mon, 15 May 2006 17:01 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Hoc,

See some replies in-line, below.

HTH,

Christian


Hoc Nguyen wrote:

> Dear ALL,
>
> I want to combine EMFT Validation and Transaction in this scenario:
>
> In my (example) application which manages a book store, there is a rule:
> a book may have one or more than chapters. So, if user tries to delete
> the last chapter of a book, he will get an error message to inform him
> that he can not do that. The last chapter of the book won't be deleted.
>
> I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
> wish I can define a validation rule that will be triggered when user
> tries to delete the last chapter of a book and I can prevent that action.
>
> Ideally, the validation shall be triggerred BEFORE user has performed
> the delete action, but this seems impossible.

Why is this impossible? Just add an enablement condition to your Delete
action that disables the action if the selection includes a chapter in a
book that contains only one chapter.


> Less ideally, the validation shall be triggerred in the MIDDLE of the
> deleting process, that means in context of a transaction (during the
> deleting action). In the validation code, I wish to be able to get the
> current transaction and rollback it, but once again, this seems
> impossible.

You could actually do this, if you attach an adapter to the book (probably
an EContentAdapter) that, upon receiving a REMOVE or REMOVE_MANY event from
a book's chapters feature, checks the number of chapters remaining. If
none remain, the currently active transaction can be aborted by:

- get the active transaction by calling
InternalTransactionalEditingDomain.getActiveTransaction()
- abort it by calling InternalTransaction.abort(IStatus)

This will ensure that the transaction does not commit, but will instead roll
back. However, you should not need to do it this way (see below).


> Well, the reality is, the validation is triggerred right AFTER the
> delete action has been performed. So, I guess that I have to get the
> last command in the command stack and undo it. This is not an optimized
> way.

No, the validation automatically undoes the changes performed by the command
when it rolls back the transaction. The command stack will ensure that the
rolled-back command is not appended to it, so the user will not see any
change in the Undo menu. You need only to ensure that your constraint has
Error severity and Live mode (see the plugin.xml in the validation example
plug-in to see how this works).


> (Of course, I know that I can write some code to check the constraint
> before proceeding the delete action just in the RemoveCommand but I want
> to concentrate on the validation in one place)
>
> I'm new with EMFT framework, so please enlighten me about it.
>
> Thanks,
> Hoc Nguyen
Re: Combine Validation and Transaction together? [message #578236 is a reply to message #34108] Mon, 22 May 2006 09:42 Go to previous message
Eclipse UserFriend
Originally posted by: hocnt.cybersoft-vn.com

Christian, thank you very much for your support.

The enablement condition seems so interesting. Could you please tell me
how to perform that? I've tried but still don't know how to add an
enablement condition to the delete action.

About the validation and rollback transaction, I can do it now but it
user deletes many objects at a time, these objects are deleted and
restored if at least one of them is not allowed to be deleled. This way
of validation makes the GUI flashed and not user-friendly.

Regards,
Hoc Nguyen


Christian W. Damus wrote:
> Hi, Hoc,
>
> See some replies in-line, below.
>
> HTH,
>
> Christian
>
>
> Hoc Nguyen wrote:
>
>
>>Dear ALL,
>>
>>I want to combine EMFT Validation and Transaction in this scenario:
>>
>>In my (example) application which manages a book store, there is a rule:
>>a book may have one or more than chapters. So, if user tries to delete
>>the last chapter of a book, he will get an error message to inform him
>>that he can not do that. The last chapter of the book won't be deleted.
>>
>>I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>wish I can define a validation rule that will be triggered when user
>>tries to delete the last chapter of a book and I can prevent that action.
>>
>>Ideally, the validation shall be triggerred BEFORE user has performed
>>the delete action, but this seems impossible.
>
>
> Why is this impossible? Just add an enablement condition to your Delete
> action that disables the action if the selection includes a chapter in a
> book that contains only one chapter.
>
>
>
>>Less ideally, the validation shall be triggerred in the MIDDLE of the
>>deleting process, that means in context of a transaction (during the
>>deleting action). In the validation code, I wish to be able to get the
>>current transaction and rollback it, but once again, this seems
>>impossible.
>
>
> You could actually do this, if you attach an adapter to the book (probably
> an EContentAdapter) that, upon receiving a REMOVE or REMOVE_MANY event from
> a book's chapters feature, checks the number of chapters remaining. If
> none remain, the currently active transaction can be aborted by:
>
> - get the active transaction by calling
> InternalTransactionalEditingDomain.getActiveTransaction()
> - abort it by calling InternalTransaction.abort(IStatus)
>
> This will ensure that the transaction does not commit, but will instead roll
> back. However, you should not need to do it this way (see below).
>
>
>
>>Well, the reality is, the validation is triggerred right AFTER the
>>delete action has been performed. So, I guess that I have to get the
>>last command in the command stack and undo it. This is not an optimized
>>way.
>
>
> No, the validation automatically undoes the changes performed by the command
> when it rolls back the transaction. The command stack will ensure that the
> rolled-back command is not appended to it, so the user will not see any
> change in the Undo menu. You need only to ensure that your constraint has
> Error severity and Live mode (see the plugin.xml in the validation example
> plug-in to see how this works).
>
>
>
>>(Of course, I know that I can write some code to check the constraint
>>before proceeding the delete action just in the RemoveCommand but I want
>>to concentrate on the validation in one place)
>>
>>I'm new with EMFT framework, so please enlighten me about it.
>>
>>Thanks,
>>Hoc Nguyen
>
>
Re: Combine Validation and Transaction together? [message #578383 is a reply to message #34588] Tue, 23 May 2006 14:39 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi,Hoc,

For the enablement condition, you simply need to add an <enablement> element
to your action contribution in the plugin.xml. Eclipse has plenty of
examples of enablement expressions. If necessary, your action delegate can
even implement the selectionChanged() method to introspect the new
selection and disable itself if it contains any elements that should not be
deleted.

Regarding the flashing of the UI: this should only happen if your UI
refreshes immediately upon every dispatch of a Notification from a model
element. That is the main benefit of the Transaction API's post-commit
listeners (ResourceSetChangedListener): if you trigger a UI refresh only
in a post-commit listener, then the refresh is performed at most once. If
the transaction rolls back, then the post-commit listener is not invoked
and your UI will not refresh at all (which is good, because rollback
ensures that the model is not changed, either). This prevents the UI from
removing a bunch of tree nodes (or whatever) only to put them back again
when rollback occurs.

Cheers,

Christian

Hoc Nguyen wrote:

> Christian, thank you very much for your support.
>
> The enablement condition seems so interesting. Could you please tell me
> how to perform that? I've tried but still don't know how to add an
> enablement condition to the delete action.
>
> About the validation and rollback transaction, I can do it now but it
> user deletes many objects at a time, these objects are deleted and
> restored if at least one of them is not allowed to be deleled. This way
> of validation makes the GUI flashed and not user-friendly.
>
> Regards,
> Hoc Nguyen
>
>
> Christian W. Damus wrote:
>> Hi, Hoc,
>>
>> See some replies in-line, below.
>>
>> HTH,
>>
>> Christian
>>
>>
>> Hoc Nguyen wrote:
>>
>>
>>>Dear ALL,
>>>
>>>I want to combine EMFT Validation and Transaction in this scenario:
>>>
>>>In my (example) application which manages a book store, there is a rule:
>>>a book may have one or more than chapters. So, if user tries to delete
>>>the last chapter of a book, he will get an error message to inform him
>>>that he can not do that. The last chapter of the book won't be deleted.
>>>
>>>I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>>wish I can define a validation rule that will be triggered when user
>>>tries to delete the last chapter of a book and I can prevent that action.
>>>
>>>Ideally, the validation shall be triggerred BEFORE user has performed
>>>the delete action, but this seems impossible.
>>
>>
>> Why is this impossible? Just add an enablement condition to your Delete
>> action that disables the action if the selection includes a chapter in a
>> book that contains only one chapter.
>>
>>
>>
>>>Less ideally, the validation shall be triggerred in the MIDDLE of the
>>>deleting process, that means in context of a transaction (during the
>>>deleting action). In the validation code, I wish to be able to get the
>>>current transaction and rollback it, but once again, this seems
>>>impossible.
>>
>>
>> You could actually do this, if you attach an adapter to the book
>> (probably an EContentAdapter) that, upon receiving a REMOVE or
>> REMOVE_MANY event from
>> a book's chapters feature, checks the number of chapters remaining. If
>> none remain, the currently active transaction can be aborted by:
>>
>> - get the active transaction by calling
>> InternalTransactionalEditingDomain.getActiveTransaction()
>> - abort it by calling InternalTransaction.abort(IStatus)
>>
>> This will ensure that the transaction does not commit, but will instead
>> roll
>> back. However, you should not need to do it this way (see below).
>>
>>
>>
>>>Well, the reality is, the validation is triggerred right AFTER the
>>>delete action has been performed. So, I guess that I have to get the
>>>last command in the command stack and undo it. This is not an optimized
>>>way.
>>
>>
>> No, the validation automatically undoes the changes performed by the
>> command
>> when it rolls back the transaction. The command stack will ensure that
>> the rolled-back command is not appended to it, so the user will not see
>> any
>> change in the Undo menu. You need only to ensure that your constraint
>> has Error severity and Live mode (see the plugin.xml in the validation
>> example plug-in to see how this works).
>>
>>
>>
>>>(Of course, I know that I can write some code to check the constraint
>>>before proceeding the delete action just in the RemoveCommand but I want
>>>to concentrate on the validation in one place)
>>>
>>>I'm new with EMFT framework, so please enlighten me about it.
>>>
>>>Thanks,
>>>Hoc Nguyen
>>
>>
Re: Combine Validation and Transaction together? [message #578441 is a reply to message #34723] Wed, 24 May 2006 09:34 Go to previous message
Eclipse UserFriend
Originally posted by: binhduong.cybersoft-vn.com

Hi Christian,

Your recommendation is so useful for us:-)!. Actually we are new in the
EMF and EMFT technology. So could you please explain more about how to
using the post-commit listener (ResourceSetListener) instead of
immediately refresh the UI upon every dispatch of a Notification from a
model element.

Thank you very much for your support!!!

Binh Duong


Christian W. Damus wrote:
> Hi,Hoc,
>
> For the enablement condition, you simply need to add an <enablement> element
> to your action contribution in the plugin.xml. Eclipse has plenty of
> examples of enablement expressions. If necessary, your action delegate can
> even implement the selectionChanged() method to introspect the new
> selection and disable itself if it contains any elements that should not be
> deleted.
>
> Regarding the flashing of the UI: this should only happen if your UI
> refreshes immediately upon every dispatch of a Notification from a model
> element. That is the main benefit of the Transaction API's post-commit
> listeners (ResourceSetChangedListener): if you trigger a UI refresh only
> in a post-commit listener, then the refresh is performed at most once. If
> the transaction rolls back, then the post-commit listener is not invoked
> and your UI will not refresh at all (which is good, because rollback
> ensures that the model is not changed, either). This prevents the UI from
> removing a bunch of tree nodes (or whatever) only to put them back again
> when rollback occurs.
>
> Cheers,
>
> Christian
>
> Hoc Nguyen wrote:
>
>> Christian, thank you very much for your support.
>>
>> The enablement condition seems so interesting. Could you please tell me
>> how to perform that? I've tried but still don't know how to add an
>> enablement condition to the delete action.
>>
>> About the validation and rollback transaction, I can do it now but it
>> user deletes many objects at a time, these objects are deleted and
>> restored if at least one of them is not allowed to be deleled. This way
>> of validation makes the GUI flashed and not user-friendly.
>>
>> Regards,
>> Hoc Nguyen
>>
>>
>> Christian W. Damus wrote:
>>> Hi, Hoc,
>>>
>>> See some replies in-line, below.
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> Hoc Nguyen wrote:
>>>
>>>
>>>> Dear ALL,
>>>>
>>>> I want to combine EMFT Validation and Transaction in this scenario:
>>>>
>>>> In my (example) application which manages a book store, there is a rule:
>>>> a book may have one or more than chapters. So, if user tries to delete
>>>> the last chapter of a book, he will get an error message to inform him
>>>> that he can not do that. The last chapter of the book won't be deleted.
>>>>
>>>> I'm using EMFT Transaction. I'm trying to use EMFT Validation. Thus, I
>>>> wish I can define a validation rule that will be triggered when user
>>>> tries to delete the last chapter of a book and I can prevent that action.
>>>>
>>>> Ideally, the validation shall be triggerred BEFORE user has performed
>>>> the delete action, but this seems impossible.
>>>
>>> Why is this impossible? Just add an enablement condition to your Delete
>>> action that disables the action if the selection includes a chapter in a
>>> book that contains only one chapter.
>>>
>>>
>>>
>>>> Less ideally, the validation shall be triggerred in the MIDDLE of the
>>>> deleting process, that means in context of a transaction (during the
>>>> deleting action). In the validation code, I wish to be able to get the
>>>> current transaction and rollback it, but once again, this seems
>>>> impossible.
>>>
>>> You could actually do this, if you attach an adapter to the book
>>> (probably an EContentAdapter) that, upon receiving a REMOVE or
>>> REMOVE_MANY event from
>>> a book's chapters feature, checks the number of chapters remaining. If
>>> none remain, the currently active transaction can be aborted by:
>>>
>>> - get the active transaction by calling
>>> InternalTransactionalEditingDomain.getActiveTransaction()
>>> - abort it by calling InternalTransaction.abort(IStatus)
>>>
>>> This will ensure that the transaction does not commit, but will instead
>>> roll
>>> back. However, you should not need to do it this way (see below).
>>>
>>>
>>>
>>>> Well, the reality is, the validation is triggerred right AFTER the
>>>> delete action has been performed. So, I guess that I have to get the
>>>> last command in the command stack and undo it. This is not an optimized
>>>> way.
>>>
>>> No, the validation automatically undoes the changes performed by the
>>> command
>>> when it rolls back the transaction. The command stack will ensure that
>>> the rolled-back command is not appended to it, so the user will not see
>>> any
>>> change in the Undo menu. You need only to ensure that your constraint
>>> has Error severity and Live mode (see the plugin.xml in the validation
>>> example plug-in to see how this works).
>>>
>>>
>>>
>>>> (Of course, I know that I can write some code to check the constraint
>>>> before proceeding the delete action just in the RemoveCommand but I want
>>>> to concentrate on the validation in one place)
>>>>
>>>> I'm new with EMFT framework, so please enlighten me about it.
>>>>
>>>> Thanks,
>>>> Hoc Nguyen
>>>
>
Re: Combine Validation and Transaction together? [message #578464 is a reply to message #34794] Wed, 24 May 2006 16:04 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Binh,

That's a rather large question. The answer could be as simple as:

domain.addResourceSetChangeListener(
new ResourceSetChangedListenerImpl() {
public boolean isPostCommitOnly() { return true; }
public void resourceSetChanged(ResourceSetChangeEvent event) {
Display.getDefault().asyncExec(refreshTheUI());
}
});

or as complicated as the DiagramEventBroker class in the GMF diagramming
run-time, which analyzes the Notifications in the ResourceSetChangeEvent
and passes them along to registered GEF EditParts for them to update
themselves.

It really depends on your application. The Notifications in the
ResourceSetChangeEvent may give you a hint as to what portion of the UI
needs to be updated to avoid unnecessarily refreshing content that hasn't
changed. That's really about it.

HTH,

Christian


Binh DUONG wrote:

> Hi Christian,
>
> Your recommendation is so useful for us:-)!. Actually we are new in the
> EMF and EMFT technology. So could you please explain more about how to
> using the post-commit listener (ResourceSetListener) instead of
> immediately refresh the UI upon every dispatch of a Notification from a
> model element.
>
> Thank you very much for your support!!!
>
> Binh Duong
>

<snip>
Previous Topic:java.lang.CircularityError IClientSelector
Next Topic:[Announce] EMFT JETEDITOR 1.0.0 I200605202022 is available
Goto Forum:
  


Current Time: Sun May 19 04:41:40 GMT 2024

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

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

Back to the top