Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » IllegalStateException - how to get/use editing domain?
IllegalStateException - how to get/use editing domain? [message #211847] Mon, 24 November 2008 07:32 Go to next message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Hi all,

In an action which is placed in the toolbar of my GMF editor, I would like to change an attribute in my model.
If I change it right away, I get an java.lang.IllegalStateException: Cannot modify resource set without a write transaction
at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:338)

I tried to do so using the editingdomain, but I got the same exception.
What is the correct way of changing the model from within such a toolbar action (IWorkbenchWindowActionDelegate) for a GMF editor?
Please see my code below.
Any help is appreciated

Best regards
Patrick


public void run(IAction action) {

// myEditPart is set in selectionChanged()
Object model = ((Diagram) myEditPart.getModel()).getElement();
Mymodel mymodel = (Mymodel) model;

String editingdomain = "mymodel.diagram.EditingDomain";
TransactionalEditingDomain domain =
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomai n(editingdomain); // always returns null
if (domain == null) {
// neither of the following ways work

IEditorPart editor = MymodelDiagramEditorPlugin.getInstance().getWorkbench().getA ctiveWorkbenchWindow().getActivePage().getActiveEditor();
domain = ((MymodelEditPart)editor).getEditingDomain();

//domain = myEditPart.getEditingDomain();

// as described in http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/inde x.jsp?topic=/org.eclipse.emf.transaction.doc/tutorials/trans actionTutorial.html
// domain = DiagramEditingDomainFactory.getInstance().createEditingDomai n();
// domain.setID(editingdomain);
}

// illegalstateexception! this obviously needs to be executed in a command
//mymodel.setImportance(true);

// but this throws such an exception as well!
domain.getCommandStack().execute(new SetCommand(domain, mymodel,
MymodelPackage.eINSTANCE.getMymodel_Importance(), new Boolean(true)));
}
Re: IllegalStateException - how to get/use editing domain? [message #211893 is a reply to message #211847] Mon, 24 November 2008 12:21 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Patrick,

Try to create a subclass of AbstractTransactionalCommand and execute this
command using folowing code:

OperationHistoryFactory.getOperationHistory().execute(<command >, new NullProgressMonitor(),
null);

-----------------
Alex Shatalin
Re: IllegalStateException - how to get/use editing domain? [message #211925 is a reply to message #211893] Mon, 24 November 2008 15:30 Go to previous message
Patrick Konemann is currently offline Patrick KonemannFriend
Messages: 116
Registered: July 2009
Senior Member
Thanks a lot Alex, that did the trick :-)


Alex Shatalin wrote:
> Hello Patrick,
>
> Try to create a subclass of AbstractTransactionalCommand and execute
> this command using folowing code:
>
> OperationHistoryFactory.getOperationHistory().execute(<command >, new
> NullProgressMonitor(), null);
>
> -----------------
> Alex Shatalin
>
>
Previous Topic:Diagram canvas without horizontal scrolling
Next Topic:Is there a problem with gmf-sdk-2.2.0M2 ??
Goto Forum:
  


Current Time: Thu Sep 19 23:20:29 GMT 2024

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

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

Back to the top