fill all necessary default values for DBG in launch configuration
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / launcher / PHPEnvironmentTab.java
1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Iterator;
7 import java.util.Map;
8
9 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
10 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
11 import net.sourceforge.phpdt.internal.debug.ui.preferences.EditPathMapDialog;
12 import net.sourceforge.phpdt.internal.debug.ui.preferences.PHPInterpreterPreferencePage;
13 import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
14 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
15 import net.sourceforge.phpdt.internal.launching.PHPRuntime;
16 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.debug.core.ILaunchConfiguration;
24 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
25 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
26 import org.eclipse.jface.viewers.ColumnWeightData;
27 import org.eclipse.jface.viewers.ListViewer;
28 import org.eclipse.jface.viewers.TableLayout;
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.events.ModifyEvent;
31 import org.eclipse.swt.events.ModifyListener;
32 import org.eclipse.swt.events.MouseAdapter;
33 import org.eclipse.swt.events.MouseEvent;
34 import org.eclipse.swt.events.SelectionAdapter;
35 import org.eclipse.swt.events.SelectionEvent;
36 import org.eclipse.swt.events.SelectionListener;
37 import org.eclipse.swt.graphics.Image;
38 import org.eclipse.swt.layout.GridData;
39 import org.eclipse.swt.layout.GridLayout;
40 import org.eclipse.swt.widgets.Button;
41 import org.eclipse.swt.widgets.Combo;
42 import org.eclipse.swt.widgets.Composite;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.TabFolder;
45 import org.eclipse.swt.widgets.TabItem;
46 import org.eclipse.swt.widgets.Table;
47 import org.eclipse.swt.widgets.TableColumn;
48 import org.eclipse.swt.widgets.TableItem;
49 import org.eclipse.swt.widgets.Text;
50
51 public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
52   protected ListViewer loadPathListViewer;
53
54   protected java.util.List installedInterpretersWorkingCopy;
55
56   protected Combo interpreterCombo;
57
58   //    protected Button loadPathDefaultButton;
59   protected Button fRemoteDebugCheckBox;
60   protected Button fRemoteDebugTranslate;
61
62   protected Button fOpenDBGSessionInBrowserCheckBox;
63
64   protected Button fPathMapRemoveButton;
65
66   protected Button fPathMapAddButton;
67
68   protected Button fPathMapEditButton;
69
70   protected Text fRemoteSourcePath;
71
72   protected Table fRemoteDebugPathMapTable;
73
74   protected TabFolder tabFolder;
75
76   private class RemoteDebugTabListener extends SelectionAdapter implements ModifyListener {
77
78         /*
79          * (non-Javadoc)
80          *
81          * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
82          */
83         public void modifyText(ModifyEvent e) {
84           updateLaunchConfigurationDialog();
85         }
86
87         /*
88          * (non-Javadoc)
89          *
90          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
91          */
92         public void widgetSelected(SelectionEvent e) {
93           Object source = e.getSource();
94           if (source == fRemoteDebugPathMapTable) {
95                 setPathMapButtonsEnableState();
96           } else if (source == fPathMapAddButton) {
97                 handlePathMapAddButtonSelected();
98           } else if (source == fPathMapEditButton) {
99                 handlePathMapEditButtonSelected();
100           } else if (source == fPathMapRemoveButton) {
101                 handlePathMapRemoveButtonSelected();
102           } else if (source == fRemoteDebugCheckBox) {
103                 setRemoteTabEnableState();
104           } else if (source == fRemoteDebugTranslate) {
105                 setRemoteTabEnableState();
106           } else {
107                 updateLaunchConfigurationDialog();
108                 ;
109           }
110
111         }
112
113   }
114
115   private static final String EMPTY_STRING = ""; //$NON-NLS-1$
116
117   private RemoteDebugTabListener fListener = new RemoteDebugTabListener();
118
119   private static final boolean DEFAULT_REMOTE_DEBUG = false;
120
121   private static final boolean DEFAULT_REMOTE_DEBUG_TRANSLATE = false;
122
123   private static final boolean DEFAULT_OPEN_DBGSESSION_IN_BROWSER = true;
124
125   static String[] columnTitles = {
126           PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
127           PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.remote") };
128
129   public PHPEnvironmentTab() {
130         super();
131   }
132
133   public void createControl(Composite parent) {
134         Composite composite = createPageRoot(parent);
135
136         tabFolder = new TabFolder(composite, SWT.NONE);
137         GridData gridData = new GridData(GridData.FILL_BOTH);
138         tabFolder.setLayoutData(gridData);
139
140         //              addLoadPathTab(tabFolder);
141         addInterpreterTab(tabFolder);
142         addRemoteDebugTab(tabFolder);
143   }
144
145   protected void addRemoteDebugTab(TabFolder tabFolder) {
146         Label label;
147
148         TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
149         remoteDebugTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
150
151         Composite comp = new Composite(tabFolder, SWT.NONE);
152         comp.setLayout(new GridLayout());
153         remoteDebugTab.setControl(comp);
154         GridData gd;
155
156         fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
157         fRemoteDebugCheckBox.setText(PHPDebugUiMessages
158                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
159         fRemoteDebugCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
160         fRemoteDebugCheckBox.addSelectionListener(fListener);
161
162         fRemoteDebugTranslate = new Button(comp, SWT.CHECK);
163         fRemoteDebugTranslate.setText(PHPDebugUiMessages
164                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteTranslate.label"));
165         fRemoteDebugTranslate.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
166         fRemoteDebugTranslate.addSelectionListener(fListener);
167
168         fOpenDBGSessionInBrowserCheckBox = new Button(comp, SWT.CHECK);
169         fOpenDBGSessionInBrowserCheckBox.setText(PHPDebugUiMessages
170                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInBrowserCheckBox.label"));
171         fOpenDBGSessionInBrowserCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
172         fOpenDBGSessionInBrowserCheckBox.addSelectionListener(fListener);
173
174         label = new Label(comp, SWT.NONE);
175         label.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
176         fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
177         gd = new GridData(GridData.FILL_HORIZONTAL);
178         fRemoteSourcePath.setLayoutData(gd);
179         fRemoteSourcePath.addModifyListener(fListener);
180
181         createVerticalSpacer(comp, 1);
182
183         Composite pathMapComp = new Composite(comp, SWT.NONE);
184         gd = new GridData(GridData.FILL_BOTH);
185         pathMapComp.setLayoutData(gd);
186         GridLayout parametersLayout = new GridLayout();
187         parametersLayout.numColumns = 2;
188         parametersLayout.marginHeight = 0;
189         parametersLayout.marginWidth = 0;
190         pathMapComp.setLayout(parametersLayout);
191
192         Label pathMapLabel = new Label(pathMapComp, SWT.NONE);
193         pathMapLabel.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.label"));
194         gd = new GridData();
195         gd.horizontalSpan = 2;
196         pathMapLabel.setLayoutData(gd);
197
198         fRemoteDebugPathMapTable = new Table(pathMapComp, SWT.BORDER | SWT.MULTI);
199         TableLayout tableLayout = new TableLayout();
200         fRemoteDebugPathMapTable.setLayout(tableLayout);
201
202         gd = new GridData(GridData.FILL_BOTH);
203         fRemoteDebugPathMapTable.setLayoutData(gd);
204         TableColumn column1 = new TableColumn(this.fRemoteDebugPathMapTable, SWT.NONE);
205         column1.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.local")); //$NON-NLS-1$
206         TableColumn column2 = new TableColumn(this.fRemoteDebugPathMapTable, SWT.NONE);
207         column2
208                 .setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.remote")); //$NON-NLS-1$
209         tableLayout.addColumnData(new ColumnWeightData(100));
210         tableLayout.addColumnData(new ColumnWeightData(100));
211         fRemoteDebugPathMapTable.setHeaderVisible(true);
212         fRemoteDebugPathMapTable.setLinesVisible(true);
213         fRemoteDebugPathMapTable.addSelectionListener(fListener);
214         fRemoteDebugPathMapTable.addMouseListener(new MouseAdapter() {
215           public void mouseDoubleClick(MouseEvent e) {
216                 setPathMapButtonsEnableState();
217                 if (fPathMapEditButton.isEnabled()) {
218                   handlePathMapEditButtonSelected();
219                 }
220           }
221         });
222         //              fRemoteDebugPathMapTable.setEnabled(false);
223
224         Composite envButtonComp = new Composite(pathMapComp, SWT.NONE);
225         GridLayout envButtonLayout = new GridLayout();
226         envButtonLayout.marginHeight = 0;
227         envButtonLayout.marginWidth = 0;
228         envButtonComp.setLayout(envButtonLayout);
229         gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
230         envButtonComp.setLayoutData(gd);
231
232         fPathMapAddButton = createPushButton(envButtonComp, PHPDebugUiMessages
233                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Add.label"), null); //$NON-NLS-1$
234         fPathMapAddButton.addSelectionListener(fListener);
235         //              fPathMapAddButton.setEnabled(false);
236
237         fPathMapEditButton = createPushButton(envButtonComp, PHPDebugUiMessages
238                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Edit.label"), null); //$NON-NLS-1$
239         fPathMapEditButton.addSelectionListener(fListener);
240         //              fPathMapEditButton.setEnabled(false);
241
242         fPathMapRemoveButton = createPushButton(envButtonComp, PHPDebugUiMessages
243                 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Remove.label"), null); //$NON-NLS-1$
244         fPathMapRemoveButton.addSelectionListener(fListener);
245         //              fPathMapRemoveButton.setEnabled(false);
246
247   }
248
249   void handlePathMapAddButtonSelected() {
250         EditPathMapDialog dialog = new EditPathMapDialog(getShell(), "Edit File Map", new String[] { EMPTY_STRING, EMPTY_STRING });
251         openNewPathMapDialog(dialog, null);
252         //              dialog.create();
253         //              if (dialog.open()==EditPathMapDialog.OK)
254         //              {
255         //                      TableItem item = new TableItem (fRemoteDebugPathMapTable, SWT.NONE);
256         //                      item.setText(0,dialog.getLocalPath());
257         //                      item.setText(1,dialog.getRemotePath());
258         //                      updateLaunchConfigurationDialog();
259         //              }
260         //              updateLaunchConfigurationDialog();
261         setPathMapButtonsEnableState();
262   }
263
264   void handlePathMapRemoveButtonSelected() {
265         int[] selectedIndices = this.fRemoteDebugPathMapTable.getSelectionIndices();
266         this.fRemoteDebugPathMapTable.remove(selectedIndices);
267         setPathMapButtonsEnableState();
268         updateLaunchConfigurationDialog();
269   }
270
271   void handlePathMapEditButtonSelected() {
272         TableItem selectedItem = this.fRemoteDebugPathMapTable.getSelection()[0];
273         String local = selectedItem.getText(0);
274         String remote = selectedItem.getText(1);
275         EditPathMapDialog dialog = new EditPathMapDialog(getShell(), "Edit File Map", new String[] { local, remote });
276         openNewPathMapDialog(dialog, selectedItem);
277   }
278
279   /**
280    * Set the enabled state of whole tab.
281    */
282   private void setRemoteTabEnableState() {
283         boolean state = fRemoteDebugCheckBox.getSelection();
284         fRemoteSourcePath.setEnabled(state);
285         fRemoteDebugTranslate.setEnabled(state);
286
287         fRemoteDebugPathMapTable.setEnabled(state);
288         if (!state) {
289           fPathMapEditButton.setEnabled(false);
290           fPathMapRemoveButton.setEnabled(false);
291           fPathMapAddButton.setEnabled(false);
292           fOpenDBGSessionInBrowserCheckBox.setEnabled(false);
293         } else {
294           setPathMapButtonsEnableState();
295         }
296
297         updateLaunchConfigurationDialog();
298   }
299
300   /**
301    * Set the enabled state of the three environment variable-related buttons based on the selection in the PathMapTable widget.
302    */
303   private void setPathMapButtonsEnableState() {
304         //      just do nothing for now
305         //
306         if (fRemoteDebugCheckBox.getSelection()) {
307           fOpenDBGSessionInBrowserCheckBox.setEnabled(true);
308           fRemoteDebugTranslate.setEnabled(true);
309           int selectCount = this.fRemoteDebugPathMapTable.getSelectionIndices().length;
310           if (selectCount < 1) {
311                 fPathMapEditButton.setEnabled(false);
312                 fPathMapRemoveButton.setEnabled(false);
313           } else {
314                 fPathMapRemoveButton.setEnabled(true);
315                 if (selectCount == 1) {
316                   fPathMapEditButton.setEnabled(true);
317                 } else {
318                   fPathMapEditButton.setEnabled(false);
319                 }
320           }
321           fPathMapAddButton.setEnabled(true);
322         }
323   }
324
325   /**
326    * Show the specified dialog and update the pathMapTable table based on its results.
327    * 
328    * @param updateItem
329    *          the item to update, or <code>null</code> if adding a new item
330    */
331   private void openNewPathMapDialog(EditPathMapDialog dialog, TableItem updateItem) {
332         if (dialog.open() != EditPathMapDialog.OK) {
333           return;
334         }
335         String[] pathPair = dialog.getPathPair();
336         TableItem tableItem = updateItem;
337         if (tableItem == null) {
338           tableItem = getTableItemForName(pathPair[0]);
339           if (tableItem == null) {
340                 tableItem = new TableItem(this.fRemoteDebugPathMapTable, SWT.NONE);
341           }
342         }
343         tableItem.setText(pathPair);
344         this.fRemoteDebugPathMapTable.setSelection(new TableItem[] { tableItem });
345         updateLaunchConfigurationDialog();
346   }
347
348   /**
349    * Helper method that indicates whether the specified parameter name is already present in the parameters table.
350    */
351   private TableItem getTableItemForName(String candidateName) {
352         TableItem[] items = this.fRemoteDebugPathMapTable.getItems();
353         for (int i = 0; i < items.length; i++) {
354           String name = items[i].getText(0);
355           if (name.equals(candidateName)) {
356                 return items[i];
357           }
358         }
359         return null;
360   }
361
362   //    protected void addLoadPathTab(TabFolder tabFolder) {
363   //            Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
364   //            loadPathComposite.setLayout(new GridLayout());
365   //
366   //            loadPathListViewer = new ListViewer(loadPathComposite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
367   //            loadPathListViewer.setContentProvider(new ListContentProvider());
368   //            loadPathListViewer.setLabelProvider(new LoadPathEntryLabelProvider());
369   //            loadPathListViewer.getList().setLayoutData(new GridData(GridData.FILL_BOTH));
370   //
371   //            TabItem loadPathTab = new TabItem(tabFolder, SWT.NONE, 0);
372   //            loadPathTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathTab.label"));
373   //            loadPathTab.setControl(loadPathComposite);
374   //            loadPathTab.setData(loadPathListViewer);
375
376   //            loadPathDefaultButton = new Button(loadPathComposite, SWT.CHECK);
377   //            loadPathDefaultButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label"));
378   //            loadPathDefaultButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
379   //            loadPathDefaultButton.addSelectionListener(getLoadPathDefaultButtonSelectionListener());
380   //            
381   //            loadPathDefaultButton.setEnabled(false); //for now, until the load path is customizable on the configuration
382   //    }
383
384   protected SelectionListener getLoadPathSelectionListener() {
385         return new SelectionAdapter() {
386           public void widgetSelected(SelectionEvent e) {
387                 System.out.println("Loadpath list selection occurred: " + e.getSource());
388           }
389         };
390   }
391
392   protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
393         return new SelectionAdapter() {
394           public void widgetSelected(SelectionEvent e) {
395                 setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
396           }
397         };
398   }
399
400   protected void addInterpreterTab(TabFolder tabFolder) {
401         Composite interpreterComposite = new Composite(tabFolder, SWT.NONE);
402         GridLayout layout = new GridLayout();
403         layout.numColumns = 2;
404         layout.marginHeight = 0;
405         layout.marginWidth = 0;
406         interpreterComposite.setLayout(layout);
407         interpreterComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
408
409         createVerticalSpacer(interpreterComposite, 2);
410
411         interpreterCombo = new Combo(interpreterComposite, SWT.READ_ONLY);
412         interpreterCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
413         initializeInterpreterCombo(interpreterCombo);
414         interpreterCombo.addModifyListener(getInterpreterComboModifyListener());
415
416         Button interpreterAddButton = new Button(interpreterComposite, SWT.PUSH);
417         interpreterAddButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label"));
418         interpreterAddButton.addSelectionListener(new SelectionAdapter() {
419           public void widgetSelected(SelectionEvent evt) {
420                 PHPInterpreter newInterpreter = new PHPInterpreter(null);
421                 File phpRuntime = PHPInterpreterPreferencePage.getFile(getShell(), null);
422                 if (phpRuntime != null) {
423                   newInterpreter.setInstallLocation(phpRuntime);
424                   PHPRuntime.getDefault().addInstalledInterpreter(newInterpreter);
425                   interpreterCombo.add(newInterpreter.getInstallLocation().toString());
426                   interpreterCombo.select(interpreterCombo.indexOf(newInterpreter.getInstallLocation().toString()));
427                 }
428           }
429         });
430
431         TabItem interpreterTab = new TabItem(tabFolder, SWT.NONE);
432         interpreterTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.interpreterTab.label"));
433         interpreterTab.setControl(interpreterComposite);
434   }
435
436   protected ModifyListener getInterpreterComboModifyListener() {
437         return new ModifyListener() {
438           public void modifyText(ModifyEvent evt) {
439                 updateLaunchConfigurationDialog();
440           }
441         };
442   }
443
444   protected void createVerticalSpacer(Composite comp, int colSpan) {
445         Label label = new Label(comp, SWT.NONE);
446         GridData gd = new GridData();
447         gd.horizontalSpan = colSpan;
448         label.setLayoutData(gd);
449   }
450
451   public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
452                 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
453                                 .getSelectedInterpreter();
454                 if (selectedInterpreter != null) {
455                         String interpreterLocation = selectedInterpreter
456                                         .getInstallLocation().toString();
457                         configuration.setAttribute(
458                                         PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
459                                         interpreterLocation);
460                 }
461                 try {
462                         String projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,"");
463                         if (projectName!="") {
464                                 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
465                                 if (project!=null) {
466                                         IPath remotePath = project.getLocation();
467                                         String fileName=configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME,"");
468                                         if (fileName!="") {
469                                                 Path filePath = new Path(fileName);
470                                                 remotePath=remotePath.append(filePath.removeLastSegments(1));
471                                         }
472                                         configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, remotePath.toOSString());
473                                 }
474                         }
475                 } catch (CoreException e) {
476                         // TODO Auto-generated catch block
477                         e.printStackTrace();
478                 }
479         }
480
481   public void initializeFrom(ILaunchConfiguration configuration) {
482         //              initializeLoadPath(configuration);
483         initializeInterpreterSelection(configuration);
484         initializeRemoteDebug(configuration);
485   }
486
487   protected void initializeRemoteDebug(ILaunchConfiguration configuration) {
488         try {
489           fRemoteDebugCheckBox.setSelection(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
490                   DEFAULT_REMOTE_DEBUG));
491         } catch (CoreException ce) {
492           fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
493         }
494         try {
495                 fRemoteDebugTranslate.setSelection(configuration.getAttribute(
496                         PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE, DEFAULT_REMOTE_DEBUG_TRANSLATE));
497           } catch (CoreException ce) {
498                 fRemoteDebugTranslate.setSelection(DEFAULT_REMOTE_DEBUG_TRANSLATE);
499           }
500         try {
501           fOpenDBGSessionInBrowserCheckBox.setSelection(configuration.getAttribute(
502                   PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER, DEFAULT_OPEN_DBGSESSION_IN_BROWSER));
503         } catch (CoreException ce) {
504           fOpenDBGSessionInBrowserCheckBox.setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
505         }
506         setRemoteTabEnableState();
507         try {
508           fRemoteSourcePath.setText(configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
509         } catch (CoreException ce) {
510           fRemoteSourcePath.setText("");
511         }
512
513         updatePathMapFromConfig(configuration);
514
515   }
516
517   private void updatePathMapFromConfig(ILaunchConfiguration config) {
518         Map envVars = null;
519         try {
520           if (config != null) {
521                 envVars = config.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
522           }
523           updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
524           setPathMapButtonsEnableState();
525         } catch (CoreException ce) {
526           log(ce);
527         }
528   }
529
530   private void updatePathMapTable(Map map, Table tableWidget) {
531         tableWidget.removeAll();
532         if (map == null) {
533           return;
534         }
535         Iterator iterator = map.keySet().iterator();
536         while (iterator.hasNext()) {
537           String key = (String) iterator.next();
538           String value = (String) map.get(key);
539           TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
540           tableItem.setText(new String[] { key, value });
541         }
542   }
543
544   //    protected void initializeLoadPath(ILaunchConfiguration configuration) {
545   //            boolean useDefaultLoadPath = true;
546   //            try {
547   //                    useDefaultLoadPath = configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH, true);
548   //                    setUseLoadPathDefaults(useDefaultLoadPath);
549   //                    if (useDefaultLoadPath) {
550   //                            String projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
551   //                            if (projectName != "") {
552   //                                IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
553   //                                    if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
554   //                                          JavaProject thePHPProject = new JavaProject();
555   //                                          thePHPProject.setProject(aProject);
556   //                                            List loadPathEntries = thePHPProject.getLoadPathEntries();
557   //                                            loadPathListViewer.setInput(loadPathEntries);
558   //                                    }
559   //                            }
560   //                    }
561   //            } catch (CoreException e) {
562   //                    log(e);
563   //            }
564   //    }
565
566   protected void setUseLoadPathDefaults(boolean useDefaults) {
567         loadPathListViewer.getList().setEnabled(!useDefaults);
568         //              loadPathDefaultButton.setSelection(useDefaults);
569   }
570
571   protected void initializeInterpreterSelection(ILaunchConfiguration configuration) {
572         String interpreterName = null;
573         try {
574           interpreterName = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
575         } catch (CoreException e) {
576           log(e);
577         }
578         if (interpreterName != null && !interpreterName.equals(""))
579           interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
580   }
581
582   protected void initializeInterpreterCombo(Combo interpreterCombo) {
583         installedInterpretersWorkingCopy = new ArrayList();
584         installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault().getInstalledInterpreters());
585
586         String[] interpreterNames = new String[installedInterpretersWorkingCopy.size()];
587         for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy.size(); interpreterIndex++) {
588           PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy.get(interpreterIndex);
589           interpreterNames[interpreterIndex] = interpreter.getInstallLocation().toString();
590         }
591         interpreterCombo.setItems(interpreterNames);
592
593         PHPInterpreter selectedInterpreter = PHPRuntime.getDefault().getSelectedInterpreter();
594         if (selectedInterpreter != null)
595           interpreterCombo.select(interpreterCombo.indexOf(selectedInterpreter.getInstallLocation().toString()));
596   }
597
598   public void performApply(ILaunchConfigurationWorkingCopy configuration) {
599         int selectionIndex = interpreterCombo.getSelectionIndex();
600         if (selectionIndex >= 0)
601           configuration.setAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, interpreterCombo.getItem(selectionIndex));
602
603         //              configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH, loadPathDefaultButton.getSelection());
604
605         //              if (!loadPathDefaultButton.getSelection()) {
606         //                      List loadPathEntries = (List) loadPathListViewer.getInput();
607         //                      List loadPathStrings = new ArrayList();
608         //                      for (Iterator iterator = loadPathEntries.iterator(); iterator.hasNext();) {
609         //                              LoadPathEntry entry = (LoadPathEntry) iterator.next();
610         //                              loadPathStrings.add(entry.getPath().toString());
611         //                      }
612         //                      configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH, loadPathStrings);
613         //              }
614
615         configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG, fRemoteDebugCheckBox.getSelection());
616         configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE, fRemoteDebugTranslate.getSelection());
617         configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, getMapFromPathMapTable());
618         configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, fRemoteSourcePath.getText());
619         configuration.setAttribute(PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER, fOpenDBGSessionInBrowserCheckBox
620                 .getSelection());
621   }
622
623   protected Composite createPageRoot(Composite parent) {
624         Composite composite = new Composite(parent, SWT.NULL);
625         GridLayout layout = new GridLayout();
626         layout.numColumns = 2;
627         composite.setLayout(layout);
628         createVerticalSpacer(composite, 2);
629         setControl(composite);
630
631         return composite;
632   }
633
634   private Map getMapFromPathMapTable() {
635         TableItem[] items = fRemoteDebugPathMapTable.getItems();
636         if (items.length == 0) {
637           return null;
638         }
639         Map map = new HashMap(items.length);
640         for (int i = 0; i < items.length; i++) {
641           TableItem item = items[i];
642           String key = item.getText(0);
643           String value = item.getText(1);
644           map.put(key, value);
645         }
646         return map;
647   }
648
649   public String getName() {
650         return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.name");
651   }
652
653   public boolean isValid(ILaunchConfiguration launchConfig) {
654         try {
655           String selectedInterpreter = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
656           if (selectedInterpreter.length() == 0) {
657                 setErrorMessage(PHPDebugUiMessages
658                         .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
659                 return false;
660           }
661         } catch (CoreException e) {
662           log(e);
663         }
664
665         setErrorMessage(null);
666         return true;
667   }
668
669   protected void log(Throwable t) {
670         PHPDebugUiPlugin.log(t);
671   }
672
673   public Image getImage() {
674         return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
675   }
676
677 }