[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] IllegalStateException - how to get/use editing domain?

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.assertWriting(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.getEditingDomain(editingdomain); // always returns null
	if (domain == null) {
		// neither of the following ways work

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

		//domain = myEditPart.getEditingDomain();

		// as described in http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/index.jsp?topic=/org.eclipse.emf.transaction.doc/tutorials/transactionTutorial.html
//		domain = DiagramEditingDomainFactory.getInstance().createEditingDomain();
//		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)));
}