IllegalStateException - how to get/use editing domain? [message #211847] |
Mon, 24 November 2008 02:32  |
Eclipse User |
|
|
|
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 #211925 is a reply to message #211893] |
Mon, 24 November 2008 10:30  |
Eclipse User |
|
|
|
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
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03704 seconds