Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Capella/Tutorials/Extensibility/ExtendCreationCommand
It is possible to extends default creation of objects (to create another elements while creating one, to rename a newly created element or other.)
- Creation tools: covered by this extension point -- Diagram Palette -- Add Element in project explorer -- Programatic calls such as modeling accelerators (i think of 'generation of component exchanges')
- Other programmatic calls: (calling only the generic "constructor" of a model element) are not covered by this extension point -- Copy paste of an element -- Transitions, Patterns, REC/RPL -- other transformation mechanism
It is used for instance when creating a Property in a Class, cardinalities are created under the newly created Property.
Existing Capella Creation Contributions
This extension will contribute to all creation mechanism (From Project Explorer or Diagram Tool Palette)
On Manifest.MF / plugin.xml, add dependency towards org.polarsys.capella.common.menu.dynamic and an extension to it: such as
<extension name="name" point="org.polarsys.capella.common.menu.dynamic.MDEMenuItemContribution"> <MDEMenuItemContribution class="org.polarsys.capella.xxxx.ComponentExchangeItemContribution" id="org.polarsys.capella.xxxx.ComponentExchangeItemContribution"> </MDEMenuItemContribution> </extension>
Linked to a new class implementing IMDEMenuItemContribution : such as
/******************************************************************************* * Copyright (c) 2006, 2016 THALES GLOBAL SERVICES. * 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: * Thales - initial API and implementation *******************************************************************************/ package org.polarsys.capella.xxxx; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; import org.polarsys.capella.common.data.modellingcore.ModelElement; import org.polarsys.capella.common.menu.dynamic.CreationHelper; import org.polarsys.capella.common.menu.dynamic.contributions.IMDEMenuItemContribution; import org.polarsys.capella.core.data.capellacore.CapellacoreFactory; import org.polarsys.capella.core.data.capellacore.Constraint; import org.polarsys.capella.core.data.fa.ComponentExchange; import org.polarsys.capella.core.data.fa.FaPackage; public class ComponentExchangeItemContribution implements IMDEMenuItemContribution { /** * @see org.polarsys.capella.common.ui.menu.IMDEMenuItemContribution#executionContribution() */ public Command executionContribution(EditingDomain editingDomain, ModelElement containerElement, ModelElement createdElement, EStructuralFeature feature) { if (createdElement instanceof ComponentExchange) { ComponentExchange exchange = (ComponentExchange) createdElement; CompoundCommand cmd = new CompoundCommand(); RecordingCommand c = new RecordingCommand((TransactionalEditingDomain)editingDomain) { @Override protected void doExecute() { //if (something relevant) { //we create a constraint inside the ComponentExchange. Constraint c = CapellacoreFactory.eINSTANCE.createConstraint("MyConstraint"); exchange.getOwnedConstraints().add(c); CreationHelper.performContributionCommands(c, exchange); //} } }; cmd.append(c); return cmd; } return null; } /** * @see org.polarsys.capella.common.ui.menu.IMDEMenuItemContribution#getMetaclass() */ public EClass getMetaclass() { return FaPackage.Literals.COMPONENT_EXCHANGE; } /** * @see org.polarsys.capella.common.ui.menu.IMDEMenuItemContribution#selectionContribution() */ public boolean selectionContribution(ModelElement modelElement, EClass cls, EStructuralFeature feature) { return false; } }