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