blob: 15f2e1ce5b3e4718bd5a737dd5d1ed1691a30757 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2019 CEA LIST.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Shuai Li (CEA LIST) <shuai.li@cea.fr> - initial API and implementation
*******************************************************************************/
package org.eclipse.papyrus.iotml.wot.td.codegen.ui.handlers;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.iotml.wot.td.codegen.transformation.TDModelElementsCreator;
import org.eclipse.papyrus.uml.diagram.common.handlers.CmdHandler;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.PackageableElement;
/**
* Handler class for generating VDHL code from UML model.
*/
public class GenerateTDHandler extends CmdHandler {
/**
* Execute the generation TD code from the selected UML Class.
*
* {@inheritDoc}
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
updateSelectedEObject();
if (selectedEObject instanceof PackageableElement) {
PackageableElement pe = (PackageableElement) selectedEObject;
URI uri = pe.eResource().getURI();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
if (uri.segmentCount() < 2) {
return null;
}
IProject modelProject = root.getProject(uri.segment(1));
if (modelProject == null) {
return null;
}
if (modelProject.exists()) {
TDModelElementsCreator mec = new TDModelElementsCreator(modelProject, pe);
mec.createPackageableElement(pe, null);
}
}
return null;
}
/**
* The handler is capable of executing at this time if the selected element is a UML Class.
*
* {@inheritDoc}
*/
@Override
public boolean isEnabled() {
updateSelectedEObject();
if (selectedEObject instanceof Class) {
return true;
}
return super.isEnabled();
}
}