Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / launcher / PHPEnvironmentTab.java
index 877147d..87e8a33 100644 (file)
@@ -33,7 +33,8 @@ import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
+//import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -62,6 +63,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
        protected Button fOpenDBGSessionInBrowserCheckBox;
 
+       protected Button fOpenDBGSessionInExternalBrowserCheckBox;
+
        protected Button fPathMapRemoveButton;
 
        protected Button fPathMapAddButton;
@@ -74,6 +77,10 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
        protected TabFolder tabFolder;
 
+       private Text targetFile;
+
+       private String originalFileName = "";
+
        private class RemoteDebugTabListener extends SelectionAdapter implements
                        ModifyListener {
 
@@ -84,6 +91,7 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                 */
                public void modifyText(ModifyEvent e) {
                        updateLaunchConfigurationDialog();
+                       makeupTargetFile();
                }
 
                /*
@@ -105,11 +113,12 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                                setRemoteTabEnableState();
                        } else if (source == fRemoteDebugTranslate) {
                                setRemoteTabEnableState();
+                       } else if (source == fOpenDBGSessionInBrowserCheckBox) {
+                               setRemoteTabEnableState();
                        } else {
                                updateLaunchConfigurationDialog();
-                               ;
                        }
-
+                       makeupTargetFile();
                }
 
        }
@@ -124,6 +133,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
        private static final boolean DEFAULT_OPEN_DBGSESSION_IN_BROWSER = true;
 
+       private static final boolean DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER = false;
+
        static String[] columnTitles = {
                        PHPDebugUiMessages
                                        .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
@@ -142,8 +153,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                tabFolder.setLayoutData(gridData);
 
                // addLoadPathTab(tabFolder);
-               addInterpreterTab(tabFolder);
                addRemoteDebugTab(tabFolder);
+               addInterpreterTab(tabFolder);
        }
 
        protected void addRemoteDebugTab(TabFolder tabFolder) {
@@ -183,6 +194,18 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                                GridData.HORIZONTAL_ALIGN_BEGINNING));
                fOpenDBGSessionInBrowserCheckBox.addSelectionListener(fListener);
 
+               // addendum
+               fOpenDBGSessionInExternalBrowserCheckBox = new Button(comp, SWT.CHECK);
+               fOpenDBGSessionInExternalBrowserCheckBox
+                               .setText(PHPDebugUiMessages
+                                               .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInExternalBrowserCheckBox.label"));
+               fOpenDBGSessionInExternalBrowserCheckBox.setLayoutData(new GridData(
+                               SWT.BEGINNING));
+               ((GridData) fOpenDBGSessionInExternalBrowserCheckBox.getLayoutData()).horizontalIndent = 16;
+               fOpenDBGSessionInExternalBrowserCheckBox
+                               .addSelectionListener(fListener);
+               // addendum
+
                label = new Label(comp, SWT.NONE);
                label
                                .setText(PHPDebugUiMessages
@@ -192,6 +215,34 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                fRemoteSourcePath.setLayoutData(gd);
                fRemoteSourcePath.addModifyListener(fListener);
 
+               // addendum - make an effect of RemoteSourcePath clear
+               Composite targetComp = new Composite(comp, SWT.NONE);
+               targetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+               GridLayout targetLayout = new GridLayout(4, false);
+               targetLayout.marginHeight = 0;
+               targetLayout.marginWidth = 3;
+               targetComp.setLayout(targetLayout);
+               Color targetColor = new Color(null, 160, 160, 160);
+               Label label_lp = new Label(targetComp, SWT.NONE);
+               label_lp.setText("(");
+               label_lp.setForeground(targetColor);
+               label_lp.setLayoutData(new GridData(GridData.BEGINNING));
+               Label targetLabel = new Label(targetComp, SWT.NONE);
+               targetLabel
+                               .setText(PHPDebugUiMessages
+                                               .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.TargetFile.label"));
+               targetLabel.setForeground(targetColor);
+               targetLabel.setLayoutData(new GridData(GridData.BEGINNING));
+               targetFile = new Text(targetComp, SWT.SINGLE);
+               targetFile.setForeground(targetColor);
+               targetFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+               targetFile.setEditable(false);
+               Label label_rp = new Label(targetComp, SWT.NONE);
+               label_rp.setText(")");
+               label_rp.setForeground(targetColor);
+               label_rp.setLayoutData(new GridData(GridData.END));
+               // addendum
+
                createVerticalSpacer(comp, 1);
 
                Composite pathMapComp = new Composite(comp, SWT.NONE);
@@ -322,6 +373,7 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                        fPathMapRemoveButton.setEnabled(false);
                        fPathMapAddButton.setEnabled(false);
                        fOpenDBGSessionInBrowserCheckBox.setEnabled(false);
+                       fOpenDBGSessionInExternalBrowserCheckBox.setEnabled(false);
                } else {
                        setPathMapButtonsEnableState();
                }
@@ -338,6 +390,8 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                //
                if (fRemoteDebugCheckBox.getSelection()) {
                        fOpenDBGSessionInBrowserCheckBox.setEnabled(true);
+                       fOpenDBGSessionInExternalBrowserCheckBox
+                                       .setEnabled(fOpenDBGSessionInBrowserCheckBox.getSelection());
                        fRemoteDebugTranslate.setEnabled(true);
                        int selectCount = this.fRemoteDebugPathMapTable
                                        .getSelectionIndices().length;
@@ -425,29 +479,29 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
        // is customizable on the configuration
        // }
 
-       protected SelectionListener getLoadPathSelectionListener() {
-               return new SelectionAdapter() {
-                       public void widgetSelected(SelectionEvent e) {
-                               System.out.println("Loadpath list selection occurred: "
-                                               + e.getSource());
-                       }
-               };
-       }
-
-       protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
-               return new SelectionAdapter() {
-                       public void widgetSelected(SelectionEvent e) {
-                               setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
-                       }
-               };
-       }
+//     protected SelectionListener getLoadPathSelectionListener() {
+//             return new SelectionAdapter() {
+//                     public void widgetSelected(SelectionEvent e) {
+//                             System.out.println("Loadpath list selection occurred: "
+//                                             + e.getSource());
+//                     }
+//             };
+//     }
+
+//     protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
+//             return new SelectionAdapter() {
+//                     public void widgetSelected(SelectionEvent e) {
+//                             setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
+//                     }
+//             };
+//     }
 
        protected void addInterpreterTab(TabFolder tabFolder) {
                Composite interpreterComposite = new Composite(tabFolder, SWT.NONE);
                GridLayout layout = new GridLayout();
                layout.numColumns = 2;
-//             layout.marginHeight = 0;
-//             layout.marginWidth = 0;
+               // layout.marginHeight = 0;
+               // layout.marginWidth = 0;
                interpreterComposite.setLayout(layout);
                interpreterComposite.setLayoutData(new GridData(
                                GridData.FILL_HORIZONTAL));
@@ -520,7 +574,7 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                                IProject project = ResourcesPlugin.getWorkspace().getRoot()
                                                .getProject(projectName);
                                if (project != null) {
-                                       IPath remotePath = project.getLocation();
+                                       IPath remotePath = project.getFullPath();
                                        String fileName = configuration.getAttribute(
                                                        PHPLaunchConfigurationAttribute.FILE_NAME, "");
                                        if (fileName != "") {
@@ -534,8 +588,7 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                                }
                        }
                } catch (CoreException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       log(e);
                }
        }
 
@@ -553,6 +606,7 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                } catch (CoreException ce) {
                        fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
                }
+               tabFolder.setSelection(fRemoteDebugCheckBox.getSelection() ? 0 : 1);
                try {
                        fRemoteDebugTranslate.setSelection(configuration.getAttribute(
                                        PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
@@ -570,7 +624,19 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                        fOpenDBGSessionInBrowserCheckBox
                                        .setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
                }
+               try {
+                       fOpenDBGSessionInExternalBrowserCheckBox
+                                       .setSelection(configuration
+                                                       .getAttribute(
+                                                                       PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
+                                                                       DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER));
+               } catch (CoreException ce) {
+                       fOpenDBGSessionInExternalBrowserCheckBox
+                                       .setSelection(DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER);
+               }
+
                setRemoteTabEnableState();
+
                try {
                        fRemoteSourcePath.setText(configuration.getAttribute(
                                        PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
@@ -580,6 +646,14 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
                updatePathMapFromConfig(configuration);
 
+               try {
+                       originalFileName = configuration.getAttribute(
+                                       PHPLaunchConfigurationAttribute.FILE_NAME, "");
+                       makeupTargetFile();
+               } catch (CoreException ce) {
+                       originalFileName = "";
+               }
+
        }
 
        private void updatePathMapFromConfig(ILaunchConfiguration config) {
@@ -637,10 +711,10 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
        // }
        // }
 
-       protected void setUseLoadPathDefaults(boolean useDefaults) {
-               loadPathListViewer.getList().setEnabled(!useDefaults);
-               // loadPathDefaultButton.setSelection(useDefaults);
-       }
+//     protected void setUseLoadPathDefaults(boolean useDefaults) {
+//             loadPathListViewer.getList().setEnabled(!useDefaults);
+//             // loadPathDefaultButton.setSelection(useDefaults);
+//     }
 
        protected void initializeInterpreterSelection(
                        ILaunchConfiguration configuration) {
@@ -651,8 +725,16 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                } catch (CoreException e) {
                        log(e);
                }
-               if (interpreterName != null && !interpreterName.equals(""))
+               if (interpreterName != null && !interpreterName.equals("")) {
                        interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
+               }
+               if (interpreterCombo.getSelectionIndex() < 0) {
+                       // previous definition had been deleted
+                       ((ILaunchConfigurationWorkingCopy) configuration).setAttribute(
+                                       PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
+                       setErrorMessage(PHPDebugUiMessages
+                                       .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
+               }
        }
 
        protected void initializeInterpreterCombo(Combo interpreterCombo) {
@@ -714,6 +796,10 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                configuration.setAttribute(
                                PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
                                fOpenDBGSessionInBrowserCheckBox.getSelection());
+               configuration
+                               .setAttribute(
+                                               PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
+                                               fOpenDBGSessionInExternalBrowserCheckBox.getSelection());
        }
 
        protected Composite createPageRoot(Composite parent) {
@@ -749,12 +835,15 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
 
        public boolean isValid(ILaunchConfiguration launchConfig) {
                try {
-                       String selectedInterpreter = launchConfig.getAttribute(
-                                       PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
-                       if (selectedInterpreter.length() == 0) {
-                               setErrorMessage(PHPDebugUiMessages
-                                               .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
-                               return false;
+                       if (launchConfig.getAttribute(
+                                       PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "")
+                                       .equals("")) {
+                               if (!launchConfig.getAttribute(
+                                               PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false)) {
+                                       setErrorMessage(PHPDebugUiMessages
+                                                       .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
+                                       return false;
+                               }
                        }
                } catch (CoreException e) {
                        log(e);
@@ -772,4 +861,63 @@ public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
                return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
        }
 
+       private void makeupTargetFile() {
+               if (!fRemoteDebugCheckBox.getSelection() || originalFileName.equals("")) {
+                       targetFile.setText("");
+                       return;
+               }
+
+               // see net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.MapPath(PHPLineBreakpoint)
+
+               IPath remoteSourcePath = new Path(fRemoteSourcePath.getText());
+               IPath filename = new Path(originalFileName);
+               filename = remoteSourcePath.append(filename);
+               String path = filename.toOSString();
+               Map pathmap = getMapFromPathMapTable();
+
+               if (pathmap != null) {
+                       Iterator it = pathmap.keySet().iterator();
+                       while (it.hasNext()) {
+                               String k = (String) it.next();
+                               if (path.startsWith(k)) {
+                                       path = pathmap.get(k) + path.substring(k.length());
+                                       break;
+                               }
+                       }
+               }
+
+               if (remoteSourcePath.isEmpty()) {
+                       if (pathmap != null) {
+                               Iterator it = pathmap.keySet().iterator();
+                               while (it.hasNext()) {
+                                       String local = (String) it.next();
+                                       IPath remotePath = new Path((String) pathmap.get(local));
+                                       IPath localPath = new Path(local);
+                                       if (localPath.isPrefixOf(filename)) {
+                                               IPath newpath = filename.removeFirstSegments(localPath
+                                                               .matchingFirstSegments(filename));
+                                               newpath = remotePath.append(newpath);
+                                               path = newpath.toString();
+                                               if (path.substring(0, 1).equals("/")) {
+                                                       path = path.replace('\\', '/');
+                                               } else {
+                                                       path = path.replace('/', '\\');
+                                               }
+                                               break;
+                                       }
+                               }
+                       }
+               } else {
+                       if (fRemoteDebugTranslate.getSelection()) {
+                               if (remoteSourcePath.toString().substring(0, 1).equals("/")) {
+                                       path = path.replace('\\', '/');
+                               } else {
+                                       path = path.replace('/', '\\');
+                               }
+                       }
+               }
+
+               targetFile.setText(path);
+       }
+
 }
\ No newline at end of file