| /******************************************************************************* |
| * Copyright (c) 2016 ALL4TEC & CEA LIST. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * ALL4TEC & CEA LIST - initial API and implementation |
| ******************************************************************************/ |
| package org.polarsys.esf.safetyreq.execution.ui.handler; |
| |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.papyrus.sysml14.sysmlPackage; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| import org.eclipse.uml2.uml.Model; |
| import org.eclipse.uml2.uml.NamedElement; |
| import org.eclipse.uml2.uml.UMLPackage; |
| import org.polarsys.esf.core.utils.ModelUtil; |
| import org.polarsys.esf.safetyreq.profile.tools.util.ESFSafetyRequirementsUtil; |
| |
| /** |
| * Handler class for applying SysML profile. |
| * |
| * @author $Author: ymunoz $ |
| * @version $Revision: 168 $ |
| */ |
| public class ApplySysMLProfileHandler |
| extends AbstractHandler { |
| |
| /** |
| * Default constructor. |
| */ |
| public ApplySysMLProfileHandler() { |
| } |
| |
| /** |
| * Get the selected an element and apply SysML profile. |
| * |
| * {@inheritDoc} |
| */ |
| @Override |
| public Object execute(final ExecutionEvent pEvent) throws ExecutionException { |
| ISelection vSelection = HandlerUtil.getCurrentSelection(pEvent); |
| |
| final NamedElement vSelectedElement = |
| (NamedElement) ModelUtil.getSelectedEObjectOfType(vSelection, UMLPackage.eINSTANCE.getNamedElement()); |
| |
| if (vSelectedElement != null) { |
| Model vESFModel = ModelUtil.getWorkingModel(); |
| if (vESFModel != null) { |
| |
| // Verify and apply (if necessary) SysML profile |
| if (vESFModel.getAppliedProfile(sysmlPackage.eNS_PREFIX) == null) { |
| ESFSafetyRequirementsUtil.applySysMLProfile(vESFModel); |
| } |
| } |
| } |
| |
| return null; |
| } |
| } |