Refactory: debug UI plugin.
[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()
27                                 .getPreferenceStore();
28
29                 String documentRoot = webUIStore.getString(WebUI.PHP_DOCUMENTROOT_PREF);
30                 final IPreferenceStore store = ExternalToolsPlugin.getDefault()
31                                 .getPreferenceStore();
32
33                 // replace backslash with slash in the DocumentRoot under Windows
34                 documentRoot = documentRoot.replace('\\', '/');
35                 String[] arguments = { documentRoot };
36                 MessageFormat form = new MessageFormat(store
37                                 .getString(ExternalToolsPlugin.APACHE_START_PREF));
38                 execute("apache_start", store
39                                 .getString(ExternalToolsPlugin.APACHE_RUN_PREF), form
40                                 .format(arguments), store
41                                 .getBoolean(ExternalToolsPlugin.APACHE_START_BACKGROUND));
42         }
43
44         /**
45          * Executes an external progam and saves the LaunchConfiguration under
46          * external tools
47          * 
48          * @param command
49          *            external tools command name
50          * @param executable
51          *            executable path i.e.c:\apache\apache.exe
52          * @param arguments
53          *            arguments for this configuration
54          * @param background
55          *            run this configuration in background mode
56          */
57         public static void execute(String command, String executable,
58                         String arguments, boolean background) {
59                 // PHPConsole console = new PHPConsole();
60                 // String consoleMessage;
61                 // if (background) {
62                 // consoleMessage = "run in background mode-" + command + ": " +
63                 // executable + " " + arguments;
64                 // } else {
65                 // consoleMessage = "run in foreground mode-" + command + ": " +
66                 // executable + " " + arguments;
67                 // }
68                 // console.println(consoleMessage);
69
70                 ExternalToolsUtil.execute(command, executable, arguments, background);
71         }
72
73         public void selectionChanged(IAction action, ISelection selection) {
74
75         }
76
77         public void init(IWorkbenchWindow window) {
78                 this.activeWindow = window;
79         }
80
81         public void dispose() {
82
83         }
84
85 }