blob: 514d9caa09d1419f59867589a15239536006cc8f [file] [log] [blame]
/**
********************************************************************************
* 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.EClassContentsAndHierarchyBufferBuilder;
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 EClassContentsAndHierarchyHandler extends AbstractHandlerUtils {
/**
* The constructor.
*/
public EClassContentsAndHierarchyHandler() {
}
/**
* 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>();
StringBuffer plantumlBuffer = new StringBuffer();
String eClassName = "";
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();
final EClassContentsAndHierarchyBufferBuilder builder = new EClassContentsAndHierarchyBufferBuilder();
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>();
// propsMap.put(ExecutionCategory.isClassHierarchy_Contents_Generation.toString(), "true");
ExecutionUtil.setExecutionCategory(ExecutionCategory.eClassContentsAndHierarchy);
generateSVGAndDisplayDiagram(plantumlBuffer, eClassName + "__contents_deep_Heirarchy", id2ObjectsMap,
propsMap);
}
catch (final IOException e) {
// TODO Zmeer Auto-generated catch block
e.printStackTrace();
}
return null;
}
}