| /******************************************************************************* |
| * 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.localanalysis.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.dialogs.MessageDialog; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| import org.eclipse.uml2.uml.Class; |
| import org.eclipse.uml2.uml.UMLPackage; |
| import org.eclipse.uml2.uml.util.UMLUtil; |
| import org.polarsys.esf.core.profile.esfarchitectureconcepts.application.ApplyESFArchitectureConceptsAnnotation; |
| import org.polarsys.esf.core.utils.ModelUtil; |
| import org.polarsys.esf.esfarchitectureconcepts.ISBlock; |
| import org.polarsys.esf.localanalysis.execution.setup.NewLocalAnalysisSetup; |
| |
| /** |
| * Handler class for starting a new local analysis. |
| * |
| * @author $Author: ymunoz $ |
| * @version $Revision: 168 $ |
| */ |
| public final class StartNewLocalAnalysisHandler |
| extends AbstractHandler { |
| |
| /** |
| * Default constructor. |
| */ |
| public StartNewLocalAnalysisHandler() { } |
| |
| /** |
| * Get the selected element and setup a new Local Analysis. |
| * |
| * {@inheritDoc} |
| */ |
| @Override |
| public Object execute(final ExecutionEvent pEvent) throws ExecutionException { |
| ISelection vSelection = HandlerUtil.getCurrentSelection(pEvent); |
| |
| final Class vSelectedClass = |
| (Class) ModelUtil.getSelectedEObjectOfType(vSelection, UMLPackage.eINSTANCE.getClass_()); |
| |
| if (vSelectedClass != null) { |
| if (UMLUtil.getStereotypeApplication(vSelectedClass, ISBlock.class) == null) { |
| Shell shell = Display.getCurrent().getActiveShell(); |
| boolean apply = MessageDialog.openQuestion(shell, "Cannot execute", "In order to execute this command, please apply the stereotype SBlock to the class. Should the tool apply ESF stereotypes on the whole model?"); |
| if (apply) { |
| if (vSelectedClass.getModel() != null) { |
| ApplyESFArchitectureConceptsAnnotation.applyAnnotationOnUMLModel(vSelectedClass.getModel()); |
| } |
| else { |
| // error message |
| } |
| } |
| } |
| if (UMLUtil.getStereotypeApplication(vSelectedClass, ISBlock.class) != null) { |
| NewLocalAnalysisSetup.setup(UMLUtil.getStereotypeApplication(vSelectedClass, ISBlock.class)); |
| } |
| } |
| else { |
| |
| } |
| return null; |
| } |
| |
| } |