misc changes
[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.text.MessageFormat;
15
16 import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18 import net.sourceforge.phpeclipse.ui.WebUI;
19 import net.sourceforge.phpeclipse.views.PHPConsole;
20
21 import org.eclipse.jface.action.IAction;
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 =
32       PHPeclipsePlugin.getDefault().getPreferenceStore();
33     String documentRoot = store.getString(WebUI.PHP_DOCUMENTROOT_PREF);
34     // replace backslash with slash in the DocumentRoot under Windows
35     documentRoot = documentRoot.replace('\\', '/');
36     String[] arguments = { documentRoot };
37     MessageFormat form =
38       new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
39     execute(
40       "apache_start",
41       store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
42       form.format(arguments),
43       store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
44   }
45
46   /**
47          * Executes an external progam and saves the LaunchConfiguration under external tools 
48          * @param command external tools command name
49          * @param executable executable path i.e.c:\apache\apache.exe
50          * @param arguments arguments for this configuration
51          * @param background run this configuration in background mode
52          */
53   public static void execute(
54     String command,
55     String executable,
56     String arguments,
57     boolean background) {
58     PHPConsole console = PHPConsole.getInstance();
59     String consoleMessage;
60     if (background) {
61       consoleMessage =
62         "run in background mode-"
63           + command
64           + ": "
65           + executable
66           + " "
67           + arguments;
68     } else {
69       consoleMessage =
70         "run in foreground mode-"
71           + command
72           + ": "
73           + executable
74           + " "
75           + arguments;
76     }
77     console.write(consoleMessage + "\n");
78
79     ExternalToolsUtil.execute(command, executable, arguments, background);
80   }
81   
82   public void selectionChanged(IAction action, ISelection selection) {
83
84   }
85
86   public void init(IWorkbenchWindow window) {
87     this.activeWindow = window;
88   }
89
90   public void dispose() {
91
92   }
93
94 }