blob: 8c2f9ff501f6cf42a6666be9136e385bcaa10cfd [file] [log] [blame]
/*******************************************************************************
* 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 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:
* ALL4TEC & CEA LIST - initial API and implementation
******************************************************************************/
package org.polarsys.esf.core.diagram.esfarchitectureconcepts.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.util.UMLUtil;
import org.polarsys.esf.core.diagram.esfarchitectureconcepts.util.ESFArchitectureConceptsDiagramUtil;
import org.polarsys.esf.core.utils.ModelUtil;
import org.polarsys.esf.esfarchitectureconcepts.ISBlock;
import org.polarsys.esf.esfarchitectureconcepts.ISPart;
/**
* Handler class for the creation of the ESF Architecture Concepts Diagram.
*
* @author $Author: ymunoz $
* @version $Revision: 168 $
*/
public class CreateESFArchitectureConceptsDiagramHandler
extends AbstractHandler {
@Override
public Object execute(ExecutionEvent pEvent) throws ExecutionException {
ISelection vSelection = HandlerUtil.getCurrentSelection(pEvent);
// get the Property selected by the user
final Property vSelectedProperty =
(Property) ModelUtil.getSelectedEObjectOfType(vSelection, UMLPackage.eINSTANCE.getProperty());
// check if the selected property exists
if (vSelectedProperty != null) {
// check if property is stereotyped SPart
if (UMLUtil.getStereotypeApplication(vSelectedProperty, ISPart.class) != null) {
// get its type
Class vType = (Class) (vSelectedProperty.getType());
// check if its type is stereotyped SBlock
if ((vType != null) && (UMLUtil.getStereotypeApplication(vType, ISBlock.class) != null)) {
TransactionalEditingDomain vDomain = ModelUtil.getTransactionalEditingDomain(vType);
// create ESF Architecture Concepts Diagram in type
ESFArchitectureConceptsDiagramUtil.createDiagram(vType, vDomain);
}
}
} else {
// get the Class selected by the user
final Class vSelectedClass =
(Class) ModelUtil.getSelectedEObjectOfType(vSelection, UMLPackage.eINSTANCE.getClass_());
// check if the selected class exists
if (vSelectedClass != null) {
// check if class is stereotyped SBlock
if (UMLUtil.getStereotypeApplication(vSelectedClass, ISBlock.class) != null) {
TransactionalEditingDomain vDomain = ModelUtil.getTransactionalEditingDomain(vSelectedClass);
// create ESF Architecture Concepts Diagram
ESFArchitectureConceptsDiagramUtil.createDiagram(vSelectedClass, vDomain);
}
}
}
return null;
}
}