Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Cannot modify resource set without a write transaction
Cannot modify resource set without a write transaction [message #71849] Tue, 31 October 2006 09:52 Go to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi!

I am trying to change one of the attributes of an object when a node is
double-clicked on the diagram, but I am having some problems with it.

My case is the following:
the object name is a "track" and its attribute "status" can be OCCUPIED or
FREE. I want that, when a object track is doubled-clicked, it changes the
status from free to occupied or viceversa. I created a new class extending
OpenEditPolicy, and this the code in the getOpenCommand function:

protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);
if (targetEditPart instanceof IGraphicalEditPart) {
IGraphicalEditPart editPart =
(IGraphicalEditPart)targetEditPart; Track thisObject = (Track)
((View) editPart.getModel()).getElement();
StatusType myStatus=thisObject.getTrackStatus();

if(myStatus.equals(StatusType.OCCUPIED_LITERAL)){
thisObject.setTrackStatus(StatusType.FREE_LITERAL);
}
else{
thisObject.setTrackStatus(StatusType.OCCUPIED_LITERAL);
}
}
return null;
}

That code it is actually changing the status, but it throws these
exceptions:
Cannot modify resource set without a write transaction
Read-only transaction rolled back
- Transaction aborted due to concurrent write
Unhandled event loop exception

This is the Exception track trace:
java.lang.IllegalStateException: Cannot modify resource set without a
write transaction
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:291)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:253)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:235)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:191)
at
org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:230)
at
com.bombardier.train_sim.yard.impl.TrackImpl.setTrackStatus( TrackImpl.java:131)
at
com.bombardier.train_sim.yard.diagram.edit.policies.ClickedT rackEditPolicy.getOpenCommand(ClickedTrackEditPolicy.java:44 )
at
org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPoli cy.getCommand(OpenEditPolicy.java:58)
at
org.eclipse.gef.editparts.AbstractEditPart.getCommand(Abstra ctEditPart.java:473)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.access$1(GraphicalEditPart.java:1)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt$1.run(GraphicalEditPart.java:414)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.runExclusive(TransactionalEditingDomainImpl.java:258)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.getCommand(GraphicalEditPart.java:409)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.performRequest(GraphicalEditPart.java:964)
at
org.eclipse.gef.tools.SelectEditPartTracker.performOpen(Sele ctEditPartTracker.java:187)
at
org.eclipse.gef.tools.SelectEditPartTracker.handleDoubleClic k(SelectEditPartTracker.java:131)
at
org.eclipse.gef.tools.AbstractTool.mouseDoubleClick(Abstract Tool.java:944)
at
org.eclipse.gef.tools.SelectionTool.mouseDoubleClick(Selecti onTool.java:501)
at org.eclipse.gef.EditDomain.mouseDoubleClick(EditDomain.java: 204)
...

I tried to fix it by using EditingDomain as explained in the topic:
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg01922.html
but it did not work. Does someone how to get rid of this exception? Thanks
for your time!
Re: Cannot modify resource set without a write transaction [message #71883 is a reply to message #71849] Tue, 31 October 2006 12:10 Go to previous messageGo to next message
ciukes is currently offline ciukesFriend
Messages: 19
Registered: July 2009
Junior Member
> I tried to fix it by using EditingDomain as explained in the topic:
> http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg01922.html
> but it did not work.
Could you tell more about that?
Executing command on CommandStack is desired way.

Regards,
Marcin.
Re: Cannot modify resource set without a write transaction [message #71902 is a reply to message #71883] Tue, 31 October 2006 12:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi!

I followed the example in the topic and changed the code to this:
------------------------------------------------------------ ---------------
public class ClickedTrackEditPolicy extends OpenEditPolicy {

protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);
if (targetEditPart instanceof IGraphicalEditPart) {
IGraphicalEditPart editPart = (IGraphicalEditPart)targetEditPart;
Track thisObject = (Track) ((View)
editPart.getModel()).getElement();
StatusType myStatus=thisObject.getTrackStatus();
EditingDomain editingDomain =
((IGraphicalEditPart)getTargetEditPart(request)).getEditingD omain();

EAttribute feature = YardPackage.eINSTANCE.getTrack_TrackStatus();

if(myStatus.equals(StatusType.OCCUPIED_LITERAL)){
editingDomain.getCommandStack().execute(
SetCommand.create(editingDomain, thisObject, feature ,
(Object)StatusType.FREE_LITERAL));
}
else{
editingDomain.getCommandStack().execute(
SetCommand.create(editingDomain, thisObject, feature ,
(Object)StatusType.OCCUPIED_LITERAL));
}
}
return null;
}
------------------------------------------------------------ ------------
Maybe the problem is in the way I get the editingDomain, as in the topic
said you should get it like:
EditingDomain editingDomain = ( (YardDiagramEditor)
getPart()).getEditingDomain();
but there is no such getPart() function in my YardDiagramEditor class.
Any suggestions??
Thanks a lot!
Re: Cannot modify resource set without a write transaction [message #71957 is a reply to message #71902] Tue, 31 October 2006 12:59 Go to previous messageGo to next message
ciukes is currently offline ciukesFriend
Messages: 19
Registered: July 2009
Junior Member
Noelia Rodriguez wrote:
> Hi!
>
> I followed the example in the topic and changed the code to this:
> ------------------------------------------------------------ ---------------
> ...
> ------------------------------------------------------------ ------------
> Maybe the problem is in the way I get the editingDomain, as in the topic
> said you should get it like:
> EditingDomain editingDomain = ( (YardDiagramEditor)
> getPart()).getEditingDomain();
> but there is no such getPart() function in my YardDiagramEditor class.
> Any suggestions?? Thanks a lot!
>

Change this
------------------------------------------------------------ ------------
> if(myStatus.equals(StatusType.OCCUPIED_LITERAL)){
> editingDomain.getCommandStack().execute(
> SetCommand.create(editingDomain, thisObject, feature ,
> (Object)StatusType.FREE_LITERAL));
> }
> else{
> editingDomain.getCommandStack().execute(
> SetCommand.create(editingDomain, thisObject, feature ,
> (Object)StatusType.OCCUPIED_LITERAL));
> }
------------------------------------------------------------ ------------
to this:
------------------------------------------------------------ ------------
Object newStatus;
if(myStatus.equals(StatusType.OCCUPIED_LITERAL)){
newStatus=StatusType.FREE_LITERAL;
}else{
newStatus=StatusType.OCCUPIED_LITERAL;
}
Command cmd=SetCommand.create(editingDomain, thisObject, feature ,
newStatus);

// for debug purpose
boolean isExecutable=cmd.canExecute();

editingDomain.getCommandStack().execute(newStatus);
------------------------------------------------------------ ------------
and make sure command you've created can execute.

Regards,
Marcin.
Re: Cannot modify resource set without a write transaction [message #71998 is a reply to message #71957] Tue, 31 October 2006 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi again!
I changed the code to the following:
------------------------------------------------------------ ---------------
IGraphicalEditPart editPart = (IGraphicalEditPart)targetEditPart;
Track thisObject = (Track) ((View) editPart.getModel()).getElement();
StatusType myStatus=thisObject.getTrackStatus();
EditingDomain editingDomain =
((IGraphicalEditPart)getTargetEditPart(request)).getEditingD omain();
EAttribute feature = YardPackage.eINSTANCE.getTrack_TrackStatus();
Object newStatus;
if(myStatus.equals(StatusType.OCCUPIED_LITERAL)){
newStatus=StatusType.FREE_LITERAL;
}
else {
newStatus=StatusType.OCCUPIED_LITERAL;
}
org.eclipse.emf.common.command.Command cmd=
SetCommand.create(editingDomain, thisObject, feature , newStatus);
boolean isExecutable=cmd.canExecute();
if(isExecutable){
editingDomain.getCommandStack().execute(cmd);
}
------------------------------------------------------------ ---
and isExecutable is true, but these exceptions are thrown when the command
is executed:
- Unhandled event loop exception
- Cannot activate read/write transaction in read-only transaction context

java.lang.IllegalStateException: Cannot activate read/write transaction in
read-only transaction context
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.acquire(TransactionalEditingDomainImpl.java:498)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.activate(TransactionalEditingDomainImpl.java:436)
at
org.eclipse.emf.transaction.impl.TransactionImpl.start(Trans actionImpl.java:154)
at
org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.cre ateTransaction(WorkspaceCommandStackImpl.java:346)
at
org.eclipse.emf.workspace.EMFCommandOperation.createTransact ion(EMFCommandOperation.java:189)
at
org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:124)
at
org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:509)
at
org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.exe cute(WorkspaceCommandStackImpl.java:144)
at
org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.exe cute(WorkspaceCommandStackImpl.java:180)
at
com.bombardier.train_sim.yard.diagram.edit.policies.ClickedT rackEditPolicy.getOpenCommand(ClickedTrackEditPolicy.java:63 )
at
org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPoli cy.getCommand(OpenEditPolicy.java:58)
at
org.eclipse.gef.editparts.AbstractEditPart.getCommand(Abstra ctEditPart.java:473)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.access$1(GraphicalEditPart.java:1)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt$1.run(GraphicalEditPart.java:414)
at
org.eclipse.emf.transaction.impl.TransactionalEditingDomainI mpl.runExclusive(TransactionalEditingDomainImpl.java:258)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.getCommand(GraphicalEditPart.java:409)
at
org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPa rt.performRequest(GraphicalEditPart.java:964)
at
org.eclipse.gef.tools.SelectEditPartTracker.performOpen(Sele ctEditPartTracker.java:187)
at
org.eclipse.gef.tools.SelectEditPartTracker.handleDoubleClic k(SelectEditPartTracker.java:131)

I really dont know how to solve this :-S Thanks for trying!
Re: Cannot modify resource set without a write transaction [message #72035 is a reply to message #71998] Tue, 31 October 2006 13:50 Go to previous messageGo to next message
ciukes is currently offline ciukesFriend
Messages: 19
Registered: July 2009
Junior Member
> I really dont know how to solve this :-S Thanks for trying!
>
Last chance:

Not so long ago I had problems with executing commands on transactional
stack because I had two different TransactionalEditingDomains. One was
assigned with model and the other was used for command execution. That
broke transactions recorder and lead me to problems. When I checked
carefully I'm sharing same TransactionalEditiongDomain when reading
model and executing command everything started working fine.

Regards,
Marcin.
Re: Cannot modify resource set without a write transaction [message #72054 is a reply to message #72035] Tue, 31 October 2006 14:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi Marcin!

thank you very much for helping me. I just found this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=154998

that explains that I may get the error because I am trying to execute a
write transaction inside getCommand method, and that is a read
environment.

Now I am trying to put my code out of the getCommand, but I dont really
know how to do it if I want it to be executed when the object is
double-clicked.

I will keep on trying... thanks for your time!
Re: Cannot modify resource set without a write transaction [message #72160 is a reply to message #72054] Tue, 31 October 2006 15:01 Go to previous messageGo to next message
Cherie Revells is currently offline Cherie RevellsFriend
Messages: 299
Registered: July 2009
Senior Member
Noelia,

You don't need to execute the command. An editpolicy usually takes a
request and returns the command and the GMF infrastructure will execute
it.

Your command should be an AbstractTransactionalCommand as it is
modifying the model. Take a look at SetPropertyCommand -- you can
probably use this command as is.

Regards,
Cherie

Noelia Rodriguez wrote:
> Hi Marcin!
>
> thank you very much for helping me. I just found this:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=154998
>
> that explains that I may get the error because I am trying to execute a
> write transaction inside getCommand method, and that is a read environment.
> Now I am trying to put my code out of the getCommand, but I dont really
> know how to do it if I want it to be executed when the object is
> double-clicked.
> I will keep on trying... thanks for your time!
>
Re: Cannot modify resource set without a write transaction [message #72514 is a reply to message #72160] Wed, 01 November 2006 09:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi!

I followed your advice and create a new command of type
AbstractTransactionalCommand. The problem now is when trying to return it
the from getOpenCommand()function, because the types does not much.

My created command is:
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTr ansactionalCommand

The expected return value from getOpenCommand is:
org.eclipse.gef.commands.Command

I havent been able to cast my variable to org.eclipse.gef.commands.Command:
...return (org.eclipse.gef.commands.Command)cmd; ->gives compiling errors
...return (org.eclipse.gef.commands.Command)cmd.reduce();-> when executed
throws java.lang.ClassCastException:
org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCom mand

Any idea of how to cast one type to the other or any other solution?
Thanks!!
Re: Cannot modify resource set without a write transaction [message #72680 is a reply to message #72514] Wed, 01 November 2006 14:39 Go to previous messageGo to next message
Cherie Revells is currently offline Cherie RevellsFriend
Messages: 299
Registered: July 2009
Senior Member
Noelia,

You need to wrap an AbstractTransactionalCommand in an ICommandProxy to
return it in an editpolicy. See
org.eclipse.gmf.runtime.diagram.ui.commands.OpenDiagramEditP olicy.getOpenCommand()
for an example.

Regards,
Cherie

Noelia Rodriguez wrote:
> Hi!
>
> I followed your advice and create a new command of type
> AbstractTransactionalCommand. The problem now is when trying to return
> it the from getOpenCommand()function, because the types does not much.
>
> My created command is:
> org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTr ansactionalCommand
>
>
> The expected return value from getOpenCommand is:
> org.eclipse.gef.commands.Command
>
> I havent been able to cast my variable to org.eclipse.gef.commands.Command:
> ..return (org.eclipse.gef.commands.Command)cmd; ->gives compiling errors
> ..return (org.eclipse.gef.commands.Command)cmd.reduce();-> when executed
> throws java.lang.ClassCastException:
> org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCom mand
>
> Any idea of how to cast one type to the other or any other solution?
> Thanks!!
>
Re: Cannot modify resource set without a write transaction [message #72705 is a reply to message #72680] Wed, 01 November 2006 14:55 Go to previous message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Thank you very much! Using the ICommandProxy it works perfect.

Thanks again for your time!
Previous Topic:default but not forced colors of figures (GMF 2.0)
Next Topic:Gmf rcp lite ...resize/move problem
Goto Forum:
  


Current Time: Fri Apr 26 03:48:56 GMT 2024

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

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

Back to the top