1) Fixed stackoverflow when clicking on entry in PHPeclipse Error Log: OverrideIndica...
[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 //import net.sourceforge.phpeclipse.ui.WebUI;
16
17 import org.eclipse.jface.action.IAction;
18 import org.eclipse.jface.preference.IPreferenceStore;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.ui.IWorkbenchWindow;
21 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
22
23 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
24         protected IWorkbenchWindow activeWindow = null;
25
26         public void run(IAction action) {
27                 final IPreferenceStore webUIStore = WebUI.getDefault()
28                                 .getPreferenceStore();
29
30                 String documentRoot = webUIStore.getString(WebUI.PHP_DOCUMENTROOT_PREF);
31                 final IPreferenceStore store = ExternalToolsPlugin.getDefault()
32                                 .getPreferenceStore();
33
34                 // replace backslash with slash in the DocumentRoot under Windows
35                 documentRoot = documentRoot.replace('\\', '/');
36                 String[] arguments = { documentRoot };
37                 MessageFormat form = new MessageFormat(store
38                                 .getString(ExternalToolsPlugin.APACHE_START_PREF));
39                 execute("apache_start", store
40                                 .getString(ExternalToolsPlugin.APACHE_RUN_PREF), form
41                                 .format(arguments), store
42                                 .getBoolean(ExternalToolsPlugin.APACHE_START_BACKGROUND));
43         }
44
45         /**
46          * Executes an external progam and saves the LaunchConfiguration under
47          * external tools
48          * 
49          * @param command
50          *            external tools command name
51          * @param executable
52          *            executable path i.e.c:\apache\apache.exe
53          * @param arguments
54          *            arguments for this configuration
55          * @param background
56          *            run this configuration in background mode
57          */
58         public static void execute(String command, String executable,
59                         String arguments, boolean background) {
60                 // PHPConsole console = new PHPConsole();
61                 // String consoleMessage;
62                 // if (background) {
63                 // consoleMessage = "run in background mode-" + command + ": " +
64                 // executable + " " + arguments;
65                 // } else {
66                 // consoleMessage = "run in foreground mode-" + command + ": " +
67                 // executable + " " + arguments;
68                 // }
69                 // console.println(consoleMessage);
70
71                 ExternalToolsUtil.execute(command, executable, arguments, background);
72         }
73
74         public void selectionChanged(IAction action, ISelection selection) {
75
76         }
77
78         public void init(IWorkbenchWindow window) {
79                 this.activeWindow = window;
80         }
81
82         public void dispose() {
83
84         }
85
86 }