1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Iterator;
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;
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.Color;
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;
52 public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
53 protected ListViewer loadPathListViewer;
55 protected java.util.List installedInterpretersWorkingCopy;
57 protected Combo interpreterCombo;
59 // protected Button loadPathDefaultButton;
60 protected Button fRemoteDebugCheckBox;
62 protected Button fRemoteDebugTranslate;
64 protected Button fOpenDBGSessionInBrowserCheckBox;
66 protected Button fOpenDBGSessionInExternalBrowserCheckBox;
68 protected Button fPathMapRemoveButton;
70 protected Button fPathMapAddButton;
72 protected Button fPathMapEditButton;
74 protected Text fRemoteSourcePath;
76 protected Table fRemoteDebugPathMapTable;
78 protected TabFolder tabFolder;
80 private Text targetFile;
82 private String originalFileName = "";
84 private class RemoteDebugTabListener extends SelectionAdapter implements
90 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
92 public void modifyText(ModifyEvent e) {
93 updateLaunchConfigurationDialog();
100 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
102 public void widgetSelected(SelectionEvent e) {
103 Object source = e.getSource();
104 if (source == fRemoteDebugPathMapTable) {
105 setPathMapButtonsEnableState();
106 } else if (source == fPathMapAddButton) {
107 handlePathMapAddButtonSelected();
108 } else if (source == fPathMapEditButton) {
109 handlePathMapEditButtonSelected();
110 } else if (source == fPathMapRemoveButton) {
111 handlePathMapRemoveButtonSelected();
112 } else if (source == fRemoteDebugCheckBox) {
113 setRemoteTabEnableState();
114 } else if (source == fRemoteDebugTranslate) {
115 setRemoteTabEnableState();
116 } else if (source == fOpenDBGSessionInBrowserCheckBox) {
117 setRemoteTabEnableState();
119 updateLaunchConfigurationDialog();
126 private static final String EMPTY_STRING = ""; //$NON-NLS-1$
128 private RemoteDebugTabListener fListener = new RemoteDebugTabListener();
130 private static final boolean DEFAULT_REMOTE_DEBUG = false;
132 private static final boolean DEFAULT_REMOTE_DEBUG_TRANSLATE = false;
134 private static final boolean DEFAULT_OPEN_DBGSESSION_IN_BROWSER = true;
136 private static final boolean DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER = false;
138 static String[] columnTitles = {
140 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
142 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.remote") };
144 public PHPEnvironmentTab() {
148 public void createControl(Composite parent) {
149 Composite composite = createPageRoot(parent);
151 tabFolder = new TabFolder(composite, SWT.NONE);
152 GridData gridData = new GridData(GridData.FILL_BOTH);
153 tabFolder.setLayoutData(gridData);
155 // addLoadPathTab(tabFolder);
156 addRemoteDebugTab(tabFolder);
157 addInterpreterTab(tabFolder);
160 protected void addRemoteDebugTab(TabFolder tabFolder) {
163 TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
165 .setText(PHPDebugUiMessages
166 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
168 Composite comp = new Composite(tabFolder, SWT.NONE);
169 comp.setLayout(new GridLayout());
170 remoteDebugTab.setControl(comp);
173 fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
175 .setText(PHPDebugUiMessages
176 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
177 fRemoteDebugCheckBox.setLayoutData(new GridData(
178 GridData.HORIZONTAL_ALIGN_BEGINNING));
179 fRemoteDebugCheckBox.addSelectionListener(fListener);
181 fRemoteDebugTranslate = new Button(comp, SWT.CHECK);
182 fRemoteDebugTranslate
183 .setText(PHPDebugUiMessages
184 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteTranslate.label"));
185 fRemoteDebugTranslate.setLayoutData(new GridData(
186 GridData.HORIZONTAL_ALIGN_BEGINNING));
187 fRemoteDebugTranslate.addSelectionListener(fListener);
189 fOpenDBGSessionInBrowserCheckBox = new Button(comp, SWT.CHECK);
190 fOpenDBGSessionInBrowserCheckBox
191 .setText(PHPDebugUiMessages
192 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInBrowserCheckBox.label"));
193 fOpenDBGSessionInBrowserCheckBox.setLayoutData(new GridData(
194 GridData.HORIZONTAL_ALIGN_BEGINNING));
195 fOpenDBGSessionInBrowserCheckBox.addSelectionListener(fListener);
198 fOpenDBGSessionInExternalBrowserCheckBox = new Button(comp, SWT.CHECK);
199 fOpenDBGSessionInExternalBrowserCheckBox
200 .setText(PHPDebugUiMessages
201 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInExternalBrowserCheckBox.label"));
202 fOpenDBGSessionInExternalBrowserCheckBox.setLayoutData(new GridData(
204 ((GridData) fOpenDBGSessionInExternalBrowserCheckBox.getLayoutData()).horizontalIndent = 16;
205 fOpenDBGSessionInExternalBrowserCheckBox
206 .addSelectionListener(fListener);
209 label = new Label(comp, SWT.NONE);
211 .setText(PHPDebugUiMessages
212 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
213 fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
214 gd = new GridData(GridData.FILL_HORIZONTAL);
215 fRemoteSourcePath.setLayoutData(gd);
216 fRemoteSourcePath.addModifyListener(fListener);
218 // addendum - make an effect of RemoteSourcePath clear
219 Composite targetComp = new Composite(comp, SWT.NONE);
220 targetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
221 GridLayout targetLayout = new GridLayout(4, false);
222 targetLayout.marginHeight = 0;
223 targetLayout.marginWidth = 3;
224 targetComp.setLayout(targetLayout);
225 Color targetColor = new Color(null, 160, 160, 160);
226 Label label_lp = new Label(targetComp, SWT.NONE);
227 label_lp.setText("(");
228 label_lp.setForeground(targetColor);
229 label_lp.setLayoutData(new GridData(GridData.BEGINNING));
230 Label targetLabel = new Label(targetComp, SWT.NONE);
232 .setText(PHPDebugUiMessages
233 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.TargetFile.label"));
234 targetLabel.setForeground(targetColor);
235 targetLabel.setLayoutData(new GridData(GridData.BEGINNING));
236 targetFile = new Text(targetComp, SWT.SINGLE);
237 targetFile.setForeground(targetColor);
238 targetFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
239 targetFile.setEditable(false);
240 Label label_rp = new Label(targetComp, SWT.NONE);
241 label_rp.setText(")");
242 label_rp.setForeground(targetColor);
243 label_rp.setLayoutData(new GridData(GridData.END));
246 createVerticalSpacer(comp, 1);
248 Composite pathMapComp = new Composite(comp, SWT.NONE);
249 gd = new GridData(GridData.FILL_BOTH);
250 pathMapComp.setLayoutData(gd);
251 GridLayout parametersLayout = new GridLayout();
252 parametersLayout.numColumns = 2;
253 parametersLayout.marginHeight = 0;
254 parametersLayout.marginWidth = 0;
255 pathMapComp.setLayout(parametersLayout);
257 Label pathMapLabel = new Label(pathMapComp, SWT.NONE);
259 .setText(PHPDebugUiMessages
260 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.label"));
262 gd.horizontalSpan = 2;
263 pathMapLabel.setLayoutData(gd);
265 fRemoteDebugPathMapTable = new Table(pathMapComp, SWT.BORDER
267 TableLayout tableLayout = new TableLayout();
268 fRemoteDebugPathMapTable.setLayout(tableLayout);
270 gd = new GridData(GridData.FILL_BOTH);
271 fRemoteDebugPathMapTable.setLayoutData(gd);
272 TableColumn column1 = new TableColumn(this.fRemoteDebugPathMapTable,
275 .setText(PHPDebugUiMessages
276 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.local")); //$NON-NLS-1$
277 TableColumn column2 = new TableColumn(this.fRemoteDebugPathMapTable,
280 .setText(PHPDebugUiMessages
281 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.remote")); //$NON-NLS-1$
282 tableLayout.addColumnData(new ColumnWeightData(100));
283 tableLayout.addColumnData(new ColumnWeightData(100));
284 fRemoteDebugPathMapTable.setHeaderVisible(true);
285 fRemoteDebugPathMapTable.setLinesVisible(true);
286 fRemoteDebugPathMapTable.addSelectionListener(fListener);
287 fRemoteDebugPathMapTable.addMouseListener(new MouseAdapter() {
288 public void mouseDoubleClick(MouseEvent e) {
289 setPathMapButtonsEnableState();
290 if (fPathMapEditButton.isEnabled()) {
291 handlePathMapEditButtonSelected();
295 // fRemoteDebugPathMapTable.setEnabled(false);
297 Composite envButtonComp = new Composite(pathMapComp, SWT.NONE);
298 GridLayout envButtonLayout = new GridLayout();
299 envButtonLayout.marginHeight = 0;
300 envButtonLayout.marginWidth = 0;
301 envButtonComp.setLayout(envButtonLayout);
302 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
303 | GridData.HORIZONTAL_ALIGN_FILL);
304 envButtonComp.setLayoutData(gd);
306 fPathMapAddButton = createPushButton(
309 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Add.label"), null); //$NON-NLS-1$
310 fPathMapAddButton.addSelectionListener(fListener);
311 // fPathMapAddButton.setEnabled(false);
313 fPathMapEditButton = createPushButton(
316 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Edit.label"), null); //$NON-NLS-1$
317 fPathMapEditButton.addSelectionListener(fListener);
318 // fPathMapEditButton.setEnabled(false);
320 fPathMapRemoveButton = createPushButton(
323 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Remove.label"), null); //$NON-NLS-1$
324 fPathMapRemoveButton.addSelectionListener(fListener);
325 // fPathMapRemoveButton.setEnabled(false);
329 void handlePathMapAddButtonSelected() {
330 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
331 "Edit File Map", new String[] { EMPTY_STRING, EMPTY_STRING });
332 openNewPathMapDialog(dialog, null);
334 // if (dialog.open()==EditPathMapDialog.OK)
336 // TableItem item = new TableItem (fRemoteDebugPathMapTable, SWT.NONE);
337 // item.setText(0,dialog.getLocalPath());
338 // item.setText(1,dialog.getRemotePath());
339 // updateLaunchConfigurationDialog();
341 // updateLaunchConfigurationDialog();
342 setPathMapButtonsEnableState();
345 void handlePathMapRemoveButtonSelected() {
346 int[] selectedIndices = this.fRemoteDebugPathMapTable
347 .getSelectionIndices();
348 this.fRemoteDebugPathMapTable.remove(selectedIndices);
349 setPathMapButtonsEnableState();
350 updateLaunchConfigurationDialog();
353 void handlePathMapEditButtonSelected() {
354 TableItem selectedItem = this.fRemoteDebugPathMapTable.getSelection()[0];
355 String local = selectedItem.getText(0);
356 String remote = selectedItem.getText(1);
357 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
358 "Edit File Map", new String[] { local, remote });
359 openNewPathMapDialog(dialog, selectedItem);
363 * Set the enabled state of whole tab.
365 private void setRemoteTabEnableState() {
366 boolean state = fRemoteDebugCheckBox.getSelection();
367 fRemoteSourcePath.setEnabled(state);
368 fRemoteDebugTranslate.setEnabled(state);
370 fRemoteDebugPathMapTable.setEnabled(state);
372 fPathMapEditButton.setEnabled(false);
373 fPathMapRemoveButton.setEnabled(false);
374 fPathMapAddButton.setEnabled(false);
375 fOpenDBGSessionInBrowserCheckBox.setEnabled(false);
376 fOpenDBGSessionInExternalBrowserCheckBox.setEnabled(false);
378 setPathMapButtonsEnableState();
381 updateLaunchConfigurationDialog();
385 * Set the enabled state of the three environment variable-related buttons
386 * based on the selection in the PathMapTable widget.
388 private void setPathMapButtonsEnableState() {
389 // just do nothing for now
391 if (fRemoteDebugCheckBox.getSelection()) {
392 fOpenDBGSessionInBrowserCheckBox.setEnabled(true);
393 fOpenDBGSessionInExternalBrowserCheckBox
394 .setEnabled(fOpenDBGSessionInBrowserCheckBox.getSelection());
395 fRemoteDebugTranslate.setEnabled(true);
396 int selectCount = this.fRemoteDebugPathMapTable
397 .getSelectionIndices().length;
398 if (selectCount < 1) {
399 fPathMapEditButton.setEnabled(false);
400 fPathMapRemoveButton.setEnabled(false);
402 fPathMapRemoveButton.setEnabled(true);
403 if (selectCount == 1) {
404 fPathMapEditButton.setEnabled(true);
406 fPathMapEditButton.setEnabled(false);
409 fPathMapAddButton.setEnabled(true);
414 * Show the specified dialog and update the pathMapTable table based on its
418 * the item to update, or <code>null</code> if adding a new
421 private void openNewPathMapDialog(EditPathMapDialog dialog,
422 TableItem updateItem) {
423 if (dialog.open() != EditPathMapDialog.OK) {
426 String[] pathPair = dialog.getPathPair();
427 TableItem tableItem = updateItem;
428 if (tableItem == null) {
429 tableItem = getTableItemForName(pathPair[0]);
430 if (tableItem == null) {
431 tableItem = new TableItem(this.fRemoteDebugPathMapTable,
435 tableItem.setText(pathPair);
436 this.fRemoteDebugPathMapTable
437 .setSelection(new TableItem[] { tableItem });
438 updateLaunchConfigurationDialog();
442 * Helper method that indicates whether the specified parameter name is
443 * already present in the parameters table.
445 private TableItem getTableItemForName(String candidateName) {
446 TableItem[] items = this.fRemoteDebugPathMapTable.getItems();
447 for (int i = 0; i < items.length; i++) {
448 String name = items[i].getText(0);
449 if (name.equals(candidateName)) {
456 // protected void addLoadPathTab(TabFolder tabFolder) {
457 // Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
458 // loadPathComposite.setLayout(new GridLayout());
460 // loadPathListViewer = new ListViewer(loadPathComposite, SWT.BORDER |
461 // SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
462 // loadPathListViewer.setContentProvider(new ListContentProvider());
463 // loadPathListViewer.setLabelProvider(new LoadPathEntryLabelProvider());
464 // loadPathListViewer.getList().setLayoutData(new
465 // GridData(GridData.FILL_BOTH));
467 // TabItem loadPathTab = new TabItem(tabFolder, SWT.NONE, 0);
468 // loadPathTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathTab.label"));
469 // loadPathTab.setControl(loadPathComposite);
470 // loadPathTab.setData(loadPathListViewer);
472 // loadPathDefaultButton = new Button(loadPathComposite, SWT.CHECK);
473 // loadPathDefaultButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label"));
474 // loadPathDefaultButton.setLayoutData(new
475 // GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
476 // loadPathDefaultButton.addSelectionListener(getLoadPathDefaultButtonSelectionListener());
478 // loadPathDefaultButton.setEnabled(false); //for now, until the load path
479 // is customizable on the configuration
482 // protected SelectionListener getLoadPathSelectionListener() {
483 // return new SelectionAdapter() {
484 // public void widgetSelected(SelectionEvent e) {
485 // System.out.println("Loadpath list selection occurred: "
491 // protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
492 // return new SelectionAdapter() {
493 // public void widgetSelected(SelectionEvent e) {
494 // setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
499 protected void addInterpreterTab(TabFolder tabFolder) {
500 Composite interpreterComposite = new Composite(tabFolder, SWT.NONE);
501 GridLayout layout = new GridLayout();
502 layout.numColumns = 2;
503 // layout.marginHeight = 0;
504 // layout.marginWidth = 0;
505 interpreterComposite.setLayout(layout);
506 interpreterComposite.setLayoutData(new GridData(
507 GridData.FILL_HORIZONTAL));
509 createVerticalSpacer(interpreterComposite, 2);
511 interpreterCombo = new Combo(interpreterComposite, SWT.READ_ONLY);
512 interpreterCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
513 initializeInterpreterCombo(interpreterCombo);
514 interpreterCombo.addModifyListener(getInterpreterComboModifyListener());
516 Button interpreterAddButton = new Button(interpreterComposite, SWT.PUSH);
518 .setText(PHPDebugUiMessages
519 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label"));
520 interpreterAddButton.addSelectionListener(new SelectionAdapter() {
521 public void widgetSelected(SelectionEvent evt) {
522 PHPInterpreter newInterpreter = new PHPInterpreter(null);
523 File phpRuntime = PHPInterpreterPreferencePage.getFile(
525 if (phpRuntime != null) {
526 newInterpreter.setInstallLocation(phpRuntime);
527 PHPRuntime.getDefault().addInstalledInterpreter(
529 interpreterCombo.add(newInterpreter.getInstallLocation()
531 interpreterCombo.select(interpreterCombo
532 .indexOf(newInterpreter.getInstallLocation()
538 TabItem interpreterTab = new TabItem(tabFolder, SWT.NONE);
540 .setText(PHPDebugUiMessages
541 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterTab.label"));
542 interpreterTab.setControl(interpreterComposite);
545 protected ModifyListener getInterpreterComboModifyListener() {
546 return new ModifyListener() {
547 public void modifyText(ModifyEvent evt) {
548 updateLaunchConfigurationDialog();
553 protected void createVerticalSpacer(Composite comp, int colSpan) {
554 Label label = new Label(comp, SWT.NONE);
555 GridData gd = new GridData();
556 gd.horizontalSpan = colSpan;
557 label.setLayoutData(gd);
560 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
561 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
562 .getSelectedInterpreter();
563 if (selectedInterpreter != null) {
564 String interpreterLocation = selectedInterpreter
565 .getInstallLocation().toString();
566 configuration.setAttribute(
567 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
568 interpreterLocation);
571 String projectName = configuration.getAttribute(
572 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
573 if (projectName != "") {
574 IProject project = ResourcesPlugin.getWorkspace().getRoot()
575 .getProject(projectName);
576 if (project != null) {
577 IPath remotePath = project.getFullPath();
578 String fileName = configuration.getAttribute(
579 PHPLaunchConfigurationAttribute.FILE_NAME, "");
580 if (fileName != "") {
581 Path filePath = new Path(fileName);
582 remotePath = remotePath.append(filePath
583 .removeLastSegments(1));
585 configuration.setAttribute(
586 PHPLaunchConfigurationAttribute.REMOTE_PATH,
587 remotePath.toOSString());
590 } catch (CoreException e) {
595 public void initializeFrom(ILaunchConfiguration configuration) {
596 // initializeLoadPath(configuration);
597 initializeInterpreterSelection(configuration);
598 initializeRemoteDebug(configuration);
601 protected void initializeRemoteDebug(ILaunchConfiguration configuration) {
603 fRemoteDebugCheckBox.setSelection(configuration.getAttribute(
604 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
605 DEFAULT_REMOTE_DEBUG));
606 } catch (CoreException ce) {
607 fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
609 tabFolder.setSelection(fRemoteDebugCheckBox.getSelection() ? 0 : 1);
611 fRemoteDebugTranslate.setSelection(configuration.getAttribute(
612 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
613 DEFAULT_REMOTE_DEBUG_TRANSLATE));
614 } catch (CoreException ce) {
615 fRemoteDebugTranslate.setSelection(DEFAULT_REMOTE_DEBUG_TRANSLATE);
618 fOpenDBGSessionInBrowserCheckBox
619 .setSelection(configuration
621 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
622 DEFAULT_OPEN_DBGSESSION_IN_BROWSER));
623 } catch (CoreException ce) {
624 fOpenDBGSessionInBrowserCheckBox
625 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
628 fOpenDBGSessionInExternalBrowserCheckBox
629 .setSelection(configuration
631 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
632 DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER));
633 } catch (CoreException ce) {
634 fOpenDBGSessionInExternalBrowserCheckBox
635 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER);
638 setRemoteTabEnableState();
641 fRemoteSourcePath.setText(configuration.getAttribute(
642 PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
643 } catch (CoreException ce) {
644 fRemoteSourcePath.setText("");
647 updatePathMapFromConfig(configuration);
650 originalFileName = configuration.getAttribute(
651 PHPLaunchConfigurationAttribute.FILE_NAME, "");
653 } catch (CoreException ce) {
654 originalFileName = "";
659 private void updatePathMapFromConfig(ILaunchConfiguration config) {
662 if (config != null) {
663 envVars = config.getAttribute(
664 PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
666 updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
667 setPathMapButtonsEnableState();
668 } catch (CoreException ce) {
673 private void updatePathMapTable(Map map, Table tableWidget) {
674 tableWidget.removeAll();
678 Iterator iterator = map.keySet().iterator();
679 while (iterator.hasNext()) {
680 String key = (String) iterator.next();
681 String value = (String) map.get(key);
682 TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
683 tableItem.setText(new String[] { key, value });
687 // protected void initializeLoadPath(ILaunchConfiguration configuration) {
688 // boolean useDefaultLoadPath = true;
690 // useDefaultLoadPath =
691 // configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
693 // setUseLoadPathDefaults(useDefaultLoadPath);
694 // if (useDefaultLoadPath) {
695 // String projectName =
696 // configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,
698 // if (projectName != "") {
699 // IProject aProject =
700 // PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
701 // if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
702 // JavaProject thePHPProject = new JavaProject();
703 // thePHPProject.setProject(aProject);
704 // List loadPathEntries = thePHPProject.getLoadPathEntries();
705 // loadPathListViewer.setInput(loadPathEntries);
709 // } catch (CoreException e) {
714 // protected void setUseLoadPathDefaults(boolean useDefaults) {
715 // loadPathListViewer.getList().setEnabled(!useDefaults);
716 // // loadPathDefaultButton.setSelection(useDefaults);
719 protected void initializeInterpreterSelection(
720 ILaunchConfiguration configuration) {
721 String interpreterName = null;
723 interpreterName = configuration.getAttribute(
724 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
725 } catch (CoreException e) {
728 if (interpreterName != null && !interpreterName.equals("")) {
729 interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
731 if (interpreterCombo.getSelectionIndex() < 0) {
732 // previous definition had been deleted
733 ((ILaunchConfigurationWorkingCopy) configuration).setAttribute(
734 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
735 setErrorMessage(PHPDebugUiMessages
736 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
740 protected void initializeInterpreterCombo(Combo interpreterCombo) {
741 installedInterpretersWorkingCopy = new ArrayList();
742 installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault()
743 .getInstalledInterpreters());
745 String[] interpreterNames = new String[installedInterpretersWorkingCopy
747 for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy
748 .size(); interpreterIndex++) {
749 PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy
750 .get(interpreterIndex);
751 interpreterNames[interpreterIndex] = interpreter
752 .getInstallLocation().toString();
754 interpreterCombo.setItems(interpreterNames);
756 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
757 .getSelectedInterpreter();
758 if (selectedInterpreter != null)
759 interpreterCombo.select(interpreterCombo
760 .indexOf(selectedInterpreter.getInstallLocation()
764 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
765 int selectionIndex = interpreterCombo.getSelectionIndex();
766 if (selectionIndex >= 0)
767 configuration.setAttribute(
768 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
769 interpreterCombo.getItem(selectionIndex));
771 // configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
772 // loadPathDefaultButton.getSelection());
774 // if (!loadPathDefaultButton.getSelection()) {
775 // List loadPathEntries = (List) loadPathListViewer.getInput();
776 // List loadPathStrings = new ArrayList();
777 // for (Iterator iterator = loadPathEntries.iterator();
778 // iterator.hasNext();) {
779 // LoadPathEntry entry = (LoadPathEntry) iterator.next();
780 // loadPathStrings.add(entry.getPath().toString());
782 // configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH,
786 configuration.setAttribute(
787 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
788 fRemoteDebugCheckBox.getSelection());
789 configuration.setAttribute(
790 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
791 fRemoteDebugTranslate.getSelection());
792 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP,
793 getMapFromPathMapTable());
794 configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,
795 fRemoteSourcePath.getText());
796 configuration.setAttribute(
797 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
798 fOpenDBGSessionInBrowserCheckBox.getSelection());
801 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
802 fOpenDBGSessionInExternalBrowserCheckBox.getSelection());
805 protected Composite createPageRoot(Composite parent) {
806 Composite composite = new Composite(parent, SWT.NULL);
807 GridLayout layout = new GridLayout();
808 layout.numColumns = 2;
809 composite.setLayout(layout);
810 createVerticalSpacer(composite, 2);
811 setControl(composite);
816 private Map getMapFromPathMapTable() {
817 TableItem[] items = fRemoteDebugPathMapTable.getItems();
818 if (items.length == 0) {
821 Map map = new HashMap(items.length);
822 for (int i = 0; i < items.length; i++) {
823 TableItem item = items[i];
824 String key = item.getText(0);
825 String value = item.getText(1);
831 public String getName() {
832 return PHPDebugUiMessages
833 .getString("LaunchConfigurationTab.PHPEnvironment.name");
836 public boolean isValid(ILaunchConfiguration launchConfig) {
838 if (launchConfig.getAttribute(
839 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "")
841 if (!launchConfig.getAttribute(
842 PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false)) {
843 setErrorMessage(PHPDebugUiMessages
844 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
848 } catch (CoreException e) {
852 setErrorMessage(null);
856 protected void log(Throwable t) {
857 PHPDebugUiPlugin.log(t);
860 public Image getImage() {
861 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
864 private void makeupTargetFile() {
865 if (!fRemoteDebugCheckBox.getSelection() || originalFileName.equals("")) {
866 targetFile.setText("");
870 // see net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.MapPath(PHPLineBreakpoint)
872 IPath remoteSourcePath = new Path(fRemoteSourcePath.getText());
873 IPath filename = new Path(originalFileName);
874 filename = remoteSourcePath.append(filename);
875 String path = filename.toOSString();
876 Map pathmap = getMapFromPathMapTable();
878 if (pathmap != null) {
879 Iterator it = pathmap.keySet().iterator();
880 while (it.hasNext()) {
881 String k = (String) it.next();
882 if (path.startsWith(k)) {
883 path = pathmap.get(k) + path.substring(k.length());
889 if (remoteSourcePath.isEmpty()) {
890 if (pathmap != null) {
891 Iterator it = pathmap.keySet().iterator();
892 while (it.hasNext()) {
893 String local = (String) it.next();
894 IPath remotePath = new Path((String) pathmap.get(local));
895 IPath localPath = new Path(local);
896 if (localPath.isPrefixOf(filename)) {
897 IPath newpath = filename.removeFirstSegments(localPath
898 .matchingFirstSegments(filename));
899 newpath = remotePath.append(newpath);
900 path = newpath.toString();
901 if (path.substring(0, 1).equals("/")) {
902 path = path.replace('\\', '/');
904 path = path.replace('/', '\\');
911 if (fRemoteDebugTranslate.getSelection()) {
912 if (remoteSourcePath.toString().substring(0, 1).equals("/")) {
913 path = path.replace('\\', '/');
915 path = path.replace('/', '\\');
920 targetFile.setText(path);