carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.templates/xpt/diagram/editpolicies/linkCommands.xpt
author cawthron
Fri, 04 Dec 2009 12:29:56 -0600
changeset 779 4870ed7d9d38
parent 422 033392511bf7
permissions -rw-r--r--
remove .branch.txt

/*
 * Copyright (c) 2007 Borland Software Corporation
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Alexander Shatalin (Borland) - initial API and implementation
 *    Dmitry Stadnik (Borland) - creation logic was moved in commands
 */

«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«EXTENSION xpt::diagram::editpolicies::Utils»
«EXTENSION xpt::GenModelUtils»

«REM»
 * Start  		start of link creation. 
 *				User click to this editpart and start dragging with link tool.
 * Complete 	end of the command
 *				User points to this editpart as a link target and release mouse button.
 *
 * Outgoing 	the node is link source
 *				This element could be a source for this type of link.
 * Incoming		the node is link destination
 *				This element could be a target for this type of link.
 *
 * Parameters:
 *
 * 	diagram 	GenDiagram used to collect all defined links
 *
 *	this		Instance of TypeModelFacet for the element link could be creates to/from.
 *				This could be TypeModelFacet or TypeLinkModelFacet in case of links to links.
 *
«ENDREM»

«DEFINE linkCommands(gmfgen::GenDiagram diagram) FOR gmfgen::TypeModelFacet-»
	«IF getAllPotentialLinks(diagram).size() > 0-»
		«EXPAND createLinkCommands(diagram)-»
	«ENDIF-»
	«IF getReroutableTypeLinks(diagram).size() > 0-»
		«EXPAND reorientTypeLinkCommands(diagram)-»
	«ENDIF-»
	«IF getReroutableRefLinks(diagram).size() > 0-»
		«EXPAND reorientRefLinkCommands(diagram)-»
	«ENDIF-»
«ENDDEFINE»

«DEFINE createLinkCommands(gmfgen::GenDiagram diagram) FOR gmfgen::TypeModelFacet-»

«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.commands.Command getCreateRelationshipCommand(
		org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest req) {
	org.eclipse.gef.commands.Command command = req.getTarget() == null ?
			getStartCreateRelationshipCommand(req) : getCompleteCreateRelationshipCommand(req);
	return command != null ? command : super.getCreateRelationshipCommand(req);
}

«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.commands.Command getStartCreateRelationshipCommand(
		org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest req) {
	«EXPAND startLinkCommands(this) FOREACH getAllPotentialLinks(diagram)-»
	return null;
}

«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.commands.Command getCompleteCreateRelationshipCommand(
		org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest req) {
	«EXPAND completeLinkCommands(this) FOREACH getAllPotentialLinks(diagram)-»
	return null;
}
«ENDDEFINE»

«DEFINE startLinkCommands(gmfgen::TypeModelFacet typeModelFacet) FOR gmfgen::GenLink-»
if («getDiagram().getElementTypesQualifiedClassName()».«getUniqueIdentifier()» == req.getElementType()) {
	«IF createStartLinkCommand(typeModelFacet)-»
	return getGEFWrapper(new «getCreateCommandQualifiedClassName()»(req,
		«IF createStartIncomingLinkCommand(typeModelFacet)-»
			req.getTarget(), req.getSource()
		«ELSE-»
			req.getSource(), req.getTarget()
		«ENDIF-»
	));
	«ELSE-»
	return null;
	«ENDIF-»
}
«ENDDEFINE»

«DEFINE completeLinkCommands(gmfgen::TypeModelFacet typeModelFacet) FOR gmfgen::GenLink-»
if («getDiagram().getElementTypesQualifiedClassName()».«getUniqueIdentifier()» == req.getElementType()) {
	«IF createCompleteLinkCommand(typeModelFacet)-»
	return getGEFWrapper(new «getCreateCommandQualifiedClassName()»(req,
		«IF createCompleteOutgoingLinkCommand(typeModelFacet)-»
			req.getTarget(), req.getSource()
		«ELSE-»
			req.getSource(), req.getTarget()
		«ENDIF-»
	));
	«ELSE-»
	return null;
	«ENDIF-»
}
«ENDDEFINE»

«DEFINE reorientTypeLinkCommands(gmfgen::GenDiagram diagram) FOR gmfgen::TypeModelFacet-»

«EXPAND xpt::Common::generatedMemberComment(
	"Returns command to reorient EClass based link. New link target or source\n" +
	"should be the domain model element associated with this node.\n"

protected org.eclipse.gef.commands.Command getReorientRelationshipCommand(
		org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest req) {
	switch (getVisualID(req)) {
	«EXPAND reorientLinkCommand FOREACH getReroutableTypeLinks(diagram)-»
	}
	return super.getReorientRelationshipCommand(req);
}
«ENDDEFINE»

«DEFINE reorientRefLinkCommands(gmfgen::GenDiagram diagram) FOR gmfgen::TypeModelFacet-»

«EXPAND xpt::Common::generatedMemberComment(
	"Returns command to reorient EReference based link. New link target or source\n" +
	"should be the domain model element associated with this node.\n"

protected org.eclipse.gef.commands.Command getReorientReferenceRelationshipCommand(
		org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest req) {
	switch (getVisualID(req)) {
	«EXPAND reorientLinkCommand FOREACH getReroutableRefLinks(diagram)-»
	}
	return super.getReorientReferenceRelationshipCommand(req);
}
«ENDDEFINE»

«DEFINE reorientLinkCommand FOR gmfgen::GenLink-»
«EXPAND xpt::Common::caseVisualID»
	return getGEFWrapper(new «getReorientCommandQualifiedClassName()»(req));
«ENDDEFINE»