blob: 6121f42fe46d5379a3a1a78eb834383feb3148dc [file] [log] [blame]
/*****************************************************************************
* 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.services.ServiceLink;
import org.eclipse.papyrus.robotics.profile.robotics.services.ServiceWish;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.uml2.uml.InstanceSpecification;
/**
* Edit Helper Advice for {@link ServiceLink}
*/
public class ServiceLinkAdvice 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();
boolean verifiedCondOnSource = (source instanceof InstanceSpecification) && (StereotypeUtil.isApplied((InstanceSpecification) source, ServiceWish.class));
boolean verifiedCondOnTarget = (target instanceof InstanceSpecification) && (StereotypeUtil.isApplied((InstanceSpecification) target, ServiceWish.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);
}
}