package org.bonitasoft.studio.application.actions;
import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.application.actions.wizards.OpenProcessWizard;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.jface.CustomWizardDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.repository.ProcessArtifact;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class OpenProcessCommandHandler extends AbstractHandler implements IHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
final OpenProcessWizard wizard = new OpenProcessWizard(false);
new CustomWizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
wizard, Messages.OpenProcessButtonLabel).open();
IProgressService progressManager = PlatformUI.getWorkbench().getProgressService() ;
IRunnableWithProgress runnable = new IRunnableWithProgress(){
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
monitor.beginTask("Opening Process...", wizard.getProcessArtifact().size()*5) ; //$NON-NLS-1$
for(ProcessArtifact artifact : wizard.getProcessArtifact()){
artifact.open(monitor) ;
}
monitor.done();
}
};
try {
if(!wizard.getProcessArtifact().isEmpty())
progressManager.run(false, false, runnable);
} catch (Exception e) {
BonitaStudioLog.log(e);
}
return null;
}
}
|