initial plugin manifest addition: declares view and action in popup menu
[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.views.PHPConsole;
19
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.ui.IWorkbenchWindow;
24 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
25
26 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
27   protected IWorkbenchWindow activeWindow = null;
28
29   public void run(IAction action) {
30     final IPreferenceStore store =
31       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 =
37       new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
38     execute(
39       "apache_start",
40       store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
41       form.format(arguments),
42       store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
43   }
44
45   /**
46          * Executes an external progam and saves the LaunchConfiguration under external tools 
47          * @param command external tools command name
48          * @param executable executable path i.e.c:\apache\apache.exe
49          * @param arguments arguments for this configuration
50          * @param background run this configuration in background mode
51          */
52   public static void execute(
53     String command,
54     String executable,
55     String arguments,
56     boolean background) {
57     PHPConsole console = PHPConsole.getInstance();
58     String consoleMessage;
59     if (background) {
60       consoleMessage =
61         "run in background mode-"
62           + command
63           + ": "
64           + executable
65           + " "
66           + arguments;
67     } else {
68       consoleMessage =
69         "run in foreground mode-"
70           + command
71           + ": "
72           + executable
73           + " "
74           + arguments;
75     }
76     console.write(consoleMessage + "\n");
77
78     ExternalToolsUtil.execute(command, executable, arguments, background);
79   }
80   
81   public void selectionChanged(IAction action, ISelection selection) {
82
83   }
84
85   public void init(IWorkbenchWindow window) {
86     this.activeWindow = window;
87   }
88
89   public void dispose() {
90
91   }
92
93 }