| /******************************************************************************* |
| * 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.viewers.ISelection; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| import org.eclipse.uml2.uml.Package; |
| import org.eclipse.uml2.uml.UMLPackage; |
| import org.eclipse.uml2.uml.util.UMLUtil; |
| import org.polarsys.esf.core.utils.ESFTablesUtil; |
| import org.polarsys.esf.core.utils.ModelUtil; |
| import org.polarsys.esf.esflocalanalysis.ISLocalAnalysis; |
| import org.polarsys.esf.localanalysis.profile.tools.util.ESFLocalAnalysisUtil; |
| import org.polarsys.esf.localanalysis.table.set.ESFLocalAnalysisTablesSet; |
| |
| /** |
| * Handler class for creating a SSytemEventslibrary. |
| * |
| * @author $Author: ymunoz $ |
| * @version $Revision: 168 $ |
| */ |
| public class CreateSSystemEventsLibraryHandler |
| extends AbstractHandler { |
| |
| /** |
| * Default constructor. |
| */ |
| public CreateSSystemEventsLibraryHandler() { |
| } |
| |
| /** |
| * Get the selected element (SLocalAnalysis package) and call the command for creating a SSytemEventslibrary. |
| * |
| * {@inheritDoc} |
| */ |
| @Override |
| public Object execute(final ExecutionEvent pEvent) throws ExecutionException { |
| ISelection vSelection = HandlerUtil.getCurrentSelection(pEvent); |
| |
| final Package vSelectedPackage = |
| (Package) ModelUtil.getSelectedEObjectOfType(vSelection, UMLPackage.eINSTANCE.getPackage()); |
| |
| if ((vSelectedPackage != null) |
| && (UMLUtil.getStereotypeApplication(vSelectedPackage, ISLocalAnalysis.class) != null)) { |
| ISLocalAnalysis vLocalAnalysis = |
| (ISLocalAnalysis) UMLUtil.getStereotypeApplication(vSelectedPackage, ISLocalAnalysis.class); |
| |
| if (vLocalAnalysis.getSSystemEventsLibrary() == null) { |
| ESFLocalAnalysisUtil.createSSystemEventsLibrary(vSelectedPackage); |
| // Retrieve 'SystemEventsLibrary' package |
| Package vSystemEventsLibraryPackage = vLocalAnalysis.getSSystemEventsLibrary().getBase_Package(); |
| |
| if (vSystemEventsLibraryPackage != null) { |
| // Create SystemEventsLibrary table |
| ESFTablesUtil.createTable( |
| ESFLocalAnalysisTablesSet.SSYSTEMEVENTSLIBRARY_TABLE_ID, |
| ESFLocalAnalysisTablesSet.SSYSTEMEVENTSLIBRARY_TABLE_NAME, |
| vSystemEventsLibraryPackage); |
| } |
| } |
| |
| } |
| return null; |
| } |
| } |