Cannot modify resource set without a write transaction [message #71849] |
Tue, 31 October 2006 04:52  |
Eclipse User |
|
|
|
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 #71957 is a reply to message #71902] |
Tue, 31 October 2006 07:59   |
Eclipse User |
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05887 seconds