| /* |
| * Copyright (c) 2007, 2009 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/2009/GenModel'» |
| «IMPORT 'http://www.eclipse.org/emf/2002/GenModel'» |
| |
| «DEFINE CreateNodeCommand FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::copyright FOR getDiagram().editorGen» |
| package «getDiagram().editCommandsPackageName»; |
| |
| «EXPAND xpt::Common::generatedClassComment» |
| public class «EXPAND className» «EXPAND supertypes» { |
| «EXPAND attributes-» |
| «EXPAND ctors-» |
| «EXPAND prepare-» |
| «EXPAND canUndo-» |
| «EXPAND execute-» |
| «EXPAND undo-» |
| «EXPAND redo-» |
| «EXPAND additions-» |
| } |
| «ENDDEFINE» |
| |
| «DEFINE attributes FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| private final org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand notationAddCommand; |
| |
| «EXPAND xpt::Common::generatedMemberComment» |
| private final org.eclipse.emf.common.command.Command domainModelAddCommand; |
| «ENDDEFINE» |
| |
| «DEFINE ctors FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parent, org.eclipse.gmf.runtime.lite.requests.CreateRequestEx request) { |
| this(parent, request, null); |
| } |
| |
| «EXPAND xpt::Common::generatedMemberComment» |
| public «EXPAND className»(org.eclipse.gmf.runtime.notation.View parent, org.eclipse.gmf.runtime.lite.requests.CreateRequestEx request, org.eclipse.draw2d.geometry.Rectangle constraint) { |
| «EXPAND MetaModel::NewInstance('createdDomainElement') FOR modelFacet.metaClass-» |
| «EXPAND initialize('createdDomainElement')-» |
| «EXPAND initializeDomainModelCommand FOR modelFacet-» |
| «EXPAND xpt::commands::Common::adjustConstraint-» |
| this.notationAddCommand = new org.eclipse.gmf.runtime.lite.commands.CreateNotationalNodeCommand(parent, «EXPAND MetaModel::DowncastToEObject('createdDomainElement') FOR modelFacet.metaClass», |
| constraint, «getNotationViewFactoryQualifiedClassName()».INSTANCE); |
| request.setCreatedObject(notationAddCommand.getCreatedView()); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE initializeDomainModelCommand FOR gmfgen::TypeModelFacet-» |
| «EXPAND checkFeature('parent.getElement()', null) FOR containmentMetaFeature-» |
| «LET childMetaFeature <> null and (childMetaFeature <> containmentMetaFeature and not childMetaFeature.ecoreFeature._derived) AS addChild-» |
| «IF addChild-» |
| «EXPAND checkFeature('parent.getElement()', null) FOR childMetaFeature-» |
| «ENDIF-» |
| org.eclipse.emf.transaction.TransactionalEditingDomain domainModelEditDomain = org.eclipse.emf.transaction.util.TransactionUtil.getEditingDomain(parent.getDiagram().getElement()); |
| «IF addChild-» |
| org.eclipse.emf.common.command.CompoundCommand compoundCommand = new org.eclipse.emf.common.command.CompoundCommand(); |
| «IF containmentMetaFeature = null-» |
| compoundCommand.append(new org.eclipse.emf.edit.command.AddCommand(domainModelEditDomain, «EXPAND xpt::commands::Common::getPhantomContainmentResource FOR 'parent'».getContents(), createdDomainElement)); |
| «ELSE-» |
| compoundCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand('domainModelEditDomain', 'parent.getElement()', 'createdDomainElement') FOR containmentMetaFeature»); |
| «ENDIF-» |
| compoundCommand.append(«EXPAND xpt::commands::Common::plugFeatureCommand('domainModelEditDomain', 'parent.getElement()', 'createdDomainElement') FOR childMetaFeature»); |
| domainModelAddCommand = compoundCommand; |
| «ELSE-» |
| «IF containmentMetaFeature = null-» |
| domainModelAddCommand = new org.eclipse.emf.edit.command.AddCommand(domainModelEditDomain, «EXPAND xpt::commands::Common::getPhantomContainmentResource FOR 'parent'».getContents(), createdDomainElement); |
| «ELSE-» |
| domainModelAddCommand = «EXPAND xpt::commands::Common::plugFeatureCommand('domainModelEditDomain', 'parent.getElement()', 'createdDomainElement') FOR containmentMetaFeature»; |
| «ENDIF-» |
| «ENDIF-» |
| «ENDLET-» |
| «ENDDEFINE» |
| |
| «DEFINE prepare FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| protected boolean prepare() { |
| return domainModelAddCommand != null && domainModelAddCommand.canExecute() && notationAddCommand != null && notationAddCommand.canExecute(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE className FOR gmfgen::GenNode»Create«EXPAND xpt::commands::Common::commandNameInfix»Command«ENDDEFINE» |
| «DEFINE qualifiedClassName FOR gmfgen::GenNode»«getDiagram().editCommandsPackageName».«EXPAND className»«ENDDEFINE» |
| «DEFINE supertypes FOR gmfgen::GenNode»extends org.eclipse.emf.common.command.AbstractCommand«ENDDEFINE» |
| |
| «DEFINE canUndo FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public boolean canUndo() { |
| return domainModelAddCommand != null && domainModelAddCommand.canUndo() && notationAddCommand != null && notationAddCommand.canUndo(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE execute FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public void execute() { |
| domainModelAddCommand.execute(); |
| notationAddCommand.execute(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE undo FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public void undo() { |
| notationAddCommand.undo(); |
| domainModelAddCommand.undo(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE redo FOR gmfgen::GenNode-» |
| «EXPAND xpt::Common::generatedMemberComment» |
| public void redo() { |
| execute(); |
| } |
| «ENDDEFINE» |
| |
| «DEFINE additions FOR gmfgen::GenNode-» |
| «ENDDEFINE» |
| |
| «DEFINE checkFeature(containerVar : String, containerClass : genmodel::GenClass) FOR genmodel::GenFeature-» |
| «IF ecoreFeature.upperBound > 0-» |
| if («EXPAND xpt::commands::Common::featureMultiplicityComparator(containerVar, containerClass)») { |
| domainModelAddCommand = null; |
| notationAddCommand = null; |
| return; |
| } |
| «ENDIF-» |
| «ENDDEFINE» |
| |
| «DEFINE initialize(newElementVar : String) FOR gmfgen::GenNode»«IF modelFacet.modelElementInitializer <> null-» |
| «EXPAND xpt::providers::DomainElementInitializer::qualifiedClassName FOR getDiagram()».init_«getUniqueIdentifier()»(«newElementVar»); |
| «ENDIF»«ENDDEFINE» |