package net.sourceforge.phpdt.internal.debug.ui.launcher;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.internal.core.JavaProject;
import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
import net.sourceforge.phpdt.internal.debug.ui.preferences.EditInterpreterDialog;
+import net.sourceforge.phpdt.internal.debug.ui.preferences.EditPathMapDialog;
import net.sourceforge.phpdt.internal.launching.PHPInterpreter;
import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
import net.sourceforge.phpdt.internal.launching.PHPRuntime;
import net.sourceforge.phpdt.internal.ui.PHPUiImages;
import net.sourceforge.phpeclipse.LoadPathEntry;
-import net.sourceforge.phpeclipse.PHPCore;
-import net.sourceforge.phpeclipse.resourcesview.PHPProject;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.internal.dialogs.ListContentProvider;
public class PHPEnvironmentTab extends AbstractLaunchConfigurationTab {
protected java.util.List installedInterpretersWorkingCopy;
protected Combo interpreterCombo;
protected Button loadPathDefaultButton;
+ protected Button fRemoteDebugCheckBox;
+ protected Button fPathMapRemoveButton;
+ protected Button fPathMapAddButton;
+ protected Button fPathMapEditButton;
+ protected Text fRemoteSourcePath;
+ protected Table fRemoteDebugPathMapTable;
+ protected TabFolder tabFolder;
+
+ private class RemoteDebugTabListener extends SelectionAdapter implements ModifyListener {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ public void modifyText(ModifyEvent e) {
+ updateLaunchConfigurationDialog();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ Object source= e.getSource();
+ if (source == fRemoteDebugPathMapTable) {
+ setPathMapButtonsEnableState();
+ } else if (source == fPathMapAddButton) {
+ handlePathMapAddButtonSelected();
+ } else if (source == fPathMapEditButton) {
+ handlePathMapEditButtonSelected();
+ } else if (source == fPathMapRemoveButton) {
+ handlePathMapRemoveButtonSelected();
+ } else if (source == fRemoteDebugCheckBox) {
+ setRemoteTabEnableState();
+ } else {
+ updateLaunchConfigurationDialog();;
+ }
+
+ }
+ }
+
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private RemoteDebugTabListener fListener= new RemoteDebugTabListener();
+
+ private static final boolean DEFAULT_REMOTE_DEBUG= false;
+ static String [] columnTitles = { PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.local"),
+ PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMapTableTitle.remote")
+ };
public PHPEnvironmentTab() {
super();
}
public void createControl(Composite parent) {
Composite composite = createPageRoot(parent);
- TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
+ tabFolder = new TabFolder(composite, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_BOTH);
tabFolder.setLayoutData(gridData);
addLoadPathTab(tabFolder);
addInterpreterTab(tabFolder);
+ addRemoteDebugTab(tabFolder);
}
+
+ protected void addRemoteDebugTab(TabFolder tabFolder)
+ {
+ Label label;
+
+ TabItem remoteDebugTab = new TabItem(tabFolder, SWT.NONE, 0);
+ remoteDebugTab.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.label"));
+
+ Composite comp = new Composite(tabFolder, SWT.NONE);
+ comp.setLayout(new GridLayout());
+ remoteDebugTab.setControl(comp);
+ GridData gd;
+
+ fRemoteDebugCheckBox = new Button(comp, SWT.CHECK);
+ fRemoteDebugCheckBox.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteCheckBox.label"));
+ fRemoteDebugCheckBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+ fRemoteDebugCheckBox.addSelectionListener(fListener);
+
+ label = new Label(comp, SWT.NONE);
+ label.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.RemoteSourcePath.label"));
+ fRemoteSourcePath = new Text(comp, SWT.BORDER | SWT.SINGLE);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ fRemoteSourcePath.setLayoutData(gd);
+ fRemoteSourcePath.addModifyListener(fListener);
+
+ createVerticalSpacer(comp,1);
+
+ Composite pathMapComp = new Composite(comp, SWT.NONE);
+ gd = new GridData(GridData.FILL_BOTH);
+ pathMapComp.setLayoutData(gd);
+ GridLayout parametersLayout = new GridLayout();
+ parametersLayout.numColumns = 2;
+ parametersLayout.marginHeight = 0;
+ parametersLayout.marginWidth = 0;
+ pathMapComp.setLayout(parametersLayout);
+
+
+ Label pathMapLabel = new Label(pathMapComp, SWT.NONE);
+ pathMapLabel.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.label"));
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ pathMapLabel.setLayoutData(gd);
+
+
+ fRemoteDebugPathMapTable = new Table(pathMapComp, SWT.BORDER | SWT.MULTI);
+ TableLayout tableLayout = new TableLayout();
+ fRemoteDebugPathMapTable.setLayout(tableLayout);
+
+ gd = new GridData(GridData.FILL_BOTH);
+ fRemoteDebugPathMapTable.setLayoutData(gd);
+ TableColumn column1 = new TableColumn(this.fRemoteDebugPathMapTable, SWT.NONE);
+ column1.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.local")); //$NON-NLS-1$
+ TableColumn column2 = new TableColumn(this.fRemoteDebugPathMapTable, SWT.NONE);
+ column2.setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Table.Title.remote")); //$NON-NLS-1$
+ tableLayout.addColumnData(new ColumnWeightData(100));
+ tableLayout.addColumnData(new ColumnWeightData(100));
+ fRemoteDebugPathMapTable.setHeaderVisible(true);
+ fRemoteDebugPathMapTable.setLinesVisible(true);
+ fRemoteDebugPathMapTable.addSelectionListener(fListener);
+ fRemoteDebugPathMapTable.addMouseListener(new MouseAdapter() {
+ public void mouseDoubleClick(MouseEvent e) {
+ setPathMapButtonsEnableState();
+ if (fPathMapEditButton.isEnabled()) {
+ handlePathMapEditButtonSelected();
+ }
+ }
+ });
+// fRemoteDebugPathMapTable.setEnabled(false);
+
+ Composite envButtonComp = new Composite(pathMapComp, SWT.NONE);
+ GridLayout envButtonLayout = new GridLayout();
+ envButtonLayout.marginHeight = 0;
+ envButtonLayout.marginWidth = 0;
+ envButtonComp.setLayout(envButtonLayout);
+ gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
+ envButtonComp.setLayoutData(gd);
+
+
+ fPathMapAddButton = createPushButton(envButtonComp ,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Add.label"), null); //$NON-NLS-1$
+ fPathMapAddButton.addSelectionListener(fListener);
+// fPathMapAddButton.setEnabled(false);
+
+ fPathMapEditButton = createPushButton(envButtonComp,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Edit.label"), null); //$NON-NLS-1$
+ fPathMapEditButton.addSelectionListener(fListener);
+// fPathMapEditButton.setEnabled(false);
+
+ fPathMapRemoveButton = createPushButton(envButtonComp,PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.remoteDebugTab.PathMap.Button.Remove.label"), null); //$NON-NLS-1$
+ fPathMapRemoveButton.addSelectionListener(fListener);
+// fPathMapRemoveButton.setEnabled(false);
+
+
+ }
+
+ void handlePathMapAddButtonSelected()
+ {
+ EditPathMapDialog dialog=
+ new EditPathMapDialog(
+ getShell(),
+ "Edit File Map",
+ new String[] {EMPTY_STRING, EMPTY_STRING});
+ openNewPathMapDialog(dialog,null);
+// dialog.create();
+// if (dialog.open()==EditPathMapDialog.OK)
+// {
+// TableItem item = new TableItem (fRemoteDebugPathMapTable, SWT.NONE);
+// item.setText(0,dialog.getLocalPath());
+// item.setText(1,dialog.getRemotePath());
+// updateLaunchConfigurationDialog();
+// }
+// updateLaunchConfigurationDialog();
+ setPathMapButtonsEnableState();
+ }
+
+ void handlePathMapRemoveButtonSelected()
+ {
+ int[] selectedIndices = this.fRemoteDebugPathMapTable.getSelectionIndices();
+ this.fRemoteDebugPathMapTable.remove(selectedIndices);
+ setPathMapButtonsEnableState();
+ updateLaunchConfigurationDialog();
+ }
+
+ void handlePathMapEditButtonSelected()
+ {
+ TableItem selectedItem = this.fRemoteDebugPathMapTable.getSelection()[0];
+ String local = selectedItem.getText(0);
+ String remote = selectedItem.getText(1);
+ EditPathMapDialog dialog=
+ new EditPathMapDialog(
+ getShell(),
+ "Edit File Map",
+ new String[] {local, remote});
+ openNewPathMapDialog(dialog, selectedItem);
+ }
+
+
+ /**
+ * Set the enabled state of whole tab.
+ */
+ private void setRemoteTabEnableState() {
+ boolean state=fRemoteDebugCheckBox.getSelection();
+ fRemoteSourcePath.setEnabled(state);
+
+ fRemoteDebugPathMapTable.setEnabled(state);
+ if (!state)
+ {
+ fPathMapEditButton.setEnabled(false);
+ fPathMapRemoveButton.setEnabled(false);
+ fPathMapAddButton.setEnabled(false);
+ } else {
+ setPathMapButtonsEnableState();
+ }
+
+ updateLaunchConfigurationDialog();
+ }
+
+
+ /**
+ * Set the enabled state of the three environment variable-related buttons based on the
+ * selection in the PathMapTable widget.
+ */
+ private void setPathMapButtonsEnableState() {
+// just do nothing for now
+//
+ if(fRemoteDebugCheckBox.getSelection())
+ {
+ int selectCount = this.fRemoteDebugPathMapTable.getSelectionIndices().length;
+ if (selectCount < 1) {
+ fPathMapEditButton.setEnabled(false);
+ fPathMapRemoveButton.setEnabled(false);
+ } else {
+ fPathMapRemoveButton.setEnabled(true);
+ if (selectCount == 1) {
+ fPathMapEditButton.setEnabled(true);
+ } else {
+ fPathMapEditButton.setEnabled(false);
+ }
+ }
+ fPathMapAddButton.setEnabled(true);
+ }
+ }
+
+ /**
+ * Show the specified dialog and update the pathMapTable table based on its results.
+ *
+ * @param updateItem the item to update, or <code>null</code> if
+ * adding a new item
+ */
+ private void openNewPathMapDialog(EditPathMapDialog dialog, TableItem updateItem) {
+ if (dialog.open() != EditPathMapDialog.OK) {
+ return;
+ }
+ String[] pathPair = dialog.getPathPair();
+ TableItem tableItem = updateItem;
+ if (tableItem == null) {
+ tableItem = getTableItemForName(pathPair[0]);
+ if (tableItem == null) {
+ tableItem = new TableItem(this.fRemoteDebugPathMapTable, SWT.NONE);
+ }
+ }
+ tableItem.setText(pathPair);
+ this.fRemoteDebugPathMapTable.setSelection(new TableItem[] {tableItem});
+ updateLaunchConfigurationDialog();
+ }
+
+ /**
+ * Helper method that indicates whether the specified parameter name is already present
+ * in the parameters table.
+ */
+ private TableItem getTableItemForName(String candidateName) {
+ TableItem[] items = this.fRemoteDebugPathMapTable.getItems();
+ for (int i = 0; i < items.length; i++) {
+ String name = items[i].getText(0);
+ if (name.equals(candidateName)) {
+ return items[i];
+ }
+ }
+ return null;
+ }
+
+
protected void addLoadPathTab(TabFolder tabFolder) {
Composite loadPathComposite = new Composite(tabFolder, SWT.NONE);
}
};
}
+
+
protected SelectionListener getLoadPathDefaultButtonSelectionListener() {
return new SelectionAdapter() {
public void initializeFrom(ILaunchConfiguration configuration) {
initializeLoadPath(configuration);
initializeInterpreterSelection(configuration);
+ initializeRemoteDebug(configuration);
+ }
+
+ protected void initializeRemoteDebug(ILaunchConfiguration configuration)
+ {
+ String s[];
+ int startIdx =0;
+ int idx;
+ try{
+ fRemoteDebugCheckBox.setSelection(
+ configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG,DEFAULT_REMOTE_DEBUG));
+ } catch(CoreException ce) {
+ fRemoteDebugCheckBox.setSelection(DEFAULT_REMOTE_DEBUG);
+ }
+ setRemoteTabEnableState();
+ try{
+ fRemoteSourcePath.setText(
+ configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH,""));
+ } catch(CoreException ce) {
+ fRemoteSourcePath.setText("");
+ }
+
+ updatePathMapFromConfig(configuration);
+
+ }
+
+ private void updatePathMapFromConfig(ILaunchConfiguration config) {
+ Map envVars = null;
+ try {
+ if (config != null) {
+ envVars = config.getAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, (Map)null);
+ }
+ updatePathMapTable(envVars, this.fRemoteDebugPathMapTable);
+ setPathMapButtonsEnableState();
+ } catch (CoreException ce) {
+ log(ce);
+ }
+ }
+
+ private void updatePathMapTable(Map map, Table tableWidget) {
+ tableWidget.removeAll();
+ if (map == null) {
+ return;
+ }
+ Iterator iterator = map.keySet().iterator();
+ while (iterator.hasNext()) {
+ String key = (String) iterator.next();
+ String value = (String) map.get(key);
+ TableItem tableItem = new TableItem(tableWidget, SWT.NONE);
+ tableItem.setText(new String[] {key, value});
+ }
}
protected void initializeLoadPath(ILaunchConfiguration configuration) {
if (useDefaultLoadPath) {
String projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
if (projectName != "") {
- PHPProject project = PHPCore.getPHPProject(projectName);
- if (project != null) {
- List loadPathEntries = project.getLoadPathEntries();
+ IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(projectName);
+ if ((aProject != null) && JavaCore.isPHPProject(aProject)) {
+ JavaProject thePHPProject = new JavaProject();
+ thePHPProject.setProject(aProject);
+ List loadPathEntries = thePHPProject.getLoadPathEntries();
loadPathListViewer.setInput(loadPathEntries);
}
}
}
configuration.setAttribute(PHPLaunchConfigurationAttribute.CUSTOM_LOAD_PATH, loadPathStrings);
}
+
+ configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG, fRemoteDebugCheckBox.getSelection());
+ configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_MAP, getMapFromPathMapTable());
+ configuration.setAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, fRemoteSourcePath.getText());
}
protected Composite createPageRoot(Composite parent) {
return composite;
}
+
+ private Map getMapFromPathMapTable() {
+ TableItem[] items = fRemoteDebugPathMapTable.getItems();
+ if (items.length == 0) {
+ return null;
+ }
+ Map map = new HashMap(items.length);
+ for (int i = 0; i < items.length; i++) {
+ TableItem item = items[i];
+ String key = item.getText(0);
+ String value = item.getText(1);
+ map.put(key, value);
+ }
+ return map;
+ }
public String getName() {
return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEnvironment.name");
}
protected void log(Throwable t) {
- PHPDebugUiPlugin.getDefault().log(t);
+ PHPDebugUiPlugin.log(t);
}
public Image getImage() {