|
|
Line 1: |
Line 1: |
− | = Example =
| + | This page has been moved to https://github.com/eclipse/capella/wiki/Tutorials |
− | | + | |
− | An example importing elements from another DSL/metamodel to a Capella model with iterativity (based on diff/merge technology)
| + | |
− | [http://git.eclipse.org/c/diffmerge/org.eclipse.emf.diffmerge.coevolution.git/tree/core/examples/apa APA to Capella Example]
| + | |
− | | + | |
− | = Extensions Points =
| + | |
− | org.eclipse.ui.commands
| + | |
− | | + | |
− | <pre>
| + | |
− | <extension point="org.eclipse.ui.commands">
| + | |
− |
| + | |
− | <category
| + | |
− | id="org.polarsys.capella.xxxx.category1"
| + | |
− | name="Extension commands">
| + | |
− | </category>
| + | |
− | <command
| + | |
− | categoryId="org.polarsys.capella.xxxx.category1"
| + | |
− | description="Command 1"
| + | |
− | id="org.polarsys.capella.xxxx.command1"
| + | |
− | name="Command 1">
| + | |
− | </command>
| + | |
− | </extension>
| + | |
− | | + | |
− | </pre>
| + | |
− | | + | |
− | org.eclipse.ui.handlers
| + | |
− | | + | |
− | <pre>
| + | |
− | <extension point="org.eclipse.ui.handlers">
| + | |
− | <handler commandId="org.polarsys.capella.xxxx.command1"
| + | |
− | class="org.polarsys.capella.xxxx.handlers.Command1Handler">
| + | |
− | </handler>
| + | |
− | </extension>
| + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | org.eclipse.ui.menus
| + | |
− | | + | |
− | <pre>
| + | |
− | | + | |
− | <extension point="org.eclipse.ui.menu">
| + | |
− | <menuContribution locationURI="popup:org.eclipse.ui.popup.any?after=additions">
| + | |
− |
| + | |
− | <menu id="org.polarsys.capella.xxxx"
| + | |
− | icon="icons/full/etool16/plugin.gif"
| + | |
− | label="REC / RPL">
| + | |
− | | + | |
− | <separator visible="true" name="mainCommands"/>
| + | |
− | <separator visible="true" name="additions"/>
| + | |
− | | + | |
− | </menu>
| + | |
− | </menuContribution>
| + | |
− | | + | |
− | | + | |
− | </extension>
| + | |
− | | + | |
− | <extension point="org.eclipse.ui.menus">
| + | |
− |
| + | |
− | <menuContribution locationURI="popup:org.polarsys.capella.xxxx?after=mainCommands">
| + | |
− | <command
| + | |
− | commandId="org.polarsys.capella.xxxx.command1"
| + | |
− | id="org.polarsys.capella.xxxx.command1"
| + | |
− | style="push">
| + | |
− |
| + | |
− | <visibleWhen
| + | |
− | checkEnabled="false">
| + | |
− | <with variable="activeMenuSelection">
| + | |
− | <iterate
| + | |
− | ifEmpty="false">
| + | |
− | <or>
| + | |
− | <!-- Enable on Diagram elements -->
| + | |
− | <instanceof
| + | |
− | value="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart">
| + | |
− | </instanceof>
| + | |
− | | + | |
− | <!-- Enable on Model elements -->
| + | |
− | <instanceof
| + | |
− | value="org.eclipse.emf.ecore.EObject">
| + | |
− | </instanceof>
| + | |
− | | + | |
− | <!-- Enable on Aird file -->
| + | |
− | <!--adapt type="org.eclipse.core.resources.IResource">
| + | |
− | <test property="org.eclipse.core.resources.extension" value="aird" />
| + | |
− | </adapt-->
| + | |
− | </or>
| + | |
− | </iterate>
| + | |
− | </with>
| + | |
− | </visibleWhen>
| + | |
− | | + | |
− | </command>
| + | |
− | </menuContribution>
| + | |
− | | + | |
− | </extension>
| + | |
− | </pre>
| + | |
− | | + | |
− | org.eclipse.ui.commandImages
| + | |
− | | + | |
− | <pre>
| + | |
− | | + | |
− | <extension point="org.eclipse.ui.commandImages">
| + | |
− | <extension point="org.eclipse.ui.commandImages">
| + | |
− |
| + | |
− | <image commandId="org.polarsys.capella.xxxx.command1"
| + | |
− | icon="icons/full/etool16/add_element.gif">
| + | |
− | </image>
| + | |
− | | + | |
− | </extension>
| + | |
− | | + | |
− | </extension>
| + | |
− | | + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | =Command Handler=
| + | |
− | You can inherit this following class and create an [https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.ef/src/org/polarsys/capella/common/ef/command/AbstractReadWriteCommand.java AbstractReadWriteCommand] where you perform model modifications.
| + | |
− | | + | |
− | <pre>
| + | |
− | import java.util.Collection;
| + | |
− | | + | |
− | import org.eclipse.core.commands.AbstractHandler;
| + | |
− | import org.eclipse.core.commands.ExecutionEvent;
| + | |
− | import org.eclipse.core.commands.ExecutionException;
| + | |
− | import org.eclipse.core.expressions.IEvaluationContext;
| + | |
− | import org.eclipse.emf.ecore.EObject;
| + | |
− | import org.eclipse.jface.viewers.ISelection;
| + | |
− | import org.eclipse.jface.viewers.IStructuredSelection;
| + | |
− | import org.eclipse.ui.handlers.HandlerUtil;
| + | |
− | import org.polarsys.capella.common.ef.command.ICommand;
| + | |
− | import org.polarsys.capella.common.helpers.TransactionHelper;
| + | |
− | import org.polarsys.capella.core.model.handler.helpers.CapellaAdapterHelper;
| + | |
− | | + | |
− | public abstract class CommandHandler extends AbstractHandler {
| + | |
− | | + | |
− | protected abstract ICommand createCommand(Collection<EObject> selection);
| + | |
− | | + | |
− | public Object execute(final ExecutionEvent event) throws ExecutionException {
| + | |
− | return execute(HandlerUtil.getCurrentSelection(event));
| + | |
− | }
| + | |
− | | + | |
− | public Object execute(ISelection selection) {
| + | |
− | Collection<EObject> semanticElements = CapellaAdapterHelper
| + | |
− | .resolveSemanticObjects(((IStructuredSelection) selection).toList(), true);
| + | |
− | ICommand cmd = createCommand(semanticElements);
| + | |
− | TransactionHelper.getExecutionManager(semanticElements).execute(cmd);
| + | |
− | return null;
| + | |
− | }
| + | |
− | | + | |
− | }
| + | |
− | | + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | <pre>
| + | |
− | | + | |
− | public class Command1Handler extends CommandHandler {
| + | |
− |
| + | |
− | @Override
| + | |
− | protected ICommand createCommand(final Collection<EObject> selection, IProgressMonitor progressMonitor) {
| + | |
− |
| + | |
− | return new AbstractReadWriteCommand() {
| + | |
− |
| + | |
− | @Override
| + | |
− | public void run() {
| + | |
− | System.out.println(selection.toString());
| + | |
− |
| + | |
− | for (EObject object : selection) {
| + | |
− | if (object instanceof SystemFunction) {
| + | |
− | ((SystemFunction)object).setName("new name");
| + | |
− | }
| + | |
− | }
| + | |
− | }
| + | |
− |
| + | |
− | };
| + | |
− | }
| + | |
− | }
| + | |
− |
| + | |
− | </pre>
| + | |