/* * Created on Jun 20, 2003 * V1.1 Edited by Jing Cao * - Fixed functionality so that it now will work when there's a space in path name of eclipse. */ package ggad.buttons; import java.io.File; import java.io.FileWriter; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; import CDBuilder.console.ConsoleDocument; import CDBuilder.console.StreamHandler; /** * @author ssim * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class GGADEXE extends Action implements IWorkbenchWindowActionDelegate{ IContainer container; IPath internalPath; public GGADEXE() { super(); setText("Simulate"); setDescription("This is a Simulator"); } class RunSimu extends Thread { private IPath internalPath; public RunSimu(IPath internalPath) { this.internalPath = internalPath; } public void run() { try { ConsoleDocument cdos = ConsoleDocument.getCDOS(); IPath GGADpath = internalPath.removeLastSegments(1).append("/GGAD/"); IPath path = internalPath.removeLastSegments(3).append("/workspace/"); FileWriter tempFile = new FileWriter(path.append("tempSimu.bat").toString()); //testing purposes tempFile.write("GGadTool.exe"); //internalPath is where the cd++.exe is located tempFile.close(); //added quotes to allow functinality with spaces in file path. Process simuProcess = Runtime.getRuntime().exec("cmd /c \"" + path.toString() + "tempSimu.bat\"", null, new File(GGADpath.toString())); StreamHandler outputHandler = new StreamHandler(simuProcess.getInputStream(), "OUTPUT", true); StreamHandler errorHandler = new StreamHandler(simuProcess.getErrorStream(), "ERROR", true); outputHandler.start(); errorHandler.start(); simuProcess.waitFor(); new File ( path.toString() + "tempSimu.bat" ).delete(); int exitVal = simuProcess.waitFor(); }catch (Throwable T) { T.printStackTrace(); } } } public void run() { try { //show console view PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("ConsoleView"); ConsoleDocument cdos = ConsoleDocument.getCDOS(); IWorkspaceRoot root = (IWorkspaceRoot)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getInput(); //get internal path IPath internalPath = root.getLocation().removeLastSegments(1); internalPath = internalPath.append("/plugins/CD++Builder_1.1.0/internal/"); System.out.println("Internal Path: " + internalPath); cdos.clear(); RunSimu rsimu = new RunSimu(internalPath); rsimu.start(); }catch (Exception np) { np.printStackTrace(); MessageBox npGui = new MessageBox(new Shell(), SWT.ICON_ERROR | SWT.OK); npGui.setMessage("could dnot start GGAD"); npGui.setText("ERROR!"); npGui.open(); ConsoleDocument.getCDOS().set("could not start GGAD"); } } public void run(IAction action) { run(); } public void dispose() { // do nothing. } public void init(IWorkbenchWindow window) { // do nothing. } public void selectionChanged(IAction action, ISelection selection) { } }