Refactory.
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / actions / PHPStartXAMPPAction.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.io.File;
11
12 import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
13 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
14
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
20
21 public class PHPStartXAMPPAction implements IWorkbenchWindowActionDelegate {
22         protected IWorkbenchWindow activeWindow = null;
23
24         public void run(IAction action) {
25                 final IPreferenceStore store = ExternalToolsPlugin.getDefault()
26                                 .getPreferenceStore();
27                 String executable = store
28                                 .getString(ExternalToolsPlugin.XAMPP_START_PREF);
29                 String workingDirectory = null;
30                 if (executable != null && executable.length() > 0) {
31                         int index = executable.lastIndexOf(File.separatorChar);
32                         if (index > 0) {
33                                 workingDirectory = executable.substring(0, index);
34                         }
35                 }
36                 execute("xampp_start", executable, workingDirectory, true);
37         }
38
39         /**
40          * Executes an external progam and saves the LaunchConfiguration under
41          * external tools
42          * 
43          * @param command
44          *            external tools command name
45          * @param executable
46          *            executable path i.e.c:\apache\apache.exe
47          * @param background
48          *            run this configuration in background mode
49          */
50         public static void execute(String command, String executable,
51                         String workingDirectory, boolean background) {
52                 // PHPConsole console = new PHPConsole();
53                 // String consoleMessage;
54                 // if (background) {
55                 // consoleMessage = "run in background mode-" + command + ": " +
56                 // executable;
57                 // } else {
58                 // consoleMessage = "run in foreground mode-" + command + ": " +
59                 // executable;
60                 // }
61                 // console.println(consoleMessage);
62
63                 ExternalToolsUtil.execute(command, executable, workingDirectory, null,
64                                 background);
65         }
66
67         public void selectionChanged(IAction action, ISelection selection) {
68
69         }
70
71         public void init(IWorkbenchWindow window) {
72                 this.activeWindow = window;
73         }
74
75         public void dispose() {
76
77         }
78
79 }