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