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