Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to gracefully cancel a transaction?
How to gracefully cancel a transaction? [message #1064264] Tue, 18 June 2013 09:43 Go to next message
Robert Brodt is currently offline Robert Brodt
Messages: 590
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi all,

My editor uses a popup dialog to gather some user input and this dialog creates some new objects that are attached to the existing model, so it runs within an EMF transaction. The user has the option of cancelling the dialog, so it needs to be able to restore the model to its previous state. I'm assuming the best way to do this is to roll back the transaction (or abort? cancel?)

I've tried throwing an OperationCanceledException but this results in an INFO log message to be written to the error log. Is there any way to prevent these messages from being emitted and cluttering up the log?

Thanks,
Bob
Re: How to gracefully cancel a transaction? [message #1064427 is a reply to message #1064264] Wed, 19 June 2013 04:35 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1583
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Bob,

the Graphiti logging is currently not configurable. Please file a Bugzilla
if you would like to have that option.

Michael
Re: How to gracefully cancel a transaction? [message #1064502 is a reply to message #1064427] Wed, 19 June 2013 10:04 Go to previous messageGo to next message
Robert Brodt is currently offline Robert Brodt
Messages: 590
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Thanks Michael, created an enhancement request.

Is there a different way of cancelling a write transaction that won't generate and info or error log message?
Re: How to gracefully cancel a transaction? [message #1064603 is a reply to message #1064502] Thu, 20 June 2013 04:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1583
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Thanks for filing that bug.

Currently there is no other way of gracefully cancelling.

Michael
Re: How to gracefully cancel a transaction? [message #1074352 is a reply to message #1064603] Fri, 26 July 2013 11:00 Go to previous message
Robert Brodt is currently offline Robert Brodt
Messages: 590
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

The solution (at least for my use-case) is to have the popup dialog manage the transaction. I have a Custom Feature that, when executed, displays a popup properties dialog for the selected Shape or Connection. When the dialog is created, it also creates a new transaction, like so:

    private void initializeTransaction() {
        try {
            final InternalTransactionalEditingDomain transactionalDomain = (InternalTransactionalEditingDomain) editor
                    .getEditingDomain();
            transaction = transactionalDomain.startTransaction(false, null);
            getShell().addDisposeListener(new DisposeListener() {
                public void widgetDisposed(DisposeEvent event) {
                    if (transaction.isActive()) {
                        if (cancel) {
                            transaction.rollback();
                        }
                        else {
                            try {
                                transaction.commit();
                            }
                            catch (RollbackException e) {
                                ErrorDialog.openError(getShell(), "Error Commiting Model Changes",
                                        "An error occurred while trying to commit changes.", new Status(IStatus.ERROR,
                                                Activator.PLUGIN_ID, e.getMessage(), e));
                            }
                        }
                    }
                }
            });
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


the boolean class variable "cancel" is set "true" in the dialog's okPressed() and "false" in cancelPressed() overrides and the dispose listener handles the closing of the transaction.

The Custom Feature also needs to override AbstractFeature.hasDoneChanges() which is returned by the popup dialog's hasDoneChanges(), like so:

    public boolean hasDoneChanges() {
        return transaction==null || !transaction.getChangeDescription().isEmpty();
    }


HTH,
Bob
Previous Topic:"Click through" an unfilled RoundedRectangle
Next Topic:Distinguish different types of connection in getAddFeature method
Goto Forum:
  


Current Time: Fri Aug 22 16:01:05 EDT 2014

Powered by FUDForum. Page generated in 0.09012 seconds