blob: 7c81f35032c480bd441c562327d4ac816fe5c1e2 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2017-2020 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.emf.viewer.plantuml.handlers;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.app4mc.emf.viewer.plantuml.builders.BuilderResult;
import org.eclipse.app4mc.emf.viewer.plantuml.builders.EClassContentsAndHierarchyBuilder;
import org.eclipse.app4mc.emf.viewer.plantuml.utils.ExecutionCategory;
import org.eclipse.app4mc.emf.viewer.plantuml.utils.ExecutionUtil;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
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 AbstractPlantUMLHandler {
/**
* 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 EClassContentsAndHierarchyBuilder builder = new EClassContentsAndHierarchyBuilder();
BuilderResult result = null;
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 Contents and Hierarchy View ===================== */
openHierarchyView(selectedObjClass);
eClassName = selectedObjClass.getName();
result = builder.generatePlantUML(selectedObjClass);
} else {
openErrorDialog();
return null;
}
}
} else {
openErrorDialog();
return null;
}
System.out.println(result.getPlantUMLText());
try {
final Map<String, String> propsMap = new HashMap<String, String>();
// propsMap.put(ExecutionCategory.isClassHierarchy_Contents_Generation.toString(), "true");
ExecutionUtil.setExecutionCategory(ExecutionCategory.eClassContentsAndHierarchy);
generateSVGAndDisplayDiagram(result, eClassName + "__contents_deep_Hierarchy", propsMap);
} catch (final IOException e) {
// TODO Zmeer Auto-generated catch block
e.printStackTrace();
}
return null;
}
}