Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Sirius / EMF : How to edit model elements programmatically ?
Sirius / EMF : How to edit model elements programmatically ? [message #1697651] Fri, 05 June 2015 16:11
Yassine BEN ATITALLAH is currently offline Yassine BEN ATITALLAHFriend
Messages: 3
Registered: June 2013
Junior Member
Hello,

I don't understand well : how to edit elements of the model pragmatically ?
I want to set feature "devicename" of "SystemMode" object via plugin.
When I test without "TransactionalEditingDomain" described by the example below :

public void SetDevice(Session s){
XMIResourceImpl xmiressourceImpl = (XMIResourceImpl) s.getSemanticResources().iterator().next();
final SystemModeImpl var = (SystemModeImpl) xmiressourceImpl.getContents().get(0);

		var.setDevicename("SystemModeTest");
}

I get :
!ENTRY org.eclipse.emf.transaction 4 41 2015-06-05 17:57:37.136
!MESSAGE Read-only transaction rolled back
!SUBENTRY 1 org.eclipse.emf.transaction 4 40 2015-06-05 17:57:37.136
!MESSAGE Transaction aborted due to concurrent write

When I test with "TransactionalEditingDomain" described by the example below :
public void SetDevice(Session s){
XMIResourceImpl xmiressourceImpl = (XMIResourceImpl) s.getSemanticResources().iterator().next();
		final SystemModeImpl var = (SystemModeImpl) xmiressourceImpl.getContents().get(0);
		
		TransactionalEditingDomain ted = s.getTransactionalEditingDomain();
		CommandStack stack = ted.getCommandStack();

		try {
		RecordingCommand cmd = new RecordingCommand(ted) {

			@Override
			protected void doExecute() {
				// TODO Auto-generated method stub
				var.setDevicename("SystemModeTest");
				
			}
		};
		
		stack.execute(cmd);
		}
		catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
}


I get :
!STACK 0
java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:576)
....


Thanks,
Yassine.

[Updated on: Mon, 08 June 2015 14:42]

Report message to a moderator

Previous Topic:Dynamic entity creation Sirius
Next Topic:NullPointerException when reopen Sirius Diagram
Goto Forum:
  


Current Time: Tue Jan 19 06:44:50 GMT 2021

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

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

Back to the top