Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Model changes triggered by Edit Helper Advice
Model changes triggered by Edit Helper Advice [message #697881] Mon, 18 July 2011 09:23 Go to next message
Greg is currently offline Greg
Messages: 15
Registered: April 2011
Junior Member
Hi,

Inside a bigger GMF project we have to react to changes of the connections.

We are trying to implement an EditHelperAdvice class, which extends AbstractEditHelperAdvice, that reacts to the creation an the deletion of a connection and then changes a label in the target element according to the previous node.

We have created a test environment to focus on this issue. It consists of two nodes (TestSource and TestTarget) and a reference test pointing from the TestSource to the TestTarget. Both nodes are contained in TestCanvas.

Our definition of the advice in the plugin.xml seems to work:

...
   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes" id="element-types">
...
            <metamodel nsURI=".../testproject/1.0"><!--Forum didn't allow http-->
               <adviceBinding
                     class="testproject.extend.advice.TestTargetAdvice"
                     id="TestProject.diagram.TestTargetAdvice"
                     inheritance="all"
                     typeId="TestProject.diagram.TestTarget_2002">
               </adviceBinding>
                              <adviceBinding
                     class="testproject.extend.advice.TestSourceAdvice"
                     id="TestProject.diagram.TestSourceAdvice"
                     inheritance="all"
                     typeId="TestProject.diagram.TestSource_2001">
               </adviceBinding>
            </metamodel>
   </extension>

... 

   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings" id="element-types-bindings">
...
      <binding context="TestProject.diagram.TypeContext">
...
         <advice ref="TestProject.diagram.TestTargetAdvice"></advice>
         <advice ref="TestProject.diagram.TestSourceAdvice"></advice>
      </binding>
   </extension>
...



And the TestTargetAdvice also works and writes "created" into the label:

package testproject.extend.advice;

...

public class TestTargetAdvice extends AbstractEditHelperAdvice {

	@Override
	protected ICommand getAfterCreateRelationshipCommand(
			CreateRelationshipRequest request) {
		if (request.getTarget() != null
				&& request.getTarget() instanceof TestTargetImpl) {

			SetValueCommand newSetCommand = new SetValueCommand(new SetRequest(
					(EObject) request.getTarget(),
					TestprojectPackageImpl.eINSTANCE
							.getTestTarget_TestTargetLabel(), "created"));

			ICommand command = super.getAfterCreateRelationshipCommand(request);

			ICompositeCommand compositeCommand = new CompositeCommand("create");

			if (command != null) {
				compositeCommand.add(command);
			}

			compositeCommand.add(newSetCommand);

			return compositeCommand;
		} else

			return super.getAfterCreateRelationshipCommand(request);
	}
}


But if we try the same for the source the reference disappears but does not get deleted from the model. The reference's name remains in the sources properties. When we close the diagram and open it again, the reference reappears.

package testproject.extend.advice;

...

public class TestSourceAdvice extends AbstractEditHelperAdvice {
	@Override
	protected ICommand getAfterDestroyReferenceCommand(
			DestroyReferenceRequest request) {

		if (request.getReferencedObject() != null
				&& request.getReferencedObject() instanceof TestTargetImpl) {

			SetValueCommand newSetCommand = new SetValueCommand(new SetRequest(
					(EObject) request.getReferencedObject(),
					TestprojectPackageImpl.eINSTANCE
							.getTestTarget_TestTargetLabel(), "deleted"));

			ICommand command = super.getAfterDestroyReferenceCommand(request);

			ICompositeCommand compositeCommand = new CompositeCommand("delete");

			if (command != null) {
				compositeCommand.add(command);
			}

			compositeCommand.add(newSetCommand);

			return compositeCommand;
		} else

			return super.getAfterDestroyReferenceCommand(request);
	}
}


We also tried to execute the command right there but that just caused an exception "Cannot activate read/write transaction in read-only transaction context":


org.eclipse.core.commands.ExecutionException: While executing the operation, an exception occurred
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:519)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:206)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:169)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack.execute(DiagramCommandStack.java:156)
	at testproject.extend.GefCommandHelper.sendCommand(GefCommandHelper.java:150)
	at testproject.extend.advice.TestSourceAdvice.getAfterDestroyReferenceCommand(TestSourceAdvice.java:52)
	at org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice.getAfterEditCommand(AbstractEditHelperAdvice.java:129)
	at org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper.getEditCommand(AbstractEditHelper.java:206)
	at org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper.getEditCommand(AbstractEditHelper.java:137)
	at org.eclipse.gmf.runtime.emf.type.core.SpecializationType.getEditCommand(SpecializationType.java:238)
	at testproject.diagram.edit.policies.TestProjectBaseItemSemanticEditPolicy.getEditHelperCommand(TestProjectBaseItemSemanticEditPolicy.java:136)
	at testproject.diagram.edit.policies.TestProjectBaseItemSemanticEditPolicy.getSemanticCommand(TestProjectBaseItemSemanticEditPolicy.java:101)
	at org.eclipse.gmf.runtime.diagram.ui.editpolicies.SemanticEditPolicy.getCommand(SemanticEditPolicy.java:69)
	at testproject.diagram.edit.policies.TestProjectBaseItemSemanticEditPolicy.getCommand(TestProjectBaseItemSemanticEditPolicy.java:83)
	at org.eclipse.gef.editparts.AbstractEditPart.getCommand(AbstractEditPart.java:501)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.access$0(ConnectionEditPart.java:1)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart$3.run(ConnectionEditPart.java:598)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart.getCommand(ConnectionEditPart.java:593)
	at testproject.diagram.part.DeleteElementAction.getCommand(DeleteElementAction.java:78)
	at org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.getCommand(DiagramAction.java:161)
	at org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.calculateEnabled(DiagramAction.java:124)
	at org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction.refresh(DiagramAction.java:114)
	at org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler.selectionChanged(AbstractActionHandler.java:387)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer.flushSelectionEvents(DiagramGraphicalViewer.java:269)
	at org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer$1.run(DiagramGraphicalViewer.java:247)
	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:4041)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3660)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	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:369)
	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:620)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
Caused by: java.lang.IllegalStateException: Cannot activate read/write transaction in read-only transaction context
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.acquire(TransactionalEditingDomainImpl.java:576)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.activate(TransactionalEditingDomainImpl.java:508)
	at org.eclipse.emf.transaction.impl.TransactionImpl.start(TransactionImpl.java:204)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.startTransaction(TransactionalEditingDomainImpl.java:424)
	at org.eclipse.emf.workspace.AbstractEMFOperation.createTransaction(AbstractEMFOperation.java:617)
	at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:147)
	at org.eclipse.gmf.runtime.common.core.command.CompositeCommand.doExecuteWithResult(CompositeCommand.java:403)
	at org.eclipse.gmf.runtime.common.core.command.AbstractCommand.execute(AbstractCommand.java:135)
	at testproject.extend.GefFromGmfCommand.execute(GefFromGmfCommand.java:48)
	at org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy.doExecuteWithResult(CommandProxy.java:50)
	at org.eclipse.gmf.runtime.common.core.command.AbstractCommand.execute(AbstractCommand.java:135)
	at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:511)
	... 50 more


I hope that someone can help us with this issue since we have been working on it for quite some time. Somehow all the available documentation and tutorials (online, in eclipse and on third-party sites) seem to be outdated and the examples there don't work on our Helios.

[Updated on: Mon, 18 July 2011 11:05]

Report message to a moderator

Re: Model changes triggered by Edit Helper Advice [message #699430 is a reply to message #697881] Thu, 21 July 2011 14:32 Go to previous messageGo to next message
Greg is currently offline Greg
Messages: 15
Registered: April 2011
Junior Member
I managed to get the wanted effect but I don't like what I had to do for it.

I added a DestroyReferenceCommand, which I created from the request sent to this method, to the commands I return in this method. But this should have been the original command which should not have been touched.

Is this an error or do I just miss something?

It seemed as if the model part of the command was blocked since the graphics disappeared but the source node's property stayed the same.

package testproject.extend.advice;

...

public class TestSourceAdvice extends AbstractEditHelperAdvice {
	
	
	
	@Override
	protected ICommand getAfterDestroyReferenceCommand(
			DestroyReferenceRequest request) {

		if (request.getReferencedObject() != null
				&& request.getReferencedObject() instanceof TestTargetImpl) {

			SetValueCommand newSetValueCommand = new SetValueCommand(
					new SetRequest((EObject) request.getReferencedObject(),
							TestprojectPackageImpl.eINSTANCE
							.getTestTarget_TestTargetLabel(), "deleted"));
			
			DestroyReferenceCommand newDestroyCommand = new DestroyReferenceCommand(request);

			ICommand command = super.getAfterDestroyReferenceCommand(request);

			ICompositeCommand compositeCommand = new CompositeCommand("delete");

			if (command != null) {
				compositeCommand.add(command);

			}

			compositeCommand.add(newSetValueCommand);
			compositeCommand.add(newDestroyCommand);

			return compositeCommand;
		} else

			return super.getAfterDestroyReferenceCommand(request);
	}
}
Re: Model changes triggered by Edit Helper Advice [message #701166 is a reply to message #699430] Sun, 24 July 2011 18:48 Go to previous messageGo to next message
Aurelien Pupier is currently offline Aurelien Pupier
Messages: 561
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

do you mean that it might be a bug in GMF? If so, please open a bug and explain your solution (and you can also provide a patch Smile)

Regards,


Aurélien Pupier - Bonitasoft S.A.
My company Eclipse-related blog
Re: Model changes triggered by Edit Helper Advice [message #701482 is a reply to message #701166] Mon, 25 July 2011 07:10 Go to previous message
Greg is currently offline Greg
Messages: 15
Registered: April 2011
Junior Member
Thank you for your response.

I first wanted to ask others (after not finding anything anywhere) before calling it a bug. The whole framework still is a huge mystery to me and good documentation seems rare.

I have just reported it as a bug here:
bugs.eclipse.org/bugs/show_bug.cgi?id=352968
Previous Topic:FlyOutPalette: how to change the background color?
Next Topic:Troubles while setting the GMF editor inside a MultiPageEditor
Goto Forum:
  


Current Time: Sun Sep 21 18:21:12 GMT 2014

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

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