|
|
Line 1: |
Line 1: |
− | It is possible to extends default creation of objects (to create another elements while creating one, to rename a newly created element or other.)
| + | This page has been moved to https://github.com/eclipse/capella/wiki/Tutorials |
− | | + | |
− | - 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.
| + | |
− |
| + | |
− | [https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.menu.dynamic/schema/MDEMenuItemContribution.exsd Extension point definition]
| + | |
− | | + | |
− | [https://git.polarsys.org/c/capella/capella.git/tree/core/plugins/org.polarsys.capella.core.data.menu.contributions 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
| + | |
− | | + | |
− | <pre>
| + | |
− | <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>
| + | |
− | | + | |
− | </pre>
| + | |
− | | + | |
− | Linked to a new class implementing IMDEMenuItemContribution : such as
| + | |
− | | + | |
− | <pre>
| + | |
− | /*******************************************************************************
| + | |
− | * 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;
| + | |
− | }
| + | |
− | }
| + | |
− | | + | |
− | </pre>
| + | |