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 addInterpreterTab(tabFolder);
157 addRemoteDebugTab(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.getLocation();
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 if (fRemoteDebugCheckBox.getSelection()) {
610 tabFolder.setSelection(0);
613 fRemoteDebugTranslate.setSelection(configuration.getAttribute(
614 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
615 DEFAULT_REMOTE_DEBUG_TRANSLATE));
616 } catch (CoreException ce) {
617 fRemoteDebugTranslate.setSelection(DEFAULT_REMOTE_DEBUG_TRANSLATE);
620 fOpenDBGSessionInBrowserCheckBox
621 .setSelection(configuration
623 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
624 DEFAULT_OPEN_DBGSESSION_IN_BROWSER));
625 } catch (CoreException ce) {
626 fOpenDBGSessionInBrowserCheckBox
627 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
630 fOpenDBGSessionInExternalBrowserCheckBox
631 .setSelection(configuration
633 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
634 DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER));
635 } catch (CoreException ce) {
636 fOpenDBGSessionInExternalBrowserCheckBox
637 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER);
640 setRemoteTabEnableState();
643 fRemoteSourcePath.setText(configuration.getAttribute(
644 PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
645 } catch (CoreException ce) {
646 fRemoteSourcePath.setText("");
649 updatePathMapFromConfig(configuration);
652 originalFileName = configuration.getAttribute(
653 PHPLaunchConfigurationAttribute.FILE_NAME, "");
655 } catch (CoreException ce) {
656 originalFileName = "";
661 private void updatePathMapFromConfig(ILaunchConfiguration config) {
664 if (config != null) {
665 envVars = config.getAttribute(
666 PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
668 updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
669 setPathMapButtonsEnableState();
670 } catch (CoreException ce) {
675 private void updatePathMapTable(Map map, Table tableWidget) {
676 tableWidget.removeAll();
680 Iterator iterator = map.keySet().iterator();
681 while (iterator.hasNext()) {
682 String key = (String) iterator.next();
683 String value = (String) map.get(key);
684 TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
685 tableItem.setText(new String[] { key, value });
689 // protected void initializeLoadPath(ILaunchConfiguration configuration) {
690 // boolean useDefaultLoadPath = true;
692 // useDefaultLoadPath =
693 // configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
695 // setUseLoadPathDefaults(useDefaultLoadPath);
696 // if (useDefaultLoadPath) {
697 // String projectName =
698 // configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,
700 // if (projectName != "") {
701 // IProject aProject =
702 // PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
703 // if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
704 // JavaProject thePHPProject = new JavaProject();
705 // thePHPProject.setProject(aProject);
706 // List loadPathEntries = thePHPProject.getLoadPathEntries();
707 // loadPathListViewer.setInput(loadPathEntries);
711 // } catch (CoreException e) {
716 protected void setUseLoadPathDefaults(boolean useDefaults) {
717 loadPathListViewer.getList().setEnabled(!useDefaults);
718 // loadPathDefaultButton.setSelection(useDefaults);
721 protected void initializeInterpreterSelection(
722 ILaunchConfiguration configuration) {
723 String interpreterName = null;
725 interpreterName = configuration.getAttribute(
726 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
727 } catch (CoreException e) {
730 if (interpreterName != null && !interpreterName.equals(""))
731 interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
734 protected void initializeInterpreterCombo(Combo interpreterCombo) {
735 installedInterpretersWorkingCopy = new ArrayList();
736 installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault()
737 .getInstalledInterpreters());
739 String[] interpreterNames = new String[installedInterpretersWorkingCopy
741 for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy
742 .size(); interpreterIndex++) {
743 PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy
744 .get(interpreterIndex);
745 interpreterNames[interpreterIndex] = interpreter
746 .getInstallLocation().toString();
748 interpreterCombo.setItems(interpreterNames);
750 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
751 .getSelectedInterpreter();
752 if (selectedInterpreter != null)
753 interpreterCombo.select(interpreterCombo
754 .indexOf(selectedInterpreter.getInstallLocation()
758 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
759 int selectionIndex = interpreterCombo.getSelectionIndex();
760 if (selectionIndex >= 0)
761 configuration.setAttribute(
762 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
763 interpreterCombo.getItem(selectionIndex));
765 // configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
766 // loadPathDefaultButton.getSelection());
768 // if (!loadPathDefaultButton.getSelection()) {
769 // List loadPathEntries = (List) loadPathListViewer.getInput();
770 // List loadPathStrings = new ArrayList();
771 // for (Iterator iterator = loadPathEntries.iterator();
772 // iterator.hasNext();) {
773 // LoadPathEntry entry = (LoadPathEntry) iterator.next();
774 // loadPathStrings.add(entry.getPath().toString());
776 // configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH,
780 configuration.setAttribute(
781 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
782 fRemoteDebugCheckBox.getSelection());
783 configuration.setAttribute(
784 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
785 fRemoteDebugTranslate.getSelection());
786 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP,
787 getMapFromPathMapTable());
788 configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,
789 fRemoteSourcePath.getText());
790 configuration.setAttribute(
791 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
792 fOpenDBGSessionInBrowserCheckBox.getSelection());
795 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
796 fOpenDBGSessionInExternalBrowserCheckBox.getSelection());
799 protected Composite createPageRoot(Composite parent) {
800 Composite composite = new Composite(parent, SWT.NULL);
801 GridLayout layout = new GridLayout();
802 layout.numColumns = 2;
803 composite.setLayout(layout);
804 createVerticalSpacer(composite, 2);
805 setControl(composite);
810 private Map getMapFromPathMapTable() {
811 TableItem[] items = fRemoteDebugPathMapTable.getItems();
812 if (items.length == 0) {
815 Map map = new HashMap(items.length);
816 for (int i = 0; i < items.length; i++) {
817 TableItem item = items[i];
818 String key = item.getText(0);
819 String value = item.getText(1);
825 public String getName() {
826 return PHPDebugUiMessages
827 .getString("LaunchConfigurationTab.PHPEnvironment.name");
830 public boolean isValid(ILaunchConfiguration launchConfig) {
832 String selectedInterpreter = launchConfig.getAttribute(
833 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
834 if (selectedInterpreter.length() == 0) {
835 setErrorMessage(PHPDebugUiMessages
836 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
839 } catch (CoreException e) {
843 setErrorMessage(null);
847 protected void log(Throwable t) {
848 PHPDebugUiPlugin.log(t);
851 public Image getImage() {
852 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
855 private void makeupTargetFile() {
856 if (!fRemoteDebugCheckBox.getSelection() || originalFileName.equals("")) {
857 targetFile.setText("");
861 // see net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.MapPath(PHPLineBreakpoint)
863 IPath remoteSourcePath = new Path(fRemoteSourcePath.getText());
864 IPath filename = new Path(originalFileName);
865 filename = remoteSourcePath.append(filename);
866 String path = filename.toOSString();
867 Map pathmap = getMapFromPathMapTable();
869 if (pathmap != null) {
870 Iterator it = pathmap.keySet().iterator();
871 while (it.hasNext()) {
872 String k = (String) it.next();
873 if (path.startsWith(k)) {
874 path = pathmap.get(k) + path.substring(k.length());
880 if (remoteSourcePath.isEmpty()) {
881 if (pathmap != null) {
882 Iterator it = pathmap.keySet().iterator();
883 while (it.hasNext()) {
884 String local = (String) it.next();
885 IPath remotePath = new Path((String) pathmap.get(local));
886 IPath localPath = new Path(local);
887 if (localPath.isPrefixOf(filename)) {
888 IPath newpath = filename.removeFirstSegments(localPath
889 .matchingFirstSegments(filename));
890 newpath = remotePath.append(newpath);
891 path = newpath.toString();
892 if (path.substring(0, 1).equals("/")) {
893 path = path.replace('\\', '/');
895 path = path.replace('/', '\\');
902 if (fRemoteDebugTranslate.getSelection()) {
903 if (remoteSourcePath.toString().substring(0, 1).equals("/")) {
904 path = path.replace('\\', '/');
906 path = path.replace('/', '\\');
911 targetFile.setText(path);