# Error: Cannot modify resource set without a write transaction



## Tomas (19. Okt 2009)

i have got a problem:

i want to get my values and set them in my model (im using gmf)


```
@Override
	protected void refreshBounds() {

		super.refreshBounds();
		EObject element = view.getElement();
		width = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getSize_Width());
		height = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getSize_Height());
		x = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_X());
		
		y = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_Y());
		
		System.out.println("hallo"+x+" "+y+" "+width+" "+height);
		
//-----------------HERE STARTS THE PROBLEM-----------------
                ((EllipseImpl) element).setX(this.x);
		((EllipseImpl) element).setY(this.y);
		((EllipseImpl) element).setRx(this.width);
		((EllipseImpl) element).setRy(this.height);
		
//-------------------------------------------------------------
		
	}
```

How can i resolve this as a transaction (or what is needed)???? I just want to set this 4 values in the model. 

my model:

Diagram
-Shapes        (value x, y)
  --Ellipse      --(+value rx, ry)
  --Rectangle --(+value width, height)
  --...
  --...
-Line            --(doesnt matter at the moment)

the main purpose is: to show this values in the property page, to change the Location/Size


```
java.lang.IllegalStateException: Cannot modify resource set without a write transaction
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:280)
	at element.impl.ShapesImpl.setX(ShapesImpl.java:111)
	at element.diagram.edit.parts.EllipseEditPart.refreshBounds(EllipseEditPart.java:85)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart.refreshVisuals(ShapeEditPart.java:186)
	at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:676)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:571)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.access$3(GraphicalEditPart.java:1)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart$3.run(GraphicalEditPart.java:855)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:313)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.refresh(GraphicalEditPart.java:845)
	at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:235)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:219)
	at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:198)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.addChild(GraphicalEditPart.java:1313)
	at org.eclipse.gef.editparts.AbstractEditPart.refreshChildren(AbstractEditPart.java:727)
	at org.eclipse.gef.editparts.AbstractEditPart.refresh(AbstractEditPart.java:677)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.refresh(AbstractGraphicalEditPart.java:571)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.access$3(GraphicalEditPart.java:1)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart$3.run(GraphicalEditPart.java:855)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:313)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart.refresh(GraphicalEditPart.java:845)
	at org.eclipse.gef.editparts.AbstractEditPart.addNotify(AbstractEditPart.java:235)
	at org.eclipse.gef.editparts.AbstractGraphicalEditPart.addNotify(AbstractGraphicalEditPart.java:219)
	at org.eclipse.gef.editparts.AbstractEditPart.addChild(AbstractEditPart.java:198)
	at org.eclipse.gef.editparts.SimpleRootEditPart.setContents(SimpleRootEditPart.java:101)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:601)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer.setContents(DiagramGraphicalViewer.java:378)
	at org.eclipse.gef.ui.parts.AbstractEditPartViewer.setContents(AbstractEditPartViewer.java:610)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.initializeGraphicalViewerContents(DiagramEditor.java:870)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.initializeGraphicalViewer(DiagramEditor.java:863)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette.initializeGraphicalViewer(DiagramEditorWithFlyOutPalette.java:116)
	at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.initializeGraphicalViewer(DiagramDocumentEditor.java:175)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.createGraphicalViewer(DiagramEditor.java:807)
	at org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:163)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.createPartControl(DiagramEditor.java:1555)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette.createPartControl(DiagramEditorWithFlyOutPalette.java:328)
	at org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.createPartControl(DiagramDocumentEditor.java:1510)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:662)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:462)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
	at org.eclipse.ui.internal.EditorAreaHelper.setVisibleEditor(EditorAreaHelper.java:271)
	at org.eclipse.ui.internal.EditorManager.setVisibleEditor(EditorManager.java:1417)
	at org.eclipse.ui.internal.EditorManager$5.runWithException(EditorManager.java:942)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3476)
	at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:803)
	at org.eclipse.ui.internal.Workbench$28.runWithException(Workbench.java:1384)
	at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4312)
	at org.eclipse.ui.internal.StartupThreading.runWithoutExceptions(StartupThreading.java:94)
	at org.eclipse.ui.internal.Workbench.init(Workbench.java:1379)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2335)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at element.diagram.application.ElementApplication.start(ElementApplication.java:19)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
```


----------



## Wildcard (19. Okt 2009)

You need to set the values with Commands and retrieve the TransactionEditingDomain from GMF (this is used to keep the Resources in sync).


----------



## Tomas (20. Okt 2009)

how can it be done. are there some examples or tuts? is it possible to explain it in a short way step-by-step??

one Solution, is it good?


```
@Override
	protected void refreshBounds() {
		System.out.println(this.primaryShape.getBounds());
		super.refreshBounds();

		final EObject element = view.getElement();

		rx = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getSize_Width());
		ry = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getSize_Height());
		x = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_X());

		y = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_Y());

		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) this)
				.getEditingDomain();

		SetRequest setRequestX = new SetRequest(editingDomain, element,
				ElementPackage.eINSTANCE.getShapes_X(), x);
		setRequestX.setParameter("oldValue", ((Ellipse) element).getX());
		
		SetRequest setRequestY = new SetRequest(editingDomain, element,
				ElementPackage.eINSTANCE.getShapes_Y(), y);
		setRequestY.setParameter("oldValue", ((Ellipse) element).getY());
		
		SetRequest setRequestRx = new SetRequest(editingDomain, element,
				ElementPackage.eINSTANCE.getEllipse_Rx(), rx);
		setRequestRx.setParameter("oldValue", ((Ellipse) element).getRx());
		
		SetRequest setRequestRy = new SetRequest(editingDomain, element,
				ElementPackage.eINSTANCE.getEllipse_Ry(), ry);
		setRequestRy.setParameter("oldValue", ((Ellipse) element).getRy());

		EditPart viewPart = this;
		SetValueCommand operation = null;
		CommandStack stack = viewPart.getViewer().getEditDomain()
				.getCommandStack();
		
		
		operation = setMultipleValueCommand(setRequestX, element, ElementPackage.eINSTANCE.getShapes_X());
		stack.execute(new ICommandProxy(operation));
		operation = setMultipleValueCommand(setRequestY, element, ElementPackage.eINSTANCE.getShapes_X());
		stack.execute(new ICommandProxy(operation));
		operation = setMultipleValueCommand(setRequestRx, element, ElementPackage.eINSTANCE.getShapes_X());
		stack.execute(new ICommandProxy(operation));
		operation = setMultipleValueCommand(setRequestRy, element, ElementPackage.eINSTANCE.getShapes_X());
		stack.execute(new ICommandProxy(operation));
		

		this.primaryShape.setBounds(new Rectangle(x, y, rx, ry));
	}

	private SetValueCommand setMultipleValueCommand(SetRequest request, final EObject element, final EAttribute eAttribute) {
		SetValueCommand operation = new SetValueCommand(request) {
			@Override
			protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				element.eSet(eAttribute, this
						.getRequest().getParameter("oldValue"));
				return Status.OK_STATUS;
			}

			@Override
			public boolean canUndo() {
				return true;
			}

			@Override
			protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				element.eSet(eAttribute,//NotationPackage.eINSTANCE.getLocation_X(),
						((SetRequest) this.getRequest()).getValue());
				return Status.OK_STATUS;
			}

			@Override
			public boolean canRedo() {
				return true;
			}
		};
		return operation;
	}
```

it worked for me fine, it keeps my location properties up to date. but now how can i set my values + figures via the propertypage? (fe: Type in PropertyValue x = 100; Shapes x position = 100), is there a simple way to get it?


----------



## Wildcard (20. Okt 2009)

I'm not sure what exactly you're having problems with, so here some general things on how to work with these commands:
GMF Tips - Eclipsepedia


----------



## Tomas (21. Okt 2009)

also da es doch ein deutschsprachiges forum ist, verwende ich mal deutsch^^

also ich habe Elemente, diese Elemente besitzen Integer X, Y, width, height! 
Wenn man das Element verschiebt, sollen sich die Werte korrekt aktualisieren. (Ist schon gemacht, siehe Code)
Nun will ich es auch umgekehrt haben. Wenn man in der Property Page was ändert, soll sich auch die Position ändern. 

Habe ich da schon von Anfang an einen Fehler gemacht, da ich mir keine spezielle PropertyPage gebaut habe? Ich nehme die Werte direkt von meinem ("ModelElement"). 

Das Problem ist


```
/**
 * @generated
 */
public class ElementPropertySection extends AdvancedPropertySection implements
		IPropertySourceProvider {

	/**
	 * @generated
	 */
	public IPropertySource getPropertySource(Object object) { //<- object ist vom Typ INTEGER
		if (object instanceof IPropertySource) {
			return (IPropertySource) object;
		}
		AdapterFactory af = getAdapterFactory(object);
		if (af != null) {
			IItemPropertySource ips = (IItemPropertySource) af.adapt(object,
					IItemPropertySource.class); //<- ips ist null wenn ich einen wert ändere
			if (ips != null) {
				return new PropertySource(object, ips);
			}
		}
		if (object instanceof IAdaptable) {
			return (IPropertySource) ((IAdaptable) object)
					.getAdapter(IPropertySource.class);
		}
		return null;
	}
[/Java]


Hat da wer ne ahnung wie man sowas am besten realisiert?

Wie kann ich diese Attribute am besten in einer Property Page anzeigen und auch ändern?

Danke
```


----------



## Tomas (22. Okt 2009)

Hab jetzt eine Funktionierende Lösung:

Quelle: GMF Tips - Eclipsepedia

1. Automatisches nachsetzen der Werte wenn man sie mit der Maus verschiebt, vergrößert (ich mach es jetzt mit x,y als beispiel(falls es wen interessiert^^))

fürs aktuallisieren

XXXEditPart


```
@Override
	public void refreshBounds() {
		refreshCoordinates(); <---added
		super.refreshBounds();
		
	}
```


Hier hohlt man sich die verschobenen Coordinaten und setzt sie zum Model(aktuallisierung fertig)

[Java]
private void refreshCoordinates() {
		EObject element = view.getElement();// <-ModelObject


		Integer x = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_X());

		Integer y = (Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
				.getLocation_Y());

		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) this)
				.getEditingDomain();


		SetRequest setRequestX = new SetRequest(editingDomain, element,
				MypropertiesPackage.eINSTANCE.getElement_X(), x);
		setRequestX.setParameter("oldValue", ((Element) element).getX());

		SetRequest setRequestY = new SetRequest(editingDomain, element,
				MypropertiesPackage.eINSTANCE.getElement_Y(), y);
		setRequestY.setParameter("oldValue", ((Element) element).getY());

		SetValueCommand operation = null;

		CommandStack stack = viewPart.getViewer().getEditDomain()
				.getCommandStack();

		operation = setMultipleValueCommand(setRequestX, element,
				MypropertiesPackage.eINSTANCE.getElement_X());
		stack.execute(new ICommandProxy(operation));

		operation = setMultipleValueCommand(setRequestY, element,
				MypropertiesPackage.eINSTANCE.getElement_Y());
		stack.execute(new ICommandProxy(operation));
	}

	private SetValueCommand setMultipleValueCommand(SetRequest request,
			final EObject element, final EAttribute eAttribute) {

		SetValueCommand operation = new SetValueCommand(request) {
			@Override
			protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				element.eSet(eAttribute, this.getRequest().getParameter(
						"notValue"));
				return Status.OK_STATUS;
			}

			@Override
			public boolean canUndo() {
				return true;
			}

			@Override
			protected IStatus doRedo(IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				element.eSet(eAttribute,// NotationPackage.eINSTANCE.getLocation_X(),
						((SetRequest) this.getRequest()).getValue());
				return Status.OK_STATUS;
			}

			@Override
			public boolean canRedo() {
				return true;
			}
		};
		return operation;
	}
[/Java]

Nun das Setzen der Position, wenn man einen Wert in die PropertyPage, label oder je nachdem, eingibt.

[Java]
@Override
	protected void handleNotificationEvent(Notification notification) {
		if (notification.getNotifier() instanceof ElementImpl) {
			getPrimaryShape().updateFace(true); <-Figure Updaten
		}
		super.handleNotificationEvent(notification);
	}
[/Java]

XXXFigure
[Java]
private void updateFace(boolean refresh) {
			Element element = (Element) ((Node) ElementEditPart.this.getModel())
					.getElement();

			x = element.getX();
			y = element.getY();

			// update tooltip
			if (element.getX() != null && element.getY() != null) {
				int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
						.getSize_Width())).intValue();
				int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE
						.getSize_Height())).intValue();
				size = new Dimension(width, height);
				this.setSize(size);
				loc = new Point(x, y);
				this.setLocation(loc);
				if (refresh) {
					repaint();
					refreshShape();
				}
			}
		}
[/Java]

und updateFace() im Konstruktor der Figur aufrufen.


----------

