Fix #759.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / php / launching / PHPMainTab.java
index 03e5e3e..ac4628a 100644 (file)
@@ -1,14 +1,19 @@
 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
 
+import java.io.File;
+//import java.text.MessageFormat;
+
 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 import net.sourceforge.phpdt.internal.ui.util.PHPFileSelector;
 import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector;
-import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
+//import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants;
+//import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -28,11 +33,11 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
 
 public class PHPMainTab extends AbstractLaunchConfigurationTab {
 
@@ -48,7 +53,6 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
        private Button fUseDefaultInterpreterButton;
        private Button fInterpreterButton;
        private Text fInterpreterText;
-       private Label fInterpreterLabel;
 
        public PHPMainTab() {
                super();
@@ -140,14 +144,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
                layout.numColumns = 2;
                interpreterGroup.setLayout(layout);
                interpreterGroup.setFont(font);
-               
-//             fInterpreterLabel= new Label(interpreterGroup, SWT.NONE);
-//             fInterpreterLabel.setText("Interpreter: "); 
-//             gd= new GridData();
-//             gd.horizontalSpan = 2;
-//             fInterpreterLabel.setLayoutData(gd);
-//             fInterpreterLabel.setFont(font);
-               
+                               
                fInterpreterText= new Text(interpreterGroup, SWT.SINGLE | SWT.BORDER);
                gd= new GridData(GridData.FILL_HORIZONTAL);
                fInterpreterText.setLayoutData(gd);
@@ -220,7 +217,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
        }
 
        protected IProject getContext() {
-               IWorkbenchPage page= XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+               IWorkbenchPage page= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                if (page != null) {
                        ISelection selection = page.getSelection();
                        if (selection instanceof IStructuredSelection) {
@@ -242,6 +239,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
                }
                return null;
        }
+       
 
        public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
                IProject project = getContext();
@@ -254,7 +252,7 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
                try {
                        String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
                        if (project != null) {
-                       projectSelector.setSelectionText(project);
+                               projectSelector.setSelectionText(project);
                        }
                        String file = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null);
                        if (file != null) {
@@ -292,26 +290,35 @@ public class PHPMainTab extends AbstractLaunchConfigurationTab {
         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
         */
        public boolean isValid(ILaunchConfiguration launchConfig) {
-               try {
-
-                       String projectName = launchConfig.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, "");
-                       if (projectName.length() == 0) {
-                               setErrorMessage("Iinvalid Project");
+               setErrorMessage(null);
+               String projectName=projectSelector.getSelectionText().trim();
+               IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+               if (!project.exists()) {
+                       setErrorMessage("Project does not exist");
+                       return false;
+               }
+               String fileString=fileSelector.getSelectionText().trim();
+               if (!"".equals(fileString)) {
+                       IFile file=project.getFile(fileSelector.getSelectionText().trim());
+                       if (!file.exists()) {
+                               setErrorMessage("File does not exist");
                                return false;
                        }
-
-                       String fileName = launchConfig.getAttribute(IXDebugConstants.ATTR_PHP_FILE, "");
-                       if (fileName.length() == 0) {
-                               setErrorMessage("Invalid File");
+               } else {
+                       setErrorMessage("File does not exist");
+                       return false;
+               }
+               if (!fUseDefaultInterpreterButton.getSelection()) {             
+                       File exe = new File(fInterpreterText.getText());
+                       System.out.println(exe.toString());
+                       if (!exe.exists()) {
+                               setErrorMessage("Invalid Interpreter");
                                return false;
                        }
-               } catch (CoreException e) {
-//                     XDebugCorePlugin.log(e);
                }
-
-               setErrorMessage(null);
-               return super.isValid(launchConfig);
+               return true;
        }
+       
        public Image getImage() {
                return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
        }