| /***************************************************************************** |
| * Copyright (c) 2017 CEA LIST and Thales |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Ansgar Radermacher - initial API and implementation |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.robotics.core.types.advice; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest; |
| import org.eclipse.papyrus.robotics.bpc.profile.bpc.Block; |
| import org.eclipse.uml2.uml.Element; |
| import org.eclipse.uml2.uml.util.UMLUtil; |
| |
| /** |
| * Edit Helper Advice for a {@link org.eclipse.uml2.uml.Connector} |
| */ |
| public class ConnectorEditHelperAdvice extends AbstractEditHelperAdvice { |
| |
| @Override |
| public boolean approveRequest(IEditCommandRequest request) { |
| if (request instanceof GetEditContextRequest) { |
| GetEditContextRequest context = (GetEditContextRequest) request; |
| if (context.getEditCommandRequest() instanceof CreateRelationshipRequest) { |
| return approveCreateRelationshipRequest((CreateRelationshipRequest) context.getEditCommandRequest()); |
| } |
| } |
| return super.approveRequest(request); |
| } |
| |
| /** |
| * Check that the source of the assignment is a technical policy |
| * @param request |
| * @return |
| */ |
| protected boolean approveCreateRelationshipRequest(CreateRelationshipRequest request) { |
| |
| source = request.getSource(); |
| target = request.getTarget(); |
| if ((source instanceof Element) && (target instanceof Element)) { |
| // to be refined. Source and target must be blocks |
| if (UMLUtil.getStereotypeApplication((Element) source, Block.class) != null && |
| UMLUtil.getStereotypeApplication((Element) target, Block.class) != null) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| protected EObject source; |
| protected EObject target; |
| } |