fixed bug #1263858
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / actions / PHPStartApacheAction.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made
3  * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  *
6  * Contributors: IBM Corporation - Initial implementation www.phpeclipse.de
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.externaltools.actions;
9
10 import java.text.MessageFormat;
11
12 import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
13 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
14 import net.sourceforge.phpeclipse.ui.WebUI;
15
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
21
22 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
23   protected IWorkbenchWindow activeWindow = null;
24
25   public void run(IAction action) {
26         final IPreferenceStore webUIStore = WebUI.getDefault().getPreferenceStore();
27
28         String documentRoot = webUIStore.getString(WebUI.PHP_DOCUMENTROOT_PREF);
29     final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore();
30
31     // replace backslash with slash in the DocumentRoot under Windows
32     documentRoot = documentRoot.replace('\\', '/');
33     String[] arguments = { documentRoot };
34     MessageFormat form = new MessageFormat(store.getString(ExternalToolsPlugin.APACHE_START_PREF));
35     execute("apache_start", store.getString(ExternalToolsPlugin.APACHE_RUN_PREF), form.format(arguments), store
36         .getBoolean(ExternalToolsPlugin.APACHE_START_BACKGROUND));
37   }
38
39   /**
40    * Executes an external progam and saves the LaunchConfiguration under external tools
41    *
42    * @param command
43    *          external tools command name
44    * @param executable
45    *          executable path i.e.c:\apache\apache.exe
46    * @param arguments
47    *          arguments for this configuration
48    * @param background
49    *          run this configuration in background mode
50    */
51   public static void execute(String command, String executable, String arguments, boolean background) {
52 //    PHPConsole console = new PHPConsole();
53 //    String consoleMessage;
54 //    if (background) {
55 //      consoleMessage = "run in background mode-" + command + ": " + executable + " " + arguments;
56 //    } else {
57 //      consoleMessage = "run in foreground mode-" + command + ": " + executable + " " + arguments;
58 //    }
59 //    console.println(consoleMessage);
60
61     ExternalToolsUtil.execute(command, executable, arguments, background);
62   }
63
64   public void selectionChanged(IAction action, ISelection selection) {
65
66   }
67
68   public void init(IWorkbenchWindow window) {
69     this.activeWindow = window;
70   }
71
72   public void dispose() {
73
74   }
75
76 }