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 fPathMapRemoveButton;
68 protected Button fPathMapAddButton;
70 protected Button fPathMapEditButton;
72 protected Text fRemoteSourcePath;
74 protected Table fRemoteDebugPathMapTable;
76 protected TabFolder tabFolder;
78 private Text targetFile;
80 private String originalFileName = "";
82 private class RemoteDebugTabListener extends SelectionAdapter implements
88 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
90 public void modifyText(ModifyEvent e) {
91 updateLaunchConfigurationDialog();
98 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
100 public void widgetSelected(SelectionEvent e) {
101 Object source = e.getSource();
102 if (source == fRemoteDebugPathMapTable) {
103 setPathMapButtonsEnableState();
104 } else if (source == fPathMapAddButton) {
105 handlePathMapAddButtonSelected();
106 } else if (source == fPathMapEditButton) {
107 handlePathMapEditButtonSelected();
108 } else if (source == fPathMapRemoveButton) {
109 handlePathMapRemoveButtonSelected();
110 } else if (source == fRemoteDebugCheckBox) {
111 setRemoteTabEnableState();
112 } else if (source == fRemoteDebugTranslate) {
113 setRemoteTabEnableState();
115 updateLaunchConfigurationDialog();
123 private static final String EMPTY_STRING = ""; //$NON-NLS-1$
125 private RemoteDebugTabListener fListener = new RemoteDebugTabListener();
127 private static final boolean DEFAULT_REMOTE_DEBUG = false;
129 private static final boolean DEFAULT_REMOTE_DEBUG_TRANSLATE = false;
131 private static final boolean DEFAULT_OPEN_DBGSESSION_IN_BROWSER = true;
133 static String[] columnTitles = {
135 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
137 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.remote") };
139 public PHPEnvironmentTab() {
143 public void createControl(Composite parent) {
144 Composite composite = createPageRoot(parent);
146 tabFolder = new TabFolder(composite, SWT.NONE);
147 GridData gridData = new GridData(GridData.FILL_BOTH);
148 tabFolder.setLayoutData(gridData);
150 // addLoadPathTab(tabFolder);
151 addInterpreterTab(tabFolder);
152 addRemoteDebugTab(tabFolder);
155 protected void addRemoteDebugTab(TabFolder tabFolder) {
158 TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
160 .setText(PHPDebugUiMessages
161 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
163 Composite comp = new Composite(tabFolder, SWT.NONE);
164 comp.setLayout(new GridLayout());
165 remoteDebugTab.setControl(comp);
168 fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
170 .setText(PHPDebugUiMessages
171 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
172 fRemoteDebugCheckBox.setLayoutData(new GridData(
173 GridData.HORIZONTAL_ALIGN_BEGINNING));
174 fRemoteDebugCheckBox.addSelectionListener(fListener);
176 fRemoteDebugTranslate = new Button(comp, SWT.CHECK);
177 fRemoteDebugTranslate
178 .setText(PHPDebugUiMessages
179 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteTranslate.label"));
180 fRemoteDebugTranslate.setLayoutData(new GridData(
181 GridData.HORIZONTAL_ALIGN_BEGINNING));
182 fRemoteDebugTranslate.addSelectionListener(fListener);
184 fOpenDBGSessionInBrowserCheckBox = new Button(comp, SWT.CHECK);
185 fOpenDBGSessionInBrowserCheckBox
186 .setText(PHPDebugUiMessages
187 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.OpenDBGSessionInBrowserCheckBox.label"));
188 fOpenDBGSessionInBrowserCheckBox.setLayoutData(new GridData(
189 GridData.HORIZONTAL_ALIGN_BEGINNING));
190 fOpenDBGSessionInBrowserCheckBox.addSelectionListener(fListener);
192 label = new Label(comp, SWT.NONE);
194 .setText(PHPDebugUiMessages
195 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
196 fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
197 gd = new GridData(GridData.FILL_HORIZONTAL);
198 fRemoteSourcePath.setLayoutData(gd);
199 fRemoteSourcePath.addModifyListener(fListener);
201 // addendum - make an effect of RemoteSourcePath clear
202 Composite targetComp = new Composite(comp, SWT.NONE);
203 targetComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
204 GridLayout targetLayout = new GridLayout(4, false);
205 targetLayout.marginHeight = 0;
206 targetLayout.marginWidth = 3;
207 targetComp.setLayout(targetLayout);
208 Color targetColor = new Color(null, 160, 160, 160);
209 Label label_lp = new Label(targetComp, SWT.NONE);
210 label_lp.setText("(");
211 label_lp.setForeground(targetColor);
212 label_lp.setLayoutData(new GridData(GridData.BEGINNING));
213 Label targetLabel = new Label(targetComp, SWT.NONE);
215 .setText(PHPDebugUiMessages
216 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.TargetFile.label"));
217 targetLabel.setForeground(targetColor);
218 targetLabel.setLayoutData(new GridData(GridData.BEGINNING));
219 targetFile = new Text(targetComp, SWT.SINGLE);
220 targetFile.setForeground(targetColor);
221 targetFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
222 targetFile.setEditable(false);
223 Label label_rp = new Label(targetComp, SWT.NONE);
224 label_rp.setText(")");
225 label_rp.setForeground(targetColor);
226 label_rp.setLayoutData(new GridData(GridData.END));
229 createVerticalSpacer(comp, 1);
231 Composite pathMapComp = new Composite(comp, SWT.NONE);
232 gd = new GridData(GridData.FILL_BOTH);
233 pathMapComp.setLayoutData(gd);
234 GridLayout parametersLayout = new GridLayout();
235 parametersLayout.numColumns = 2;
236 parametersLayout.marginHeight = 0;
237 parametersLayout.marginWidth = 0;
238 pathMapComp.setLayout(parametersLayout);
240 Label pathMapLabel = new Label(pathMapComp, SWT.NONE);
242 .setText(PHPDebugUiMessages
243 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.label"));
245 gd.horizontalSpan = 2;
246 pathMapLabel.setLayoutData(gd);
248 fRemoteDebugPathMapTable = new Table(pathMapComp, SWT.BORDER
250 TableLayout tableLayout = new TableLayout();
251 fRemoteDebugPathMapTable.setLayout(tableLayout);
253 gd = new GridData(GridData.FILL_BOTH);
254 fRemoteDebugPathMapTable.setLayoutData(gd);
255 TableColumn column1 = new TableColumn(this.fRemoteDebugPathMapTable,
258 .setText(PHPDebugUiMessages
259 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.local")); //$NON-NLS-1$
260 TableColumn column2 = new TableColumn(this.fRemoteDebugPathMapTable,
263 .setText(PHPDebugUiMessages
264 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.remote")); //$NON-NLS-1$
265 tableLayout.addColumnData(new ColumnWeightData(100));
266 tableLayout.addColumnData(new ColumnWeightData(100));
267 fRemoteDebugPathMapTable.setHeaderVisible(true);
268 fRemoteDebugPathMapTable.setLinesVisible(true);
269 fRemoteDebugPathMapTable.addSelectionListener(fListener);
270 fRemoteDebugPathMapTable.addMouseListener(new MouseAdapter() {
271 public void mouseDoubleClick(MouseEvent e) {
272 setPathMapButtonsEnableState();
273 if (fPathMapEditButton.isEnabled()) {
274 handlePathMapEditButtonSelected();
278 // fRemoteDebugPathMapTable.setEnabled(false);
280 Composite envButtonComp = new Composite(pathMapComp, SWT.NONE);
281 GridLayout envButtonLayout = new GridLayout();
282 envButtonLayout.marginHeight = 0;
283 envButtonLayout.marginWidth = 0;
284 envButtonComp.setLayout(envButtonLayout);
285 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
286 | GridData.HORIZONTAL_ALIGN_FILL);
287 envButtonComp.setLayoutData(gd);
289 fPathMapAddButton = createPushButton(
292 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Add.label"), null); //$NON-NLS-1$
293 fPathMapAddButton.addSelectionListener(fListener);
294 // fPathMapAddButton.setEnabled(false);
296 fPathMapEditButton = createPushButton(
299 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Edit.label"), null); //$NON-NLS-1$
300 fPathMapEditButton.addSelectionListener(fListener);
301 // fPathMapEditButton.setEnabled(false);
303 fPathMapRemoveButton = createPushButton(
306 .getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Remove.label"), null); //$NON-NLS-1$
307 fPathMapRemoveButton.addSelectionListener(fListener);
308 // fPathMapRemoveButton.setEnabled(false);
312 void handlePathMapAddButtonSelected() {
313 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
314 "Edit File Map", new String[] { EMPTY_STRING, EMPTY_STRING });
315 openNewPathMapDialog(dialog, null);
317 // if (dialog.open()==EditPathMapDialog.OK)
319 // TableItem item = new TableItem (fRemoteDebugPathMapTable, SWT.NONE);
320 // item.setText(0,dialog.getLocalPath());
321 // item.setText(1,dialog.getRemotePath());
322 // updateLaunchConfigurationDialog();
324 // updateLaunchConfigurationDialog();
325 setPathMapButtonsEnableState();
328 void handlePathMapRemoveButtonSelected() {
329 int[] selectedIndices = this.fRemoteDebugPathMapTable
330 .getSelectionIndices();
331 this.fRemoteDebugPathMapTable.remove(selectedIndices);
332 setPathMapButtonsEnableState();
333 updateLaunchConfigurationDialog();
336 void handlePathMapEditButtonSelected() {
337 TableItem selectedItem = this.fRemoteDebugPathMapTable.getSelection()[0];
338 String local = selectedItem.getText(0);
339 String remote = selectedItem.getText(1);
340 EditPathMapDialog dialog = new EditPathMapDialog(getShell(),
341 "Edit File Map", new String[] { local, remote });
342 openNewPathMapDialog(dialog, selectedItem);
346 * Set the enabled state of whole tab.
348 private void setRemoteTabEnableState() {
349 boolean state = fRemoteDebugCheckBox.getSelection();
350 fRemoteSourcePath.setEnabled(state);
351 fRemoteDebugTranslate.setEnabled(state);
353 fRemoteDebugPathMapTable.setEnabled(state);
355 fPathMapEditButton.setEnabled(false);
356 fPathMapRemoveButton.setEnabled(false);
357 fPathMapAddButton.setEnabled(false);
358 fOpenDBGSessionInBrowserCheckBox.setEnabled(false);
360 setPathMapButtonsEnableState();
363 updateLaunchConfigurationDialog();
367 * Set the enabled state of the three environment variable-related buttons
368 * based on the selection in the PathMapTable widget.
370 private void setPathMapButtonsEnableState() {
371 // just do nothing for now
373 if (fRemoteDebugCheckBox.getSelection()) {
374 fOpenDBGSessionInBrowserCheckBox.setEnabled(true);
375 fRemoteDebugTranslate.setEnabled(true);
376 int selectCount = this.fRemoteDebugPathMapTable
377 .getSelectionIndices().length;
378 if (selectCount < 1) {
379 fPathMapEditButton.setEnabled(false);
380 fPathMapRemoveButton.setEnabled(false);
382 fPathMapRemoveButton.setEnabled(true);
383 if (selectCount == 1) {
384 fPathMapEditButton.setEnabled(true);
386 fPathMapEditButton.setEnabled(false);
389 fPathMapAddButton.setEnabled(true);
394 * Show the specified dialog and update the pathMapTable table based on its
398 * the item to update, or <code>null</code> if adding a new
401 private void openNewPathMapDialog(EditPathMapDialog dialog,
402 TableItem updateItem) {
403 if (dialog.open() != EditPathMapDialog.OK) {
406 String[] pathPair = dialog.getPathPair();
407 TableItem tableItem = updateItem;
408 if (tableItem == null) {
409 tableItem = getTableItemForName(pathPair[0]);
410 if (tableItem == null) {
411 tableItem = new TableItem(this.fRemoteDebugPathMapTable,
415 tableItem.setText(pathPair);
416 this.fRemoteDebugPathMapTable
417 .setSelection(new TableItem[] { tableItem });
418 updateLaunchConfigurationDialog();
422 * Helper method that indicates whether the specified parameter name is
423 * already present in the parameters table.
425 private TableItem getTableItemForName(String candidateName) {
426 TableItem[] items = this.fRemoteDebugPathMapTable.getItems();
427 for (int i = 0; i < items.length; i++) {
428 String name = items[i].getText(0);
429 if (name.equals(candidateName)) {
436 // protected void addLoadPathTab(TabFolder tabFolder) {
437 // Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
438 // loadPathComposite.setLayout(new GridLayout());
440 // loadPathListViewer = new ListViewer(loadPathComposite, SWT.BORDER |
441 // SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
442 // loadPathListViewer.setContentProvider(new ListContentProvider());
443 // loadPathListViewer.setLabelProvider(new LoadPathEntryLabelProvider());
444 // loadPathListViewer.getList().setLayoutData(new
445 // GridData(GridData.FILL_BOTH));
447 // TabItem loadPathTab = new TabItem(tabFolder, SWT.NONE, 0);
448 // loadPathTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathTab.label"));
449 // loadPathTab.setControl(loadPathComposite);
450 // loadPathTab.setData(loadPathListViewer);
452 // loadPathDefaultButton = new Button(loadPathComposite, SWT.CHECK);
453 // loadPathDefaultButton.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.loadPathDefaultButton.label"));
454 // loadPathDefaultButton.setLayoutData(new
455 // GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
456 // loadPathDefaultButton.addSelectionListener(getLoadPathDefaultButtonSelectionListener());
458 // loadPathDefaultButton.setEnabled(false); //for now, until the load path
459 // is customizable on the configuration
462 protected SelectionListener getLoadPathSelectionListener() {
463 return new SelectionAdapter() {
464 public void widgetSelected(SelectionEvent e) {
465 System.out.println("Loadpath list selection occurred: "
471 protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
472 return new SelectionAdapter() {
473 public void widgetSelected(SelectionEvent e) {
474 setUseLoadPathDefaults(((Button) e.getSource()).getSelection());
479 protected void addInterpreterTab(TabFolder tabFolder) {
480 Composite interpreterComposite = new Composite(tabFolder, SWT.NONE);
481 GridLayout layout = new GridLayout();
482 layout.numColumns = 2;
483 // layout.marginHeight = 0;
484 // layout.marginWidth = 0;
485 interpreterComposite.setLayout(layout);
486 interpreterComposite.setLayoutData(new GridData(
487 GridData.FILL_HORIZONTAL));
489 createVerticalSpacer(interpreterComposite, 2);
491 interpreterCombo = new Combo(interpreterComposite, SWT.READ_ONLY);
492 interpreterCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
493 initializeInterpreterCombo(interpreterCombo);
494 interpreterCombo.addModifyListener(getInterpreterComboModifyListener());
496 Button interpreterAddButton = new Button(interpreterComposite, SWT.PUSH);
498 .setText(PHPDebugUiMessages
499 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterAddButton.label"));
500 interpreterAddButton.addSelectionListener(new SelectionAdapter() {
501 public void widgetSelected(SelectionEvent evt) {
502 PHPInterpreter newInterpreter = new PHPInterpreter(null);
503 File phpRuntime = PHPInterpreterPreferencePage.getFile(
505 if (phpRuntime != null) {
506 newInterpreter.setInstallLocation(phpRuntime);
507 PHPRuntime.getDefault().addInstalledInterpreter(
509 interpreterCombo.add(newInterpreter.getInstallLocation()
511 interpreterCombo.select(interpreterCombo
512 .indexOf(newInterpreter.getInstallLocation()
518 TabItem interpreterTab = new TabItem(tabFolder, SWT.NONE);
520 .setText(PHPDebugUiMessages
521 .getString("LaunchConfigurationTab.PHPEnvironment.interpreterTab.label"));
522 interpreterTab.setControl(interpreterComposite);
525 protected ModifyListener getInterpreterComboModifyListener() {
526 return new ModifyListener() {
527 public void modifyText(ModifyEvent evt) {
528 updateLaunchConfigurationDialog();
533 protected void createVerticalSpacer(Composite comp, int colSpan) {
534 Label label = new Label(comp, SWT.NONE);
535 GridData gd = new GridData();
536 gd.horizontalSpan = colSpan;
537 label.setLayoutData(gd);
540 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
541 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
542 .getSelectedInterpreter();
543 if (selectedInterpreter != null) {
544 String interpreterLocation = selectedInterpreter
545 .getInstallLocation().toString();
546 configuration.setAttribute(
547 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
548 interpreterLocation);
551 String projectName = configuration.getAttribute(
552 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
553 if (projectName != "") {
554 IProject project = ResourcesPlugin.getWorkspace().getRoot()
555 .getProject(projectName);
556 if (project != null) {
557 IPath remotePath = project.getLocation();
558 String fileName = configuration.getAttribute(
559 PHPLaunchConfigurationAttribute.FILE_NAME, "");
560 if (fileName != "") {
561 Path filePath = new Path(fileName);
562 remotePath = remotePath.append(filePath
563 .removeLastSegments(1));
565 configuration.setAttribute(
566 PHPLaunchConfigurationAttribute.REMOTE_PATH,
567 remotePath.toOSString());
570 } catch (CoreException e) {
575 public void initializeFrom(ILaunchConfiguration configuration) {
576 // initializeLoadPath(configuration);
577 initializeInterpreterSelection(configuration);
578 initializeRemoteDebug(configuration);
581 protected void initializeRemoteDebug(ILaunchConfiguration configuration) {
583 fRemoteDebugCheckBox.setSelection(configuration.getAttribute(
584 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
585 DEFAULT_REMOTE_DEBUG));
586 } catch (CoreException ce) {
587 fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
590 fRemoteDebugTranslate.setSelection(configuration.getAttribute(
591 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
592 DEFAULT_REMOTE_DEBUG_TRANSLATE));
593 } catch (CoreException ce) {
594 fRemoteDebugTranslate.setSelection(DEFAULT_REMOTE_DEBUG_TRANSLATE);
597 fOpenDBGSessionInBrowserCheckBox
598 .setSelection(configuration
600 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
601 DEFAULT_OPEN_DBGSESSION_IN_BROWSER));
602 } catch (CoreException ce) {
603 fOpenDBGSessionInBrowserCheckBox
604 .setSelection(DEFAULT_OPEN_DBGSESSION_IN_BROWSER);
606 setRemoteTabEnableState();
608 fRemoteSourcePath.setText(configuration.getAttribute(
609 PHPLaunchConfigurationAttribute.REMOTE_PATH, ""));
610 } catch (CoreException ce) {
611 fRemoteSourcePath.setText("");
614 updatePathMapFromConfig(configuration);
617 originalFileName = configuration.getAttribute(
618 PHPLaunchConfigurationAttribute.FILE_NAME, "");
620 } catch (CoreException ce) {
621 originalFileName = "";
626 private void updatePathMapFromConfig(ILaunchConfiguration config) {
629 if (config != null) {
630 envVars = config.getAttribute(
631 PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
633 updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
634 setPathMapButtonsEnableState();
635 } catch (CoreException ce) {
640 private void updatePathMapTable(Map map, Table tableWidget) {
641 tableWidget.removeAll();
645 Iterator iterator = map.keySet().iterator();
646 while (iterator.hasNext()) {
647 String key = (String) iterator.next();
648 String value = (String) map.get(key);
649 TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
650 tableItem.setText(new String[] { key, value });
654 // protected void initializeLoadPath(ILaunchConfiguration configuration) {
655 // boolean useDefaultLoadPath = true;
657 // useDefaultLoadPath =
658 // configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
660 // setUseLoadPathDefaults(useDefaultLoadPath);
661 // if (useDefaultLoadPath) {
662 // String projectName =
663 // configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME,
665 // if (projectName != "") {
666 // IProject aProject =
667 // PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
668 // if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
669 // JavaProject thePHPProject = new JavaProject();
670 // thePHPProject.setProject(aProject);
671 // List loadPathEntries = thePHPProject.getLoadPathEntries();
672 // loadPathListViewer.setInput(loadPathEntries);
676 // } catch (CoreException e) {
681 protected void setUseLoadPathDefaults(boolean useDefaults) {
682 loadPathListViewer.getList().setEnabled(!useDefaults);
683 // loadPathDefaultButton.setSelection(useDefaults);
686 protected void initializeInterpreterSelection(
687 ILaunchConfiguration configuration) {
688 String interpreterName = null;
690 interpreterName = configuration.getAttribute(
691 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
692 } catch (CoreException e) {
695 if (interpreterName != null && !interpreterName.equals(""))
696 interpreterCombo.select(interpreterCombo.indexOf(interpreterName));
699 protected void initializeInterpreterCombo(Combo interpreterCombo) {
700 installedInterpretersWorkingCopy = new ArrayList();
701 installedInterpretersWorkingCopy.addAll(PHPRuntime.getDefault()
702 .getInstalledInterpreters());
704 String[] interpreterNames = new String[installedInterpretersWorkingCopy
706 for (int interpreterIndex = 0; interpreterIndex < installedInterpretersWorkingCopy
707 .size(); interpreterIndex++) {
708 PHPInterpreter interpreter = (PHPInterpreter) installedInterpretersWorkingCopy
709 .get(interpreterIndex);
710 interpreterNames[interpreterIndex] = interpreter
711 .getInstallLocation().toString();
713 interpreterCombo.setItems(interpreterNames);
715 PHPInterpreter selectedInterpreter = PHPRuntime.getDefault()
716 .getSelectedInterpreter();
717 if (selectedInterpreter != null)
718 interpreterCombo.select(interpreterCombo
719 .indexOf(selectedInterpreter.getInstallLocation()
723 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
724 int selectionIndex = interpreterCombo.getSelectionIndex();
725 if (selectionIndex >= 0)
726 configuration.setAttribute(
727 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER,
728 interpreterCombo.getItem(selectionIndex));
730 // configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_LOAD_PATH,
731 // loadPathDefaultButton.getSelection());
733 // if (!loadPathDefaultButton.getSelection()) {
734 // List loadPathEntries = (List) loadPathListViewer.getInput();
735 // List loadPathStrings = new ArrayList();
736 // for (Iterator iterator = loadPathEntries.iterator();
737 // iterator.hasNext();) {
738 // LoadPathEntry entry = (LoadPathEntry) iterator.next();
739 // loadPathStrings.add(entry.getPath().toString());
741 // configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH,
745 configuration.setAttribute(
746 PHPLaunchConfigurationAttribute.REMOTE_DEBUG,
747 fRemoteDebugCheckBox.getSelection());
748 configuration.setAttribute(
749 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
750 fRemoteDebugTranslate.getSelection());
751 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP,
752 getMapFromPathMapTable());
753 configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,
754 fRemoteSourcePath.getText());
755 configuration.setAttribute(
756 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
757 fOpenDBGSessionInBrowserCheckBox.getSelection());
760 protected Composite createPageRoot(Composite parent) {
761 Composite composite = new Composite(parent, SWT.NULL);
762 GridLayout layout = new GridLayout();
763 layout.numColumns = 2;
764 composite.setLayout(layout);
765 createVerticalSpacer(composite, 2);
766 setControl(composite);
771 private Map getMapFromPathMapTable() {
772 TableItem[] items = fRemoteDebugPathMapTable.getItems();
773 if (items.length == 0) {
776 Map map = new HashMap(items.length);
777 for (int i = 0; i < items.length; i++) {
778 TableItem item = items[i];
779 String key = item.getText(0);
780 String value = item.getText(1);
786 public String getName() {
787 return PHPDebugUiMessages
788 .getString("LaunchConfigurationTab.PHPEnvironment.name");
791 public boolean isValid(ILaunchConfiguration launchConfig) {
793 String selectedInterpreter = launchConfig.getAttribute(
794 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
795 if (selectedInterpreter.length() == 0) {
796 setErrorMessage(PHPDebugUiMessages
797 .getString("LaunchConfigurationTab.PHPEnvironment.interpreter_not_selected_error_message"));
800 } catch (CoreException e) {
804 setErrorMessage(null);
808 protected void log(Throwable t) {
809 PHPDebugUiPlugin.log(t);
812 public Image getImage() {
813 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP);
816 private void makeupTargetFile() {
817 if (!fRemoteDebugCheckBox.getSelection() || originalFileName.equals("")) {
818 targetFile.setText("");
822 // see net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy.MapPath(PHPLineBreakpoint)
824 IPath remoteSourcePath = new Path(fRemoteSourcePath.getText());
825 IPath filename = new Path(originalFileName);
826 filename = remoteSourcePath.append(filename);
827 String path = filename.toOSString();
828 Map pathmap = getMapFromPathMapTable();
830 if (pathmap != null) {
831 Iterator it = pathmap.keySet().iterator();
832 while (it.hasNext()) {
833 String k = (String) it.next();
834 if (path.startsWith(k)) {
835 path = pathmap.get(k) + path.substring(k.length());
841 if (remoteSourcePath.isEmpty()) {
842 if (pathmap != null) {
843 Iterator it = pathmap.keySet().iterator();
844 while (it.hasNext()) {
845 String local = (String) it.next();
846 IPath remotePath = new Path((String) pathmap.get(local));
847 IPath localPath = new Path(local);
848 if (localPath.isPrefixOf(filename)) {
849 IPath newpath = filename.removeFirstSegments(localPath
850 .matchingFirstSegments(filename));
851 newpath = remotePath.append(newpath);
852 path = newpath.toString();
853 if (path.substring(0, 1).equals("/")) {
854 path = path.replace('\\', '/');
856 path = path.replace('/', '\\');
863 if (fRemoteDebugTranslate.getSelection()) {
864 if (remoteSourcePath.toString().substring(0, 1).equals("/")) {
865 path = path.replace('\\', '/');
867 path = path.replace('/', '\\');
872 targetFile.setText(path);