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