read-only transaction context problem [message #484667] |
Tue, 08 September 2009 12:53  |
Eclipse User |
|
|
|
Dear GMF folks,
I want to set an attribute of the EMF model from some arbitrary method
(not an Edit Policy). In particular I do it from the getPrintString()
method of a label parser, but never mind.
However, the following code results in a
java.lang.IllegalStateException: Cannot activate read/write transaction
in read-only transaction context
Why?
Hauke
------------------------------------------------------------ --------
final newString = ...
final targetElement = some EMF model object (EObject)
ICommand command = new AbstractTransactionalCommand(TransactionUtil
.getEditingDomain(targetElement), newString, null){
@Override
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
targetElement.setTriggersAndEffects(newString);
return CommandResult.newOKCommandResult();
}
};
ICommandProxy proxy = new ICommandProxy(command);
IEditorPart editor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor();
if(editor instanceof DiagramEditor){
DiagramCommandStack commandStack = null;
Object adapter = ((DiagramEditor)
editor).getAdapter(CommandStack.class);
if (adapter instanceof DiagramCommandStack)
commandStack = (DiagramCommandStack) adapter;
if (commandStack == null)
commandStack = new DiagramCommandStack(null);
commandStack.execute(proxy);
}
------------------------------------------------------------ --------
|
|
|
|
|
|
Re: read-only transaction context problem [message #486478 is a reply to message #484916] |
Thu, 17 September 2009 15:08   |
Eclipse User |
|
|
|
Sascha, thanks for your answer. However, it is not exactly working. See
below.
Sascha Geßler schrieb:
>> However, the following code results in a
>> java.lang.IllegalStateException: Cannot activate read/write
>> transaction in read-only transaction context
>
> Please note that the constructor of a RecordingCommand needs an
> TransactionalEditingDomain (which can be acquired from many GMF
> elements, for example by IGraphicalEditPart.getEditingDomain()).The
> editing domain also provides access to the command stack that should be
> used to execute the command.
>
> Executing your RecordingCommand on this CommandStack should provide you
> with an valid read/write transaction.
Whatever command I use, the problem is always the same. I tried a
SetCommand, a RecordingCommand or a custom command.
The problem is, that in my situation, the CommandStack I get from the
corresponding EObject is in a read-only state, i.e. the EditingDomain
has an active read-only transaction. So my write command triggers that
exception.
The thing is, that I want to tell the CommandStack then to execute the
command *after* the read-only transaction has been run through... How
can I do that? There must be a way...
Hauke
|
|
|
|
Powered by
FUDForum. Page generated in 0.07075 seconds