| /***************************************************************************** |
| * 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.diagrams.advices; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest; |
| 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.profile.robotics.commpattern.CommunicationPatternDefinition; |
| import org.eclipse.papyrus.robotics.profile.robotics.components.ComponentService; |
| import org.eclipse.papyrus.robotics.profile.robotics.generics.Uses; |
| import org.eclipse.papyrus.robotics.profile.robotics.services.ServiceDefinition; |
| import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; |
| import org.eclipse.uml2.uml.Class; |
| import org.eclipse.uml2.uml.Interface; |
| |
| /** |
| * Edit Helper Advice for {@link Uses} |
| */ |
| public class UsesEditHelperAdvice 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) { |
| |
| EObject source = request.getSource(); |
| EObject target = request.getTarget(); |
| |
| //1st case allowed - CS uses Sdef |
| boolean verifiedCondOnSource = (source instanceof Class) && (StereotypeUtil.isApplied((Class) source, ComponentService.class)); |
| boolean verifiedCondOnTarget = (target instanceof Interface) && (StereotypeUtil.isApplied((Interface) target, ServiceDefinition.class)); |
| if (verifiedCondOnSource && verifiedCondOnTarget) |
| return true; |
| |
| // 2nd case allowed - Sdef uses CommPatternDef |
| verifiedCondOnSource = (source instanceof Interface) && (StereotypeUtil.isApplied((Interface) source, ServiceDefinition.class)); |
| verifiedCondOnTarget = (target instanceof Class) && (StereotypeUtil.isApplied((Class) target, CommunicationPatternDefinition.class)); |
| if (verifiedCondOnSource && verifiedCondOnTarget) |
| return true; |
| return false; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getBeforeConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest) |
| */ |
| @Override |
| protected ICommand getBeforeConfigureCommand(ConfigureRequest request) { |
| return super.getBeforeConfigureCommand(request); |
| } |
| |
| |
| /** |
| * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) |
| */ |
| @Override |
| protected ICommand getAfterConfigureCommand(ConfigureRequest request) { |
| return super.getAfterConfigureCommand(request); |
| } |
| } |