7f698838abd95b90582050cc87252c3c3257ca84
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPStartApacheAction.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9     IBM Corporation - Initial implementation
10     Klaus Hartlage - www.eclipseproject.de
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.actions;
13
14 import java.io.BufferedReader;
15 import java.io.IOException;
16 import java.io.InputStreamReader;
17 import java.text.MessageFormat;
18
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
26
27 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
28         protected IWorkbenchWindow activeWindow = null;
29
30         public void run(IAction action) {
31                 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
32                 String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
33                 // replace backslash with slash in the DocumentRoot under Windows
34                 documentRoot = documentRoot.replace('\\', '/');
35                 String[] arguments = { documentRoot };
36                 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
37                 execute(form.format(arguments));
38         }
39
40         public void execute(String command) {
41 //              MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
42                 try {
43                         Runtime runtime = Runtime.getRuntime();
44                         //      Process process = runtime.exec(new String[] { "c:\\apache\\apache.exe" });
45                         Process process = runtime.exec(command);
46                 } catch (IOException e) {
47                         MessageDialog.openInformation(activeWindow.getShell(), "IOException: ", e.getMessage());
48                 }
49         }
50
51         public void selectionChanged(IAction action, ISelection selection) {
52
53         }
54
55         public void init(IWorkbenchWindow window) {
56                 this.activeWindow = window;
57         }
58
59         public void dispose() {
60
61         }
62 }