Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Execute Command without stacking on CommandStack
Execute Command without stacking on CommandStack [message #1151281] Wed, 23 October 2013 08:36 Go to next message
Erik Schondorff is currently offline Erik SchondorffFriend
Messages: 25
Registered: October 2013
Junior Member
Hi community,

my former aim was simply to set a property of a model element (out of the handleNotification - Method of an EditPart)

First I tried simply EObject.eSet(...) which runs into following exception:
"Cannot modify resource set without a write transaction"

Second try was to run a SetCommand adding on the CommandStack of TransactionalEditingDomain...runs in an exception too, something like "no permissions for read/write transactions"

Then I found following code snippet, which runs:

try
{
ted.runExclusive(new Runnable()
{
public void run ()
{
Display display = PlatformUI.getWorkbench().getDisplay();
display.asyncExec(new Runnable()
{
public void run ()
{
ted.getCommandStack().execute(setter);
}
});
}
});
}
catch (InterruptedException e)
{
e.printStackTrace();
}

-------------

But now I want to set a property, but which is not undoable, so will not be stacked on the CommandStack. Thought, eSet in the innermost run() method could work, but runs in same exception as the first. How I can reach my aim?

Thanks

Best Regards, Erik
Re: Execute Command without stacking on CommandStack [message #1151421 is a reply to message #1151281] Wed, 23 October 2013 10:37 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 23/10/2013 10:36, Erik Schondorff wrote:

> Second try was to run a SetCommand adding on the CommandStack of
> TransactionalEditingDomain...runs in an exception too, something like
> "no permissions for read/write transactions"

I'm interested in that. Can you show us the meaningful parts of the
stack trace?
Re: Execute Command without stacking on CommandStack [message #1151469 is a reply to message #1151281] Wed, 23 October 2013 11:19 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 23/10/2013 10:36, Erik Schondorff wrote:
> But now I want to set a property, but which is not undoable, so will not
> be stacked on the CommandStack. Thought, eSet in the innermost run()
> method could work, but runs in same exception as the first. How I can
> reach my aim?

This works for me, but I don't know if it's all technically correct, or
if there's a simpler way. Christian will probably answer soon :)

TransactionImpl t = new TransactionImpl(editingDomain, false,
Collections.EMPTY_MAP);
t.start();
Command c = SetCommand.create(...);
if (c.canExecute()){
c.execute();
}
try {
t.commit();
} catch (RollbackException exception_p) {
// ...
}

Felix
Re: Execute Command without stacking on CommandStack [message #1151538 is a reply to message #1151469] Wed, 23 October 2013 12:16 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 1195
Registered: July 2009
Location: Canada
Senior Member

Hi, Felix,

Yes, that works, but I'm a bit concerned about the statement that the
change should not be undoable. Does this command alter objects that
were modified by commands that are on the stack? If so, undoing them
would no longer work and the stack had better be flushed to avoid
potential damage.

The TransactionalCommandStack has a variant of the execute method that
accepts transaction options: passing the NO_REDO option would let the
command-stack execute the command as usual but, because it would not be
undoable, the stack would not be canUndo() and hopefully would flush
itself. But, I don't know whether it works this way ... it is all so
long ago.

HTH

Christian


On 2013-10-23 11:19:37 +0000, Felix Dorner said:

> On 23/10/2013 10:36, Erik Schondorff wrote:
>> But now I want to set a property, but which is not undoable, so will not
>> be stacked on the CommandStack. Thought, eSet in the innermost run()
>> method could work, but runs in same exception as the first. How I can
>> reach my aim?
>
> This works for me, but I don't know if it's all technically correct, or
> if there's a simpler way. Christian will probably answer soon :)
>
> TransactionImpl t = new TransactionImpl(editingDomain, false,
> Collections.EMPTY_MAP);
> t.start();
> Command c = SetCommand.create(...);
> if (c.canExecute()){
> c.execute();
> }
> try {
> t.commit();
> } catch (RollbackException exception_p) {
> // ...
> }
>
> Felix
Re: Execute Command without stacking on CommandStack [message #1151544 is a reply to message #1151421] Wed, 23 October 2013 12:25 Go to previous messageGo to next message
Erik Schondorff is currently offline Erik SchondorffFriend
Messages: 25
Registered: October 2013
Junior Member
Thanks for your reply Smile

I will try out your proposal soon.

Maybe, I have to say, that the editor is an extension for the papyrus editor, but I thought, this would be a more typical topic for EMF instead of papyrus Smile

The following command(s) (in XXXEditPart.handleNotification(Notification event) ):
eNotifier = (EObject)event.getNotifier();
TransactionalEditingDomain domain = (TransactionalEditingDomain)AdapterFactoryEditingDomain.getEditingDomainFor(eNotifier);
domain.getCommandStack().execute(SetCommand.create(domain, eNotifier, XXXPackage.Literals.MODEL_ELEMENT__MODEL_PROPERTY, false));


results in following error (think, this should be enough):
java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:576)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.activate(TransactionalEditingDomainImpl.java:508)
at org.eclipse.emf.transaction.impl.TransactionImpl.start(TransactionImpl.java:204)
at org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStack.createTransaction(NotifyingWorkspaceCommandStack.java:394)
at org.eclipse.emf.workspace.EMFCommandOperation.createTransaction(EMFCommandOperation.java:215)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:147)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:513)
at org.eclipse.papyrus.commands.CheckedOperationHistory.execute(CheckedOperationHistory.java:182)
at org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStack.doExecute(NotifyingWorkspaceCommandStack.java:252)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
at de.vw.ag.papyrus.swat.diagram.edit.parts.Anforderung2EditPart.handleNotificationEvent(Anforderung2EditPart.java:132)
at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.notifyChanged(GraphicalEditPart.java:1438)
at org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.fireNotification(DiagramEventBroker.java:500)
at org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.resourceSetChanged(DiagramEventBroker.java:395)
at org.eclipse.gmf.runtime.diagram.ui.DiagramEventBrokerThreadSafe.resourceSetChanged(DiagramEventBrokerThreadSafe.java:73)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl$1.run(TransactionalEditingDomainImpl.java:781)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.postcommit(TransactionalEditingDomainImpl.java:771)
at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.deactivate(TransactionalEditingDomainImpl.java:543)
at org.eclipse.emf.transaction.impl.TransactionImpl.close(TransactionImpl.java:712)
at org.eclipse.emf.transaction.impl.TransactionImpl.commit(TransactionImpl.java:474)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:155)
Re: Execute Command without stacking on CommandStack [message #1151624 is a reply to message #1151544] Wed, 23 October 2013 13:31 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
You need to make sure you understand the different transaction contexts,
that is none, read, read/write. Read once through the EMF Transaction
documentation, it is very good and not too complex.

Your code executes inside the call stack of a post-commit listener,
which is always in a readOnly context. It's not possible to modify the
model here.

Instead, you should put your model changing code in a
NotificationPreCommitListener, and register it somehow with the
DiagramEventBroker. Maybe the GMF group can also help, I have only a
very basic idea about that stuff.

On 23/10/2013 14:25, Erik Schondorff wrote:
> java.lang.IllegalStateException: Cannot activate read/write transaction
> in read-only transaction context
> at
> org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:576)
>
> at
> org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.activate(TransactionalEditingDomainImpl.java:508)
>
> at
> org.eclipse.emf.transaction.impl.TransactionImpl.start(TransactionImpl.java:204)
>
> at
> org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStack.createTransaction(NotifyingWorkspaceCommandStack.java:394)
>
> at
> org.eclipse.emf.workspace.EMFCommandOperation.createTransaction(EMFCommandOperation.java:215)
>
> at
> org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:147)
>
> at
> org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:513)
>
> at
> org.eclipse.papyrus.commands.CheckedOperationHistory.execute(CheckedOperationHistory.java:182)
>
> at
> org.eclipse.papyrus.commands.NotifyingWorkspaceCommandStack.doExecute(NotifyingWorkspaceCommandStack.java:252)
>
> at
> org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
>
> at
> org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
>
> at
> de.vw.ag.papyrus.swat.diagram.edit.parts.Anforderung2EditPart.handleNotificationEvent(Anforderung2EditPart.java:132)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.notifyChanged(GraphicalEditPart.java:1438)
>
> at
> org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.fireNotification(DiagramEventBroker.java:500)
>
> at
> org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker.resourceSetChanged(DiagramEventBroker.java:395)
>
> at
> org.eclipse.gmf.runtime.diagram.ui.DiagramEventBrokerThreadSafe.resourceSetChanged(DiagramEventBrokerThreadSafe.java:73)
>
> at
> org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl$1.run(TransactionalEditingDomainImpl.java:781)
>
> at
> org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
>
> at
> org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.postcommit(TransactionalEditingDomainImpl.java:771)
>
Previous Topic:Namespace information lost in reference
Next Topic:[CDO] CDO Editor missing "Live Validation"
Goto Forum:
  


Current Time: Sat Aug 24 09:11:53 GMT 2019

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

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

Back to the top