Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Delete Connection of a Node Programmatically
Delete Connection of a Node Programmatically [message #1006664] Fri, 01 February 2013 11:13 Go to next message
Daniel König is currently offline Daniel König
Messages: 24
Registered: November 2012
Junior Member
Hello!

I have a structure like this:
Node A ---(1)---> Node B ---(2)---> Node C

If I delete connection (1) I would like to also delete connection (2) between node B and C. The connections are of a different type.

Does anybody know a solution how to access and delete connection (2)?
Thank you very much!



Here is the remove of Connection (1) (after the confirmation of a dialog):
protected Command getDestroyElementCommand(DestroyElementRequest req) {
	DestroyElementCommand cmd = new DestroyElementCommand(req) {
		@Override
		protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
			Shell shell = new Shell(SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL);
			boolean result = MessageDialog.openQuestion(shell, Messages.StateTransitionDeleteQuestionTitle, Messages.StateTransitionDeleteQuestion);

			if (result) {
				// OK Button selected
				return super.doExecuteWithResult(monitor, info);
			} else {
				// Cancel Button selected
				return CommandResult.newCancelledCommandResult();
			}
		}
	};
	return getGEFWrapper(cmd);
}
Re: Delete Connection of a Node Programmatically [message #1007104 is a reply to message #1006664] Mon, 04 February 2013 13:29 Go to previous messageGo to next message
Daniel König is currently offline Daniel König
Messages: 24
Registered: November 2012
Junior Member
I found a workaround, although I don't think it's the correct way to solve my problem. However, I don't have any other solution until now...


In the EditHelper-Classes I can implement the getDestroyDependentsCommand method, where my "dependents" can be deleted:

/**
 * @generated
 */
public class StateTransitionContinuousEditHelper extends MachineBaseEditHelper {
	
	@Override
	protected ICommand getDestroyDependentsCommand(DestroyDependentsRequest req) {		
		if (req.getElementToDestroy() instanceof StateTransitionContinuous) {
			StateTransitionContinuous stc = (StateTransitionContinuous) req.getElementToDestroy();
			if (stc.getTarget() != null && stc.getTarget().getTriggerIn() != null) {
				return req.getDestroyDependentCommand(stc.getTarget().getTriggerIn());
			}
			
		}		
		return super.getDestroyDependentsCommand(req);
	}
}



But now the problem:
This method seems to be never called. This is because the PACKAGE_BaseEditHelper extends GeneratedEditHelperBase in which the getDestroyElementCommand method from AbstractEditHelper is overridden and returns null. (I don't know why this method is overridden... Sad) In that method getDestroyDependentsCommand would have been invoked.

@Override
protected ICommand getDestroyElementCommand(DestroyElementRequest req) {
	return null;
}



If I change the superclass of my PACKAGE_BaseEditHelper from GeneratedEditHelperBase to AbstractEditHelper the getDestroyDependentsCommand method will be called and the connection I wanted to remove is destroyed.

public class MachineBaseEditHelper extends AbstractEditHelper /*GeneratedEditHelperBase*/ {
}



This "solution" works for now, but I don't know about any side-effects of it.
I couldn't find any information of the usage or reason for GeneratedEditHelperBase.

If anybody has a better / clean solution please answer, because I would be really happy about it! Smile

I just have a bad feeling about changing the superclass of my PACKAGE_BaseEditHelper.
Re: Delete Connection of a Node Programmatically [message #1014460 is a reply to message #1007104] Mon, 25 February 2013 21:45 Go to previous message
Thomas Beyer is currently offline Thomas Beyer
Messages: 55
Registered: February 2013
Member
Hi Daniel,

Check the generated policies package.
There should be a class named StateTransitionContinuousSemanticEditPolicy (just a guess based on the code above).
There you will find
/**
	 * @generated
	 */
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
		return getGEFWrapper(new DestroyElementCommand(req));
	}


You could override this method by traversing to connection (2) via Node (B) and chain another Command with the corresponding DestroyElementRequest for connection (2) to the Command provided by this method.
This way, you would delete connection (1) and (2), but preserve the nodes.

Regards Thomas

[Updated on: Mon, 25 February 2013 21:45]

Report message to a moderator

Previous Topic:Where is my editing domain set to null
Next Topic:Updating existing diagrams when model changes
Goto Forum:
  


Current Time: Sat Sep 20 22:07:21 GMT 2014

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

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