| /********************************************************************* |
| * Copyright (c) 2005, 2019 SAP SE |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * SAP SE - initial API, implementation and documentation |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| **********************************************************************/ |
| package org.eclipse.graphiti.internal.command; |
| |
| import org.eclipse.graphiti.features.IAddFeature; |
| import org.eclipse.graphiti.features.IFeature; |
| import org.eclipse.graphiti.features.context.IAddContext; |
| import org.eclipse.graphiti.features.context.IContext; |
| import org.eclipse.graphiti.mm.pictograms.PictogramElement; |
| |
| /** |
| * The Class AddFeatureCommandWithContext. |
| * |
| * @noinstantiate This class is not intended to be instantiated by clients. |
| * @noextend This class is not intended to be subclassed by clients. |
| */ |
| public class AddFeatureCommandWithContext extends GenericFeatureCommandWithContext { |
| |
| /** |
| * The added pictogram element. |
| */ |
| PictogramElement addedPictogramElement; |
| |
| /** |
| * Instantiates a new adds the feature command with context. |
| * |
| * @param feature |
| * the feature |
| * @param context |
| * the context |
| */ |
| public AddFeatureCommandWithContext(IFeature feature, IContext context) { |
| super(feature, context); |
| } |
| |
| /** |
| * Gets the added pictogram elements. |
| * |
| * @return the added pictogram elements |
| */ |
| public PictogramElement getAddedPictogramElements() { |
| return addedPictogramElement; |
| } |
| |
| private void setAddedPictogramElements(PictogramElement newPictogramElements) { |
| this.addedPictogramElement = newPictogramElements; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see |
| * org.eclipse.graphiti.internal.command.GenericFeatureCommandWithContext |
| * #execute() |
| */ |
| @Override |
| public boolean execute() { |
| boolean ret = false; |
| if (getContext() instanceof IAddContext && getFeature() instanceof IAddFeature) { |
| IAddFeature addFeature = (IAddFeature) getFeature(); |
| IAddContext addContext = (IAddContext) getContext(); |
| if (addFeature.canAdd(addContext)) { |
| setAddedPictogramElements(addFeature.add(addContext)); |
| ret = true; |
| } |
| } |
| return ret; |
| } |
| } |