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;
61 protected Button fRelaunchOnScriptTerminationCheckBox;
62 protected Button fRemoteDebugTranslate;
63 protected Button fOpenDBGSessionInBrowserCheckBox;
64 protected Button fOpenDBGSessionInExternalBrowserCheckBox;
65 protected Button fPathMapRemoveButton;
66 protected Button fPathMapAddButton;
67 protected Button fPathMapEditButton;
68 protected Text fRemoteSourcePath;
69 protected Table fRemoteDebugPathMapTable;
70 protected TabFolder tabFolder;
72 private Text targetFile;
74 private String originalFileName = "";
76 private class RemoteDebugTabListener extends SelectionAdapter implements
82 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
84 public void modifyText(ModifyEvent e) {
85 updateLaunchConfigurationDialog();
92 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
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 == fRelaunchOnScriptTerminationCheckBox) {
107 setRemoteTabEnableState();
108 } else if (source == fRemoteDebugTranslate) {
109 setRemoteTabEnableState();
110 } else if (source == fOpenDBGSessionInBrowserCheckBox) {
111 setRemoteTabEnableState();
113 updateLaunchConfigurationDialog();
120 private static final String EMPTY_STRING = ""; //$NON-NLS-1$
121 private RemoteDebugTabListener fListener = new RemoteDebugTabListener();
122 private static final boolean DEFAULT_REMOTE_DEBUG = false;
123 private static final boolean DEFAULT_REMOTE_DEBUG_TRANSLATE = false;
124 private static final boolean DEFAULT_OPEN_DBGSESSION_IN_BROWSER = true;
125 private static final boolean DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER = false;
126 private static final boolean DEFAULT_RELAUNCH_ON_SCRIPT_TERMINATION = true;
128 static String[] columnTitles = {
130 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
132 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.remote") };
134 public PHPEnvironmentTab() {
138 public void createControl(Composite parent) {
139 Composite composite = createPageRoot(parent);
141 tabFolder = new TabFolder(composite, SWT.NONE);
142 GridData gridData = new GridData(GridData.FILL_BOTH);
143 tabFolder.setLayoutData(gridData);
145 // addLoadPathTab(tabFolder);
146 addRemoteDebugTab(tabFolder);
147 addInterpreterTab(tabFolder);
150 protected void addRemoteDebugTab(TabFolder tabFolder) {
153 TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
155 .setText(PHPDebugUiMessages
156 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
158 Composite comp = new Composite(tabFolder, SWT.NONE);
159 comp.setLayout(new GridLayout());
160 remoteDebugTab.setControl(comp);
163 fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
165 .setText(PHPDebugUiMessages
166 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
167 fRemoteDebugCheckBox.setLayoutData(new GridData(
168 GridData.HORIZONTAL_ALIGN_BEGINNING));
169 fRemoteDebugCheckBox.addSelectionListener(fListener);
171 fRemoteDebugTranslate = new Button(comp, SWT.CHECK);
172 fRemoteDebugTranslate
173 .setText(PHPDebugUiMessages
174 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteTranslate.label"));
175 fRemoteDebugTranslate.setLayoutData(new GridData(
176 GridData.HORIZONTAL_ALIGN_BEGINNING));
177 fRemoteDebugTranslate.addSelectionListener(fListener);
179 fOpenDBGSessionInBrowserCheckBox = new Button(comp, SWT.CHECK);
180 fOpenDBGSessionInBrowserCheckBox
181 .setText(PHPDebugUiMessages
182 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInBrowserCheckBox.label"));
183 fOpenDBGSessionInBrowserCheckBox.setLayoutData(new GridData(
184 GridData.HORIZONTAL_ALIGN_BEGINNING));
185 fOpenDBGSessionInBrowserCheckBox.addSelectionListener(fListener);
188 fOpenDBGSessionInExternalBrowserCheckBox = new Button(comp, SWT.CHECK);
189 fOpenDBGSessionInExternalBrowserCheckBox
190 .setText(PHPDebugUiMessages
191 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInExternalBrowserCheckBox.label"));
192 fOpenDBGSessionInExternalBrowserCheckBox.setLayoutData(new GridData(
194 ((GridData) fOpenDBGSessionInExternalBrowserCheckBox.getLayoutData()).horizontalIndent = 16;
195 fOpenDBGSessionInExternalBrowserCheckBox
196 .addSelectionListener(fListener);
199 fRelaunchOnScriptTerminationCheckBox = new Button (comp, SWT.CHECK);
200 fRelaunchOnScriptTerminationCheckBox
201 .setText (PHPDebugUiMessages
202 .getString ("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RelaunchOnScriptTermination.label"));
203 fRelaunchOnScriptTerminationCheckBox.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING));
204 fRelaunchOnScriptTerminationCheckBox.addSelectionListener (fListener);
206 label = new Label(comp, SWT.NONE);
208 .setText(PHPDebugUiMessages
209 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
210 fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
211 gd = new GridData(GridData.FILL_HORIZONTAL);
212 fRemoteSourcePath.setLayoutData(gd);
213 fRemoteSourcePath.addModifyListener(fListener);
215 // addendum - make an effect of RemoteSourcePath clear
216 Composite targetComp = new Composite(comp, SWT.NONE);
217 targetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
218 GridLayout targetLayout = new GridLayout(4, false);
219 targetLayout.marginHeight = 0;
220 targetLayout.marginWidth = 3;
221 targetComp.setLayout(targetLayout);
222 Color targetColor = new Color(null, 160, 160, 160);
223 Label label_lp = new Label(targetComp, SWT.NONE);
224 label_lp.setText("(");
225 label_lp.setForeground(targetColor);
226 label_lp.setLayoutData(new GridData(GridData.BEGINNING));
227 Label targetLabel = new Label(targetComp, SWT.NONE);
229 .setText(PHPDebugUiMessages
230 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.TargetFile.label"));
231 targetLabel.setForeground(targetColor);
232 targetLabel.setLayoutData(new GridData(GridData.BEGINNING));
233 targetFile = new Text(targetComp, SWT.SINGLE);
234 targetFile.setForeground(targetColor);
235 targetFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
236 targetFile.setEditable(false);
237 Label label_rp = new Label(targetComp, SWT.NONE);
238 label_rp.setText(")");
239 label_rp.setForeground(targetColor);
240 label_rp.setLayoutData(new GridData(GridData.END));
243 createVerticalSpacer(comp, 1);
245 Composite pathMapComp = new Composite(comp, SWT.NONE);
246 gd = new GridData(GridData.FILL_BOTH);
247 pathMapComp.setLayoutData(gd);
248 GridLayout parametersLayout = new GridLayout();
249 parametersLayout.numColumns = 2;
250 parametersLayout.marginHeight = 0;
251 parametersLayout.marginWidth = 0;
252 pathMapComp.setLayout(parametersLayout);
254 Label pathMapLabel = new Label(pathMapComp, SWT.NONE);
256 .setText(PHPDebugUiMessages
257 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.label"));
259 gd.horizontalSpan = 2;
260 pathMapLabel.setLayoutData(gd);
262 fRemoteDebugPathMapTable = new Table(pathMapComp, SWT.BORDER
264 TableLayout tableLayout = new TableLayout();
265 fRemoteDebugPathMapTable.setLayout(tableLayout);
267 gd = new GridData(GridData.FILL_BOTH);
268 fRemoteDebugPathMapTable.setLayoutData(gd);
269 TableColumn column1 = new TableColumn(this.fRemoteDebugPathMapTable,
272 .setText(PHPDebugUiMessages
273 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.local")); //$NON-NLS-1$
274 TableColumn column2 = new TableColumn(this.fRemoteDebugPathMapTable,
277 .setText(PHPDebugUiMessages
278 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.remote")); //$NON-NLS-1$
279 tableLayout.addColumnData(new ColumnWeightData(100));
280 tableLayout.addColumnData(new ColumnWeightData(100));
281 fRemoteDebugPathMapTable.setHeaderVisible(true);
282 fRemoteDebugPathMapTable.setLinesVisible(true);
283 fRemoteDebugPathMapTable.addSelectionListener(fListener);
284 fRemoteDebugPathMapTable.addMouseListener(new MouseAdapter() {
285 public void mouseDoubleClick(MouseEvent e) {
286 setPathMapButtonsEnableState();
287 if (fPathMapEditButton.isEnabled()) {
288 handlePathMapEditButtonSelected();
292 // fRemoteDebugPathMapTable.setEnabled(false);
294 Composite envButtonComp = new Composite(pathMapComp, SWT.NONE);
295 GridLayout envButtonLayout = new GridLayout();
296 envButtonLayout.marginHeight = 0;
297 envButtonLayout.marginWidth = 0;
298 envButtonComp.setLayout(envButtonLayout);
299 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
300 | GridData.HORIZONTAL_ALIGN_FILL);
301 envButtonComp.setLayoutData(gd);
303 fPathMapAddButton = createPushButton(
306 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Add.label"), null); //$NON-NLS-1$
307 fPathMapAddButton.addSelectionListener(fListener);
308 // fPathMapAddButton.setEnabled(false);
310 fPathMapEditButton = createPushButton(
313 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Edit.label"), null); //$NON-NLS-1$
314 fPathMapEditButton.addSelectionListener(fListener);
315 // fPathMapEditButton.setEnabled(false);
317 fPathMapRemoveButton = createPushButton(
320 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Remove.label"), null); //$NON-NLS-1$
321 fPathMapRemoveButton.addSelectionListener(fListener);
322 // fPathMapRemoveButton.setEnabled(false);
326 void handlePathMapAddButtonSelected() {
327 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
328 "Edit File Map", new String[] { EMPTY_STRING, EMPTY_STRING });
329 openNewPathMapDialog(dialog, null);
331 // if (dialog.open()==EditPathMapDialog.OK)
333 // TableItem item = new TableItem (fRemoteDebugPathMapTable, SWT.NONE);
334 // item.setText(0,dialog.getLocalPath());
335 // item.setText(1,dialog.getRemotePath());
336 // updateLaunchConfigurationDialog();
338 // updateLaunchConfigurationDialog();
339 setPathMapButtonsEnableState();
342 void handlePathMapRemoveButtonSelected() {
343 int[] selectedIndices = this.fRemoteDebugPathMapTable
344 .getSelectionIndices();
345 this.fRemoteDebugPathMapTable.remove(selectedIndices);
346 setPathMapButtonsEnableState();
347 updateLaunchConfigurationDialog();
350 void handlePathMapEditButtonSelected() {
351 TableItem selectedItem = this.fRemoteDebugPathMapTable.getSelection()[0];
352 String local = selectedItem.getText(0);
353 String remote = selectedItem.getText(1);
354 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
355 "Edit File Map", new String[] { local, remote });
356 openNewPathMapDialog(dialog, selectedItem);
360 * Set the enabled state of whole tab.
362 private void setRemoteTabEnableState() {
363 boolean state = fRemoteDebugCheckBox.getSelection();
365 fRemoteSourcePath.setEnabled (state);
366 fRemoteDebugTranslate.setEnabled (state);
367 fRemoteDebugPathMapTable.setEnabled (state);
370 fPathMapEditButton.setEnabled (false);
371 fPathMapRemoveButton.setEnabled (false);
372 fPathMapAddButton.setEnabled (false);
373 fOpenDBGSessionInBrowserCheckBox.setEnabled (false);
374 fOpenDBGSessionInExternalBrowserCheckBox.setEnabled (false);
376 setPathMapButtonsEnableState ();
379 updateLaunchConfigurationDialog ();
383 * Set the enabled state of the three environment variable-related buttons
384 * based on the selection in the PathMapTable widget.
386 private void setPathMapButtonsEnableState() {
387 // just do nothing for now
389 if (fRemoteDebugCheckBox.getSelection ()) {
390 fOpenDBGSessionInBrowserCheckBox.setEnabled (true);
391 fOpenDBGSessionInExternalBrowserCheckBox
392 .setEnabled (fOpenDBGSessionInBrowserCheckBox.getSelection ());
393 fRemoteDebugTranslate.setEnabled (true);
395 int selectCount = this.fRemoteDebugPathMapTable
396 .getSelectionIndices ().length;
398 if (selectCount < 1) {
399 fPathMapEditButton.setEnabled (false);
400 fPathMapRemoveButton.setEnabled (false);
402 fPathMapRemoveButton.setEnabled (true);
404 if (selectCount == 1) {
405 fPathMapEditButton.setEnabled (true);
407 fPathMapEditButton.setEnabled (false);
411 fPathMapAddButton.setEnabled (true);
416 * Show the specified dialog and update the pathMapTable table based on its
420 * the item to update, or <code>null</code> if adding a new
423 private void openNewPathMapDialog(EditPathMapDialog dialog,
424 TableItem updateItem) {
425 if (dialog.open() != EditPathMapDialog.OK) {
428 String[] pathPair = dialog.getPathPair();
429 TableItem tableItem = updateItem;
430 if (tableItem == null) {
431 tableItem = getTableItemForName(pathPair[0]);
432 if (tableItem == null) {
433 tableItem = new TableItem(this.fRemoteDebugPathMapTable,
437 tableItem.setText(pathPair);
438 this.fRemoteDebugPathMapTable
439 .setSelection(new TableItem[] { tableItem });
440 updateLaunchConfigurationDialog();
444 * Helper method that indicates whether the specified parameter name is
445 * already present in the parameters table.
447 private TableItem getTableItemForName(String candidateName) {
448 TableItem[] items = this.fRemoteDebugPathMapTable.getItems();
449 for (int i = 0; i < items.length; i++) {
450 String name = items[i].getText(0);
451 if (name.equals(candidateName)) {
458 // protected void addLoadPathTab(TabFolder tabFolder) {
459 // Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
460 // loadPathComposite.setLayout(new GridLayout());
462 // loadPathListViewer = new ListViewer(loadPathComposite, SWT.BORDER |
463 // SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
464 // loadPathListViewer.setContentProvider(new ListContentProvider());
465 // loadPathListViewer.setLabelProvider(new LoadPathEntryLabelProvider());
466 // loadPathListViewer.getList().setLayoutData(new
467 // GridData(GridData.FILL_BOTH));
469 // TabItem loadPathTab = new TabItem(tabFolder, SWT.NONE, 0);
470 // loadPathTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathTab.label"));
471 // loadPathTab.setControl(loadPathComposite);
472 // loadPathTab.setData(loadPathListViewer);
474 // loadPathDefaultButton = new Button(loadPathComposite, SWT.CHECK);
475 // loadPathDefaultButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label"));
476 // loadPathDefaultButton.setLayoutData(new
477 // GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
478 // loadPathDefaultButton.addSelectionListener(getLoadPathDefaultButtonSelectionListener());
480 // loadPathDefaultButton.setEnabled(false); //for now, until the load path
481 // is customizable on the configuration
484 // protected SelectionListener getLoadPathSelectionListener() {
485 // return new SelectionAdapter() {
486 // public void widgetSelected(SelectionEvent e) {
487 // System.out.println("Loadpath list selection occurred: "
493 // protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
494 // return new SelectionAdapter() {
495 // public void widgetSelected(SelectionEvent e) {
496 // setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
501 protected void addInterpreterTab(TabFolder tabFolder) {
502 Composite interpreterComposite = new Composite(tabFolder, SWT.NONE);
503 GridLayout layout = new GridLayout();
504 layout.numColumns = 2;
505 // layout.marginHeight = 0;
506 // layout.marginWidth = 0;
507 interpreterComposite.setLayout(layout);
508 interpreterComposite.setLayoutData(new GridData(
509 GridData.FILL_HORIZONTAL));
511 createVerticalSpacer(interpreterComposite, 2);
513 interpreterCombo = new Combo(interpreterComposite, SWT.READ_ONLY);
514 interpreterCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
515 initializeInterpreterCombo(interpreterCombo);
516 interpreterCombo.addModifyListener(getInterpreterComboModifyListener());
518 Button interpreterAddButton = new Button(interpreterComposite, SWT.PUSH);
520 .setText(PHPDebugUiMessages
521 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label"));
522 interpreterAddButton.addSelectionListener(new SelectionAdapter() {
523 public void widgetSelected(SelectionEvent evt) {
524 PHPInterpreter newInterpreter = new PHPInterpreter(null);
525 File phpRuntime = PHPInterpreterPreferencePage.getFile(
527 if (phpRuntime != null) {
528 newInterpreter.setInstallLocation(phpRuntime);
529 PHPRuntime.getDefault().addInstalledInterpreter(
531 interpreterCombo.add(newInterpreter.getInstallLocation()
533 interpreterCombo.select(interpreterCombo
534 .indexOf(newInterpreter.getInstallLocation()
540 TabItem interpreterTab = new TabItem(tabFolder, SWT.NONE);
542 .setText(PHPDebugUiMessages
543 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterTab.label"));
544 interpreterTab.setControl(interpreterComposite);
547 protected ModifyListener getInterpreterComboModifyListener() {
548 return new ModifyListener() {
549 public void modifyText(ModifyEvent evt) {
550 updateLaunchConfigurationDialog();
555 protected void createVerticalSpacer(Composite comp, int colSpan) {
556 Label label = new Label(comp, SWT.NONE);
557 GridData gd = new GridData();
558 gd.horizontalSpan = colSpan;
559 label.setLayoutData(gd);
562 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
563 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
564 .getSelectedInterpreter();
565 if (selectedInterpreter != null) {
566 String interpreterLocation = selectedInterpreter
567 .getInstallLocation().toString();
568 configuration.setAttribute(
569 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
570 interpreterLocation);
573 String projectName = configuration.getAttribute(
574 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
575 if (projectName != "") {
576 IProject project = ResourcesPlugin.getWorkspace().getRoot()
577 .getProject(projectName);
578 if (project != null) {
579 IPath remotePath = project.getFullPath();
580 String fileName = configuration.getAttribute(
581 PHPLaunchConfigurationAttribute.FILE_NAME, "");
582 if (fileName != "") {
583 Path filePath = new Path(fileName);
584 remotePath = remotePath.append(filePath
585 .removeLastSegments(1));
587 configuration.setAttribute(
588 PHPLaunchConfigurationAttribute.REMOTE_PATH,
589 remotePath.toOSString());
592 } catch (CoreException e) {
597 public void initializeFrom(ILaunchConfiguration configuration) {
598 // initializeLoadPath(configuration);
599 initializeInterpreterSelection(configuration);
600 initializeRemoteDebug(configuration);
603 protected void initializeRemoteDebug(ILaunchConfiguration configuration) {
605 fRemoteDebugCheckBox.setSelection(configuration.getAttribute(
606 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
607 DEFAULT_REMOTE_DEBUG));
608 } catch (CoreException ce) {
609 fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
612 tabFolder.setSelection(fRemoteDebugCheckBox.getSelection() ? 0 : 1);
615 fRemoteDebugTranslate.setSelection(configuration.getAttribute(
616 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
617 DEFAULT_REMOTE_DEBUG_TRANSLATE));
618 } catch (CoreException ce) {
619 fRemoteDebugTranslate.setSelection(DEFAULT_REMOTE_DEBUG_TRANSLATE);
623 fOpenDBGSessionInBrowserCheckBox
624 .setSelection(configuration
626 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
627 DEFAULT_OPEN_DBGSESSION_IN_BROWSER));
628 } catch (CoreException ce) {
629 fOpenDBGSessionInBrowserCheckBox
630 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
634 fOpenDBGSessionInExternalBrowserCheckBox
635 .setSelection(configuration
637 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
638 DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER));
639 } catch (CoreException ce) {
640 fOpenDBGSessionInExternalBrowserCheckBox
641 .setSelection (DEFAULT_OPEN_DBGSESSION_IN_EXTERNAL_BROWSER);
645 fRelaunchOnScriptTerminationCheckBox
646 .setSelection (configuration
648 PHPLaunchConfigurationAttribute.RELAUNCH_ON_SCRIPT_TERMINATION,
649 DEFAULT_RELAUNCH_ON_SCRIPT_TERMINATION));
650 } catch (CoreException ce) {
651 fRelaunchOnScriptTerminationCheckBox
652 .setSelection (DEFAULT_RELAUNCH_ON_SCRIPT_TERMINATION);
656 setRemoteTabEnableState();
659 fRemoteSourcePath.setText(configuration.getAttribute(
660 PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
661 } catch (CoreException ce) {
662 fRemoteSourcePath.setText("");
665 updatePathMapFromConfig(configuration);
668 originalFileName = configuration.getAttribute(
669 PHPLaunchConfigurationAttribute.FILE_NAME, "");
671 } catch (CoreException ce) {
672 originalFileName = "";
677 private void updatePathMapFromConfig(ILaunchConfiguration config) {
680 if (config != null) {
681 envVars = config.getAttribute(
682 PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
684 updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
685 setPathMapButtonsEnableState();
686 } catch (CoreException ce) {
691 private void updatePathMapTable(Map map, Table tableWidget) {
692 tableWidget.removeAll();
696 Iterator iterator = map.keySet().iterator();
697 while (iterator.hasNext()) {
698 String key = (String) iterator.next();
699 String value = (String) map.get(key);
700 TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
701 tableItem.setText(new String[] { key, value });
705 // protected void initializeLoadPath(ILaunchConfiguration configuration) {
706 // boolean useDefaultLoadPath = true;
708 // useDefaultLoadPath =
709 // configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
711 // setUseLoadPathDefaults(useDefaultLoadPath);
712 // if (useDefaultLoadPath) {
713 // String projectName =
714 // configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,
716 // if (projectName != "") {
717 // IProject aProject =
718 // PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
719 // if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
720 // JavaProject thePHPProject = new JavaProject();
721 // thePHPProject.setProject(aProject);
722 // List loadPathEntries = thePHPProject.getLoadPathEntries();
723 // loadPathListViewer.setInput(loadPathEntries);
727 // } catch (CoreException e) {
732 // protected void setUseLoadPathDefaults(boolean useDefaults) {
733 // loadPathListViewer.getList().setEnabled(!useDefaults);
734 // // loadPathDefaultButton.setSelection(useDefaults);
737 protected void initializeInterpreterSelection(
738 ILaunchConfiguration configuration) {
739 String interpreterName = null;
741 interpreterName = configuration.getAttribute(
742 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
743 } catch (CoreException e) {
746 if (interpreterName != null && !interpreterName.equals("")) {
747 interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
749 if (interpreterCombo.getSelectionIndex() < 0) {
750 // previous definition had been deleted
751 ((ILaunchConfigurationWorkingCopy) configuration).setAttribute(
752 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
753 setErrorMessage(PHPDebugUiMessages
754 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
758 protected void initializeInterpreterCombo(Combo interpreterCombo) {
759 installedInterpretersWorkingCopy = new ArrayList();
760 installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault()
761 .getInstalledInterpreters());
763 String[] interpreterNames = new String[installedInterpretersWorkingCopy
765 for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy
766 .size(); interpreterIndex++) {
767 PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy
768 .get(interpreterIndex);
769 interpreterNames[interpreterIndex] = interpreter
770 .getInstallLocation().toString();
772 interpreterCombo.setItems(interpreterNames);
774 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
775 .getSelectedInterpreter();
776 if (selectedInterpreter != null)
777 interpreterCombo.select(interpreterCombo
778 .indexOf(selectedInterpreter.getInstallLocation()
782 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
783 int selectionIndex = interpreterCombo.getSelectionIndex();
784 if (selectionIndex >= 0)
785 configuration.setAttribute(
786 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
787 interpreterCombo.getItem(selectionIndex));
789 // configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
790 // loadPathDefaultButton.getSelection());
792 // if (!loadPathDefaultButton.getSelection()) {
793 // List loadPathEntries = (List) loadPathListViewer.getInput();
794 // List loadPathStrings = new ArrayList();
795 // for (Iterator iterator = loadPathEntries.iterator();
796 // iterator.hasNext();) {
797 // LoadPathEntry entry = (LoadPathEntry) iterator.next();
798 // loadPathStrings.add(entry.getPath().toString());
800 // configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH,
804 configuration.setAttribute(
805 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
806 fRemoteDebugCheckBox.getSelection());
807 configuration.setAttribute(
808 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
809 fRemoteDebugTranslate.getSelection());
810 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP,
811 getMapFromPathMapTable());
812 configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,
813 fRemoteSourcePath.getText());
814 configuration.setAttribute(
815 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
816 fOpenDBGSessionInBrowserCheckBox.getSelection());
817 configuration.setAttribute(
818 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
819 fOpenDBGSessionInExternalBrowserCheckBox.getSelection());
820 configuration.setAttribute(
821 PHPLaunchConfigurationAttribute.RELAUNCH_ON_SCRIPT_TERMINATION,
822 fRelaunchOnScriptTerminationCheckBox.getSelection());
825 protected Composite createPageRoot(Composite parent) {
826 Composite composite = new Composite(parent, SWT.NULL);
827 GridLayout layout = new GridLayout();
828 layout.numColumns = 2;
829 composite.setLayout(layout);
830 createVerticalSpacer(composite, 2);
831 setControl(composite);
836 private Map getMapFromPathMapTable() {
837 TableItem[] items = fRemoteDebugPathMapTable.getItems();
838 if (items.length == 0) {
841 Map map = new HashMap(items.length);
842 for (int i = 0; i < items.length; i++) {
843 TableItem item = items[i];
844 String key = item.getText(0);
845 String value = item.getText(1);
851 public String getName() {
852 return PHPDebugUiMessages
853 .getString("LaunchConfigurationTab.PHPEnvironment.name");
856 public boolean isValid(ILaunchConfiguration launchConfig) {
858 if (launchConfig.getAttribute(
859 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "")
861 if (!launchConfig.getAttribute(
862 PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false)) {
863 setErrorMessage(PHPDebugUiMessages
864 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
868 } catch (CoreException e) {
872 setErrorMessage(null);
876 protected void log(Throwable t) {
877 PHPDebugUiPlugin.log(t);
880 public Image getImage() {
881 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
884 private void makeupTargetFile() {
885 if (!fRemoteDebugCheckBox.getSelection() || originalFileName.equals("")) {
886 targetFile.setText("");
890 // see net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.MapPath(PHPLineBreakpoint)
892 IPath remoteSourcePath = new Path(fRemoteSourcePath.getText());
893 IPath filename = new Path(originalFileName);
894 filename = remoteSourcePath.append(filename);
895 String path = filename.toOSString();
896 Map pathmap = getMapFromPathMapTable();
898 if (pathmap != null) {
899 Iterator it = pathmap.keySet().iterator();
900 while (it.hasNext()) {
901 String k = (String) it.next();
902 if (path.startsWith(k)) {
903 path = pathmap.get(k) + path.substring(k.length());
909 if (remoteSourcePath.isEmpty()) {
910 if (pathmap != null) {
911 Iterator it = pathmap.keySet().iterator();
912 while (it.hasNext()) {
913 String local = (String) it.next();
914 IPath remotePath = new Path((String) pathmap.get(local));
915 IPath localPath = new Path(local);
916 if (localPath.isPrefixOf(filename)) {
917 IPath newpath = filename.removeFirstSegments(localPath
918 .matchingFirstSegments(filename));
919 newpath = remotePath.append(newpath);
920 path = newpath.toString();
921 if (path.substring(0, 1).equals("/")) {
922 path = path.replace('\\', '/');
924 path = path.replace('/', '\\');
931 if (fRemoteDebugTranslate.getSelection()) {
932 if (remoteSourcePath.toString().substring(0, 1).equals("/")) {
933 path = path.replace('\\', '/');
935 path = path.replace('/', '\\');
940 targetFile.setText(path);