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