Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » read-only transaction context problem
read-only transaction context problem [message #484667] Tue, 08 September 2009 16:53 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
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 #484827 is a reply to message #484667] Wed, 09 September 2009 13:03 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Hauke,

I think the reason is - read-only transaction was started before calling
getPrintString() method, so you are not expected to modify any model properties
there.

-----------------
Alex Shatalin
Re: read-only transaction context problem [message #484858 is a reply to message #484827] Wed, 09 September 2009 13:54 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Alex Shatalin schrieb:
> I think the reason is - read-only transaction was started before calling
> getPrintString() method, so you are not expected to modify any model
> properties there.

Hey Alex,

ah, thanks for that hint. Maybe I did not get that command thing right
then yet.

So I don't really need to execute that command synchronously. I would
simply like to schedule my command such that it gets executed whenever
there is a writable status again.

Is there a way to push my command to the command stack such that it gets
executed later?

Cheers,
Hauke
Re: read-only transaction context problem [message #484916 is a reply to message #484667] Wed, 09 September 2009 16:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: news.sascha.gessler.googlemail.com

Hi Hauke,

> I want to set an attribute of the EMF model from some arbitrary method
> (not an Edit Policy).

usually a good way to go are RecordingCommands. A RecordingCommand records
the changes made by a subclass's direct manipulation of objects via the
metamodel's API. This simplifies the programming model for complex
commands and should be suitable for your application case.

> 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.


Cheers,

sas
Re: read-only transaction context problem [message #486478 is a reply to message #484916] Thu, 17 September 2009 19:08 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
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
Re: read-only transaction context problem [message #1268850 is a reply to message #486478] Tue, 11 March 2014 03:54 Go to previous message
Mona Chawla is currently offline Mona ChawlaFriend
Messages: 3
Registered: March 2014
Junior Member
Hi All,

I'm also facing the same issue. Any suggestions on this front?

Thanks in advance,
Mona
Previous Topic:How to dynamically extend palette
Next Topic:as change a EditPart, or change a figure in GEF
Goto Forum:
  


Current Time: Thu Mar 28 12:59:50 GMT 2024

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

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

Back to the top