| /** |
| ******************************************************************************** |
| * Copyright (c) 2017 - 2018 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| ******************************************************************************** |
| */ |
| package org.eclipse.app4mc.emfutils.content.extractor.handlers; |
| |
| import java.io.IOException; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.Map; |
| |
| import org.eclipse.app4mc.emfutils.content.extractor.builders.EClassHierarchyBufferBuilder; |
| import org.eclipse.app4mc.emfutils.content.extractor.utils.ExecutionCategory; |
| import org.eclipse.app4mc.emfutils.content.extractor.utils.ExecutionUtil; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.emf.common.util.BasicEMap; |
| import org.eclipse.emf.common.util.EMap; |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| |
| |
| public class EClassHierarchyHandler extends AbstractHandlerUtils { |
| |
| /** |
| * The constructor. |
| */ |
| public EClassHierarchyHandler() { |
| } |
| |
| /** |
| * the command has been executed, so extract extract the needed information from the application context. |
| */ |
| @Override |
| public Object execute(final ExecutionEvent event) throws ExecutionException { |
| |
| |
| final EMap<String, Object> id2ObjectsMap = new BasicEMap<String, Object>(); |
| |
| final EClassHierarchyBufferBuilder builder = new EClassHierarchyBufferBuilder(); |
| |
| |
| String eClassName = ""; |
| |
| StringBuffer plantumlBuffer = new StringBuffer(); |
| |
| |
| ISelection selection = null; |
| |
| selection = HandlerUtil.getActiveMenuSelection(event); |
| |
| if (selection == null) { |
| |
| selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); |
| |
| } |
| if (selection != null & selection instanceof IStructuredSelection) { |
| |
| final IStructuredSelection strucSelection = (IStructuredSelection) selection; |
| |
| for (final Iterator<Object> iterator = strucSelection.iterator(); iterator.hasNext();) { |
| |
| final Object element = iterator.next(); |
| |
| if (element instanceof EObject) { |
| |
| EClass selectedObjClass = null; |
| |
| if (element instanceof EClass) { |
| selectedObjClass = (EClass) element; |
| } |
| else { |
| selectedObjClass = ((EObject) element).eClass(); |
| } |
| |
| |
| // final EClass selectedObjClass = ((EObject) element).eClass(); |
| |
| /* ====================Opening Heirarchy View ===================== */ |
| |
| openHierarchyView(selectedObjClass); |
| |
| |
| eClassName = selectedObjClass.getName(); |
| |
| |
| plantumlBuffer = builder.buildBuffer(selectedObjClass); |
| |
| id2ObjectsMap.addAll(builder.getId2ObjectsMap()); |
| |
| } |
| else { |
| openErrorDialog(); |
| return null; |
| } |
| } |
| } |
| else { |
| openErrorDialog(); |
| return null; |
| } |
| |
| |
| System.out.println(plantumlBuffer.toString()); |
| |
| try { |
| final Map<String, String> propsMap = new HashMap<String, String>(); |
| |
| ExecutionUtil.setExecutionCategory(ExecutionCategory.eClassHierarchy); |
| |
| generateSVGAndDisplayDiagram(plantumlBuffer, eClassName + "__eclass_Heirarchy", id2ObjectsMap, propsMap); |
| } |
| catch (final IOException e) { |
| e.printStackTrace(); |
| } |
| |
| return null; |
| } |
| |
| |
| } |