added support to consider DOT.exe location from 'GRAPHVIZ_DOT' environment variable
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 3de0a86..036126d 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
@@ -88,7 +88,7 @@ EObject eObject) { // check if there is a valid dot path - if (verifyDotPath(shell, dotPath)) { + if (verifyDotPath(shell, sync, dotPath)) { // generate UML if (selected != null) { @@ -130,20 +130,60 @@ } } } - - 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 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 executable of Graphviz.\""); - return false; + + protected boolean verifyDotPath(Shell shell, UISynchronize sync, String dotPathFromPlantUMLPreferencePage) { + + String dotPathFromSystemProperty = System.getenv("GRAPHVIZ_DOT"); + + File dotFile = null; + + if (dotPathFromPlantUMLPreferencePage != null) { + dotFile = ensureValidDotFile(shell, sync, dotPathFromPlantUMLPreferencePage, "PlantUMLPreference"); + } else if (dotPathFromSystemProperty != null) { + dotFile = ensureValidDotFile(shell, sync, dotPathFromSystemProperty, "SystemProperty"); + } else { + showErrorDialog(shell, sync, "Missing Graphviz dot.exe location." + + "\nPlease specify location via Window - Preferences - PlantUML - Path to the dot executable of Graphviz."); } - System.setProperty("GRAPHVIZ_DOT", dotPath); + if (dotFile == null) + return false; + + System.setProperty("GRAPHVIZ_DOT", dotFile.getAbsolutePath()); return true; } + + private File ensureValidDotFile(Shell shell, UISynchronize sync, String dotPath, String origin) { + + + if (dotPath == null || dotPath.equals("")) { + showErrorDialog(shell, sync, "Missing Graphviz dot.exe location." + + "\nPlease specify location via Window - Preferences - PlantUML - Path to the dot executable of Graphviz."); + return null; + } + + final File dotFile = new File(dotPath); + if (!dotFile.canExecute()) { + + if(origin.equals("PlantUMLPreference")) { + showErrorDialog(shell, sync, "Invalid Graphviz dot.exe location: \'" + dotFile.getAbsolutePath()+"\'" + + "\nPlease set location via Window - Preferences - PlantUML - Path to the 'dot executable of Graphviz'."); + }else { + showErrorDialog(shell, sync, "Invalid Graphviz dot.exe location found in System Property 'GRAPHVIZ_DOT' : \'" + dotFile.getAbsolutePath()+"\'" + + "\nPlease update the System Property 'GRAPHVIZ_DOT' with valid Path to the 'dot executable of Graphviz'."); + } + return null; + } + + return dotFile; + } + + private void showErrorDialog(Shell shell, UISynchronize sync, String message) { + sync.asyncExec(() -> + MessageDialog.openError(shell, "AMALTHEA HW Visualization", message) + ); + } protected void openErrorDialog(Shell shell) { openErrorDialog(shell, "Selected object is not a EMF object");