package eu.scasefp7.eclipse.core.handlers;

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.services.IServiceLocator;

import eu.scasefp7.eclipse.core.Activator;

/**
 * Abstract handler with a convenience method to execute other commands.
 * 
 * @author themis
 */
public abstract class CommandExecutorHandler extends ProjectAwareHandler {

	/**
	 * Executes an existing command.
	 * 
	 * @param commandId the id of the command to be executed, which can reside in other plugins.
	 */
	protected void executeCommand(String commandId) {
		IServiceLocator serviceLocator = PlatformUI.getWorkbench();
		ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
		try {
			Command command = commandService.getCommand(commandId);
			command.executeWithChecks(new ExecutionEvent());
		} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
		    Activator.log("Unable to execute command " + commandId, e);
		}
	}

}
@@ -749,26 +749,240 @@
 es a
-n existing command
+ command if it exists. Returns %7B@code true%7D if the command exists or %7B@code false%7D otherwise. Note that%0D%0A%09 * if the command exists but is not executed correctly (e.g. it is not enabled), this function still returns%0D%0A%09 * %7B@code true%7D
 .%0D%0A%09
@@ -1081,16 +1081,92 @@
 ugins.%0D%0A
+%09 * @return %7B@code true%7D if the command exists or %7B@code false%7D otherwise.%0D%0A
 %09 */%0D%0A%09p
@@ -1178,12 +1178,15 @@
 ted 
-void
+boolean
  exe
@@ -1385,16 +1385,85 @@
 lass);%0D%0A
+%09%09if (commandService.getDefinedCommandIds().contains(commandId)) %7B%0D%0A%09
 %09%09try %7B%0D
@@ -1463,16 +1463,17 @@
 %09try %7B%0D%0A
+%09
 %09%09%09Comma
@@ -1524,16 +1524,17 @@
 ndId);%0D%0A
+%09
 %09%09%09comma
@@ -1580,16 +1580,17 @@
 ());%0D%0A%09%09
+%09
 %7D catch 
@@ -1687,12 +1687,10 @@
 %0D%0A%09%09
-    
+%09%09
 Acti
@@ -1748,17 +1748,63 @@
  e);%0D%0A%09%09
-%7D
+%09%7D%0D%0A%09%09%09return true;%0D%0A%09%09%7D else%0D%0A%09%09%09return false;
 %0D%0A%09%7D%0D%0A%0D%0A

Check whether the commands to be executed exist