Cannot modify resource set without a write transaction [message #71849] |
Tue, 31 October 2006 09: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 #71902 is a reply to message #71883] |
Tue, 31 October 2006 12:21 |
Eclipse User |
|
|
|
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 |
ciukes 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 |
Eclipse User |
|
|
|
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 #72514 is a reply to message #72160] |
Wed, 01 November 2006 09:49 |
Eclipse User |
|
|
|
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!!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04333 seconds