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