Bug 561236 - Update EMF Graphical Viewer

Fixed visualizations that are based on EObject an not on EClass

Change-Id: I7c4aaeef455f39fb56fe7e2304df0d7eec2dc877
Signed-off-by: Dirk Fauth <dirk.fauth@de.bosch.com>
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/AbstractPlantUMLBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/AbstractPlantUMLBuilder.java
index 2393853..4ed3691 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/AbstractPlantUMLBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/AbstractPlantUMLBuilder.java
@@ -45,7 +45,7 @@
 	public BuilderResult generatePlantUML(Object selectedObject) {
 		if (selectedObject instanceof EClass) {
 			return generatePlantUML((EClass) selectedObject);
-		}else if(selectedObject instanceof EObject) {
+		} else if (selectedObject instanceof EObject) {
 			return generatePlantUML((EObject) selectedObject);
 		}
 		return null;
@@ -53,9 +53,7 @@
 	
 	public abstract BuilderResult generatePlantUML(EClass selectedObjClass);
 	
-	public  BuilderResult generatePlantUML(EObject eObject) {
-		return null;
-	}
+	public abstract BuilderResult generatePlantUML(EObject eObject);
 	
 	protected void resetCaches() {
 		id2ObjectMap = null;
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassAllReferencesBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassAllReferencesBuilder.java
index 157be29..0480aa8 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassAllReferencesBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassAllReferencesBuilder.java
@@ -22,6 +22,7 @@
 import java.util.Set;
 
 import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.EStructuralFeature.Setting;
@@ -63,6 +64,11 @@
 		return new BuilderResult(getId2ObjectMap(), plantuml.toString());
 	}
 
+	@Override
+	public BuilderResult generatePlantUML(EObject eObject) {
+		return generatePlantUML(eObject.eClass());
+	}
+	
 	private void populateSuperClasses(final StringBuilder plantuml, final EClass eClass) {
 
 		populateEClassReferences(plantuml, eClass);
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsAndHierarchyBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsAndHierarchyBuilder.java
index 513fd80..e9fdb9d 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsAndHierarchyBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsAndHierarchyBuilder.java
@@ -18,6 +18,7 @@
 import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
 
 public class EClassContentsAndHierarchyBuilder extends AbstractPlantUMLBuilder {
@@ -52,6 +53,11 @@
 		return new BuilderResult(getId2ObjectMap(), plantuml.toString());
 	}
 
+	@Override
+	public BuilderResult generatePlantUML(EObject eObject) {
+		return generatePlantUML(eObject.eClass());
+	}
+
 	private void populateSubClassInfo(final StringBuilder plantuml, final EClass eClass) {
 
 		for (final EClass subClass : BuilderUtil.getSubClasses(eClass)) {
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsFromReferenceBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsFromReferenceBuilder.java
index ecf17f4..203fb48 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsFromReferenceBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassContentsFromReferenceBuilder.java
@@ -18,6 +18,7 @@
 import org.eclipse.emf.ecore.EAttribute;
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
 
 public class EClassContentsFromReferenceBuilder extends AbstractPlantUMLBuilder {
@@ -48,6 +49,11 @@
 		return new BuilderResult(getId2ObjectMap(), plantuml.toString());
 	}
 
+	@Override
+	public BuilderResult generatePlantUML(EObject eObject) {
+		return generatePlantUML(eObject.eClass());
+	}
+
 	private void populateSubClassInfo(final StringBuilder plantuml, final EClass eClass) {
 
 		for (final EClass subClass : BuilderUtil.getSubClasses(eClass)) {
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassHierarchyBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassHierarchyBuilder.java
index 01e8518..cf8b598 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassHierarchyBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EClassHierarchyBuilder.java
@@ -18,6 +18,7 @@
 import java.util.Set;
 
 import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
 
 public class EClassHierarchyBuilder extends AbstractPlantUMLBuilder {
 
@@ -53,6 +54,11 @@
 		return new BuilderResult(getId2ObjectMap(), plantuml.toString());
 	}
 
+	@Override
+	public BuilderResult generatePlantUML(EObject eObject) {
+		return generatePlantUML(eObject.eClass());
+	}
+
 	private void populateSuperClasses(final StringBuilder plantuml, final EClass eClass) {
 		
 		for (final EClass superClass : eClass.getESuperTypes()) {
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EObjectRefsBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EObjectRefsBuilder.java
index 8bdf1b3..af73c89 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EObjectRefsBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/EObjectRefsBuilder.java
@@ -42,10 +42,13 @@
 		this.sync = sync;
 	}
 
+	// NOTE: EClass is an EObject
+	
 	@Override
 	public BuilderResult generatePlantUML(final EClass eObject) {
-		return null;
+		return generatePlantUML((EObject) eObject);
 	}
+	
 	@Override
 	public BuilderResult generatePlantUML(final EObject eObject) {
 
@@ -83,7 +86,7 @@
 		 *
 		 * Below code provides the possibility to specify the range
 		 */
-		if (allRefSettings.size() > 10) {
+		if (allRefSettings.size() > 100) {
 
 			if (sync != null) {
 				sync.syncExec(() -> {
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/ObjectContentBuilder.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/ObjectContentBuilder.java
index c07a8fc..6057aad 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/ObjectContentBuilder.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/builders/ObjectContentBuilder.java
@@ -46,9 +46,16 @@
 		}
 		return super.generatePlantUML(selectedObject);
 	}
+
+	// NOTE: EClass is an EObject
 	
 	@Override
 	public BuilderResult generatePlantUML(final EClass eObject) {
+		return generatePlantUML((EObject) eObject);
+	}
+
+	@Override
+	public BuilderResult generatePlantUML(final EObject eObject) {
 
 		resetCaches();
 		
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/AbstractPlantUMLHandler.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/AbstractPlantUMLHandler.java
index 5df6d84..3de0a86 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/AbstractPlantUMLHandler.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/AbstractPlantUMLHandler.java
@@ -84,20 +84,20 @@
 			String dotPath,
 			String genFolderPath,
 			EPartService partService,
-			Object eClass,
+			Object selected,
 			EObject eObject) {
 		
 		// check if there is a valid dot path
 		if (verifyDotPath(shell, dotPath)) {
 			
 			// generate UML
-			if (eClass != null) {
+			if (selected != null) {
 				
 				String genFolder = DiagramCreator.getGenFolder(genFolderPath, eObject != null ? eObject.eResource() : null);
 				if (genFolder == null || genFolder.length() == 0) {
 					openErrorDialog(shell, "Folder for diagram generation is not set. Configure a folder path in Preferences -> AMALTHEA Graphical Representation");
 					return;
-				}else if(!new File(genFolder).exists()) {
+				} else if (!new File(genFolder).exists()) {
 					openErrorDialog(shell, "Invalid folder path is specified. Configure a valid folder path in Preferences -> AMALTHEA Graphical Representation");
 					return;
 				}
@@ -105,12 +105,12 @@
 				// generate UML and SVG
 				Job job = Job.create("Generate diagram", monitor -> {
 					AbstractPlantUMLBuilder builder = createPlantUMLBuilder(sync);
-					BuilderResult result = builder.generatePlantUML(eObject);
+					BuilderResult result = builder.generatePlantUML(selected);
 					
 					LOGGER.info(result.getPlantUMLText());
 					
 					ExecutionUtil.setExecutionCategory(getExecutionCategory());
-					String fileNamePrefix = getFileNamePrefix(eObject != null ? eObject : eClass);
+					String fileNamePrefix = getFileNamePrefix(eObject != null ? eObject : selected);
 					String svgFilePath = DiagramCreator.generateSVG(result, genFolder, fileNamePrefix, eObject);
 					
 					sync.asyncExec(() -> {
@@ -133,10 +133,10 @@
 	
 	protected boolean verifyDotPath(Shell shell, String dotPath) {
 		if (dotPath == null) {
-			openErrorDialog(shell, "Missing Graphviz DOT.exe location in Preferences."+System.getProperty("line.separator")+"Please specify location via \"Window - Preferences - Plantuml - Path\" to the dot.exe file of Graphviz.");
+			openErrorDialog(shell, "Missing Graphviz DOT.exe location in Preferences."+System.getProperty("line.separator")+"Please specify location via \"Window - Preferences - PlantUML - Path to the dot executable of Graphviz.\"");
 			return false;
 		} else if (!new File(dotPath).exists()) {
-			openErrorDialog(shell, "Invalid path of Graphviz DOT.exe is present in Preferences."+System.getProperty("line.separator")+"Please specify valid path via \"Window - Preferences - Plantuml - Path\" to the dot.exe file of Graphviz.");
+			openErrorDialog(shell, "Invalid path of Graphviz DOT.exe is present in Preferences."+System.getProperty("line.separator")+"Please specify valid path via \"Window - Preferences - PlantUML - Path to the dot executable of Graphviz.\"");
 			return false;
 		}
 
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/EObjectRefsHandler.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/EObjectRefsHandler.java
index 846ae6b..1ecb788 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/EObjectRefsHandler.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/EObjectRefsHandler.java
@@ -80,6 +80,18 @@
 			@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
 			EPartService partService) {
 		
-		super.execute(shell, sync, dotPath, genFolderPath, selection, partService);
+		Object element = selection.getFirstElement();
+		if (element instanceof EObject) {
+			execute(
+					shell,
+					sync,
+					dotPath,
+					genFolderPath,
+					partService,
+					element,
+					(EObject)element);
+		} else {
+			openErrorDialog(shell);
+		}
 	}
 }
diff --git a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/ObjectContentHandler.java b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/ObjectContentHandler.java
index dc078e4..0708012 100644
--- a/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/ObjectContentHandler.java
+++ b/eclipse-tools/emf-graphical-viewer/plugins/org.eclipse.app4mc.emf.viewer.plantuml/src/org/eclipse/app4mc/emf/viewer/plantuml/handlers/ObjectContentHandler.java
@@ -30,6 +30,7 @@
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.Shell;
 
@@ -81,6 +82,18 @@
 			@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
 			EPartService partService) {
 		
-		super.execute(shell, sync, dotPath, genFolderPath, selection, partService);
+		Object element = selection.getFirstElement();
+		if (element instanceof EObject) {
+			execute(
+					shell,
+					sync,
+					dotPath,
+					genFolderPath,
+					partService,
+					element,
+					(EObject)element);
+		} else {
+			openErrorDialog(shell);
+		}
 	}
 }