carbidecpp22devenv/plugins/org.eclipse.gmf.templates.legacy_1.0.0.v20090614-0839/codegen.lite.templates/xpt/diagram/policies/ComponentEditPolicy.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:
 *    bblajer (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»
«EXTENSION xpt::GenModelUtils»
«EXTENSION xpt::diagram::policies::i18n»
«EXTENSION xpt::diagram::policies::ClassNames»
«EXTENSION xpt::diagram::policies::ComponentEditPolicy»
«EXTENSION xpt::diagram::LinkFinder»

«DEFINE ComponentEditPolicy FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::copyright FOR getDiagram().editorGen»
package «getDiagram().editPoliciesPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» «EXPAND supertypes» {
	«EXPAND createDeleteCommand-»
	«EXPAND getDeleteViewCommand-»
	«EXPAND canDeleteView-»
«IF needsGetGraphicalEditPart()-»
	«EXPAND getGraphicalEditPart-»
«ENDIF-»
	«EXPAND domainModelRemoveCommand-»
	«EXPAND getDiagramElement-»
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE domainModelRemoveCommand FOR GenCommonBase»«ERROR "Unexpected type!"»«ENDDEFINE»

«DEFINE domainModelRemoveCommand FOR GenNode-»
«EXPAND xpt::commands::domainModelRemoveCommand::domainModelRemoveCommand("getDiagramNode()")-»
«ENDDEFINE»

«DEFINE domainModelRemoveCommand FOR GenLink-»
«EXPAND xpt::commands::domainModelRemoveCommand::domainModelRemoveCommand("getDiagramEdge()")-»
«ENDDEFINE»

«DEFINE getDiagramElement FOR GenCommonBase»«ERROR "Unexpected type!"»«ENDDEFINE»

«DEFINE getDiagramElement FOR GenNode-»
«EXPAND getDiagramNode-»
«ENDDEFINE»

«DEFINE getDiagramElement FOR GenLink-»
«EXPAND getDiagramEdge-»
«ENDDEFINE»

«DEFINE className FOR gmfgen::GenCommonBase»«getComponentEditPolicyClassName()»«ENDDEFINE»
«DEFINE qualifiedClassName FOR gmfgen::GenCommonBase»«getDiagram().editPoliciesPackageName».«EXPAND className»«ENDDEFINE»

«DEFINE supertypes FOR gmfgen::GenCommonBase»extends org.eclipse.gmf.runtime.lite.edit.policies.ComponentEditPolicyEx«ENDDEFINE»

«DEFINE createDeleteCommand FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.commands.Command createDeleteCommand(org.eclipse.gef.requests.GroupRequest deleteRequest) {
	org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(«EXPAND getDiagramElementMethodName»().getDiagram().getElement());
«LET incomingTypeLinks() AS incomingTypeLinks-»
«LET outgoingNonPhantomLinks() AS outgoingLinks-»
«IF incomingTypeLinks.size() > 0 || outgoingLinks.size() > 0-»
	org.eclipse.gmf.runtime.lite.commands.CompositeWrappingCommand result = new org.eclipse.gmf.runtime.lite.commands.CompositeWrappingCommand(editingDomain, «EXPAND xpt::Externalizer::accessorCall(getDiagram().i18nKeyForDeleteModelElementLabel()) FOR getDiagram().editorGen»);
«ENDIF-»
	«EXPAND deleteIncomingLinks(incomingTypeLinks, true)-»
	«EXPAND deleteOutgoingLinks(outgoingLinks, true)-»
	«EXPAND createDeleteCommandPrim(true)-»
«IF incomingTypeLinks.size() > 0 || outgoingLinks.size() > 0-»
	result.add(cc);
	return result;
«ELSE-»
	return new org.eclipse.gmf.runtime.lite.commands.WrappingCommand(editingDomain, cc);
«ENDIF-»
«ENDLET-»
«ENDLET-»
}
«ENDDEFINE»

«DEFINE deleteIncomingLinks(Collection[gmfgen::GenLink] incomingLinks, boolean deleteFromModel) FOR gmfgen::GenCommonBase-»
«IF incomingLinks.size() > 0-»
	for(java.util.Iterator it = getGraphicalEditPart().getTargetConnections().iterator(); it.hasNext(); ) {
		org.eclipse.gef.EditPart nextEditPart = (org.eclipse.gef.EditPart) it.next();
		org.eclipse.gmf.runtime.notation.Edge nextEdge = (org.eclipse.gmf.runtime.notation.Edge) nextEditPart.getModel();
		int visualID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(nextEdge);
		switch (visualID) {
«FOREACH incomingLinks AS nextLink-»
		case «nextLink.getEditPartQualifiedClassName()».VISUAL_ID:
«ENDFOREACH-»
			«EXPAND deleteDependentLinks(deleteFromModel)-»
		}
	}
«ENDIF-»
«ENDDEFINE»

«DEFINE deleteOutgoingLinks(Collection[gmfgen::GenLink] outgoingLinks, boolean deleteFromModel) FOR gmfgen::GenCommonBase-»
«IF outgoingLinks.size() > 0-»
	for(java.util.Iterator it = getGraphicalEditPart().getSourceConnections().iterator(); it.hasNext(); ) {
		org.eclipse.gef.EditPart nextEditPart = (org.eclipse.gef.EditPart) it.next();
		org.eclipse.gmf.runtime.notation.Edge nextEdge = (org.eclipse.gmf.runtime.notation.Edge) nextEditPart.getModel();
		int visualID = «getDiagram().getVisualIDRegistryQualifiedClassName()».getVisualID(nextEdge);
		switch (visualID) {
«FOREACH outgoingLinks AS nextLink-»
		case «nextLink.getEditPartQualifiedClassName()».VISUAL_ID:
«ENDFOREACH-»
			«EXPAND deleteDependentLinks(deleteFromModel)-»
		}
	}
«ENDIF-»
«ENDDEFINE»

«DEFINE deleteDependentLinks(boolean deleteFromModel) FOR gmfgen::GenCommonBase-»
{
	org.eclipse.gef.requests.GroupRequest deleteLinkRequest = new org.eclipse.gef.requests.GroupRequest(«IF deleteFromModel»org.eclipse.gef.RequestConstants.REQ_DELETE«ELSE»org.eclipse.gmf.runtime.lite.requests.RequestConstants.REQ_FORCED_DELETE_VIEW«ENDIF»);
	deleteLinkRequest.setEditParts(nextEditPart);
	result.add(nextEditPart.getCommand(deleteLinkRequest));
	break;
}
«ENDDEFINE»

«DEFINE getGraphicalEditPart FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.GraphicalEditPart getGraphicalEditPart() {
	return (org.eclipse.gef.GraphicalEditPart) getHost();
}
«ENDDEFINE»

«DEFINE createDeleteCommandPrim(boolean deleteFromModel) FOR gmfgen::GenCommonBase»«ERROR "UnexpectedType"»«ENDDEFINE»

«DEFINE createDeleteCommandPrim(boolean deleteFromModel) FOR gmfgen::GenNode-»
org.eclipse.emf.common.command.CompoundCommand cc = new org.eclipse.emf.common.command.CompoundCommand();
«IF deleteFromModel-»
cc.append(createDomainModelRemoveCommand(editingDomain));
«ENDIF-»
cc.append(new org.eclipse.gmf.runtime.lite.commands.RemoveNotationalElementCommand((org.eclipse.gmf.runtime.notation.View) «EXPAND getDiagramElementMethodName»().eContainer(), «EXPAND getDiagramElementMethodName»()));
«ENDDEFINE»

«DEFINE createDeleteCommandPrim(boolean deleteFromModel) FOR gmfgen::GenLink-»
org.eclipse.emf.common.command.CompoundCommand cc = new org.eclipse.emf.common.command.CompoundCommand();
«IF deleteFromModel-»
cc.append(createDomainModelRemoveCommand(editingDomain));
«ENDIF-»
cc.append(new org.eclipse.gmf.runtime.lite.commands.RemoveNotationalEdgeCommand(«EXPAND getDiagramElementMethodName»().getDiagram(), «EXPAND getDiagramElementMethodName»()));
«ENDDEFINE»

«DEFINE getDiagramElementMethodName FOR gmfgen::GenCommonBase»«ERROR "Unexpected type: " + this»«ENDDEFINE»
«DEFINE getDiagramElementMethodName FOR gmfgen::GenNode»getDiagramNode«ENDDEFINE»
«DEFINE getDiagramElementMethodName FOR gmfgen::GenLink»getDiagramEdge«ENDDEFINE»

«DEFINE getDiagramNode FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gmf.runtime.notation.Node «EXPAND getDiagramElementMethodName»() {
	return (org.eclipse.gmf.runtime.notation.Node) getHost().getModel();
}
«ENDDEFINE»

«DEFINE getDiagramEdge FOR gmfgen::GenLink-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gmf.runtime.notation.Edge «EXPAND getDiagramElementMethodName»() {
	return (org.eclipse.gmf.runtime.notation.Edge) getHost().getModel();
}
«ENDDEFINE»

«DEFINE getDeleteViewCommand FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected org.eclipse.gef.commands.Command getDeleteViewCommand(org.eclipse.gef.requests.GroupRequest deleteRequest, boolean isForced) {
	if (!isForced && !canDeleteView()) {
		return org.eclipse.gef.commands.UnexecutableCommand.INSTANCE;
	}
	org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(«EXPAND getDiagramElementMethodName»().getDiagram().getElement());
«LET incomingLinks() AS incomingLinks-»
«LET outgoingLinks() AS outgoingLinks-»
«IF incomingLinks.size() > 0 || outgoingLinks.size() > 0-»
	org.eclipse.gmf.runtime.lite.commands.CompositeWrappingCommand result = new org.eclipse.gmf.runtime.lite.commands.CompositeWrappingCommand(editingDomain, «EXPAND xpt::Externalizer::accessorCall(getDiagram().i18nKeyForDeleteDiagramElementLabel()) FOR getDiagram().editorGen»);
«ENDIF-»
	«EXPAND deleteIncomingLinks(incomingLinks, false)-»
	«EXPAND deleteOutgoingLinks(outgoingLinks, false)-»
	«EXPAND createDeleteCommandPrim(false)-»
«IF incomingLinks.size() > 0 || outgoingLinks.size() > 0-»
	result.add(cc);
	return result;
«ELSE-»
	return new org.eclipse.gmf.runtime.lite.commands.WrappingCommand(editingDomain, cc);
«ENDIF-»
«ENDLET-»
«ENDLET-»
}
«ENDDEFINE»

«DEFINE canDeleteView FOR gmfgen::GenCommonBase»«ERROR "Unexpected Type: " + this»«ENDDEFINE»

«DEFINE canDeleteView FOR gmfgen::GenLink-»
«EXPAND xpt::Common::generatedMemberComment»
private boolean canDeleteView() {
	return false;
}
«ENDDEFINE»

«DEFINE canDeleteView FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
private boolean canDeleteView() {
	if («EXPAND getDiagramElementMethodName»().getEAnnotation("Shortcut") != null) {	«EXPAND xpt::Common::nonNLS»
		return true;
	}
	org.eclipse.gmf.runtime.notation.View parentView = (org.eclipse.gmf.runtime.notation.View) «EXPAND getDiagramElementMethodName»().eContainer();
	if (parentView == null) {
		return true;
	}
	org.eclipse.gmf.runtime.notation.CanonicalStyle canonicalStyle = (org.eclipse.gmf.runtime.notation.CanonicalStyle) parentView.getStyle(org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getCanonicalStyle());
	if (canonicalStyle != null) {
		return !canonicalStyle.isCanonical();
	}
	return «!getDiagram().synchronized»;
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenCommonBase»«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenDiagram-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForDeleteModelElementLabel())-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForDeleteDiagramElementLabel())-»
«ENDDEFINE»

«DEFINE i18nValues FOR gmfgen::GenDiagram-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForDeleteModelElementLabel(), "Delete Model Element")-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForDeleteDiagramElementLabel(), "Delete Diagram Element")-»
«ENDDEFINE»