1 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
3 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
4 import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector;
5 //import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
6 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
7 import net.sourceforge.phpeclipse.xdebug.ui.EditPathMapDialog;
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.core.resources.IResource;
11 import org.eclipse.core.resources.ResourcesPlugin;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.debug.core.ILaunchConfiguration;
14 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
15 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
16 //import org.eclipse.jface.viewers.ColumnWeightData;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 //import org.eclipse.jface.viewers.TableLayout;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 //import org.eclipse.swt.events.MouseAdapter;
24 //import org.eclipse.swt.events.MouseEvent;
25 //import org.eclipse.swt.events.SelectionAdapter;
26 //import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.graphics.Font;
28 import org.eclipse.swt.graphics.Image;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 //import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 //import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Group;
35 import org.eclipse.swt.widgets.Label;
36 //import org.eclipse.swt.widgets.Table;
37 //import org.eclipse.swt.widgets.TableColumn;
38 //import org.eclipse.swt.widgets.TableItem;
39 import org.eclipse.swt.widgets.Text;
40 import org.eclipse.ui.IEditorInput;
41 import org.eclipse.ui.IEditorPart;
42 import org.eclipse.ui.IWorkbenchPage;
43 import org.eclipse.ui.PlatformUI;
45 public class PHPRemoteDebug extends AbstractLaunchConfigurationTab {
47 private PHPProjectSelector projectSelector;
48 private Text fIdeIDText;
49 private Text fRemoteLocationText;
51 public void createControl(Composite parent) {
52 Font font = parent.getFont();
54 Composite comp = new Composite(parent, SWT.NONE);
56 // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
57 GridLayout topLayout = new GridLayout();
58 topLayout.verticalSpacing = 0;
59 comp.setLayout(topLayout);
62 createProjectEditor(comp);
63 createVerticalSpacer(comp, 1);
64 createIdeIDEditor(comp);
69 * Creates the widgets for specifying a main type.
71 * @param parent the parent composite
73 private void createProjectEditor(Composite parent) {
74 Font font= parent.getFont();
75 Group group= new Group(parent, SWT.NONE);
76 group.setText("Project:");
77 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
78 group.setLayoutData(gd);
79 GridLayout layout = new GridLayout();
80 layout.numColumns = 1;
81 group.setLayout(layout);
84 projectSelector = new PHPProjectSelector(group);
85 projectSelector.setBrowseDialogMessage("Choose the project containing the application entry point:");
86 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
87 projectSelector.addModifyListener(new ModifyListener() {
88 public void modifyText(ModifyEvent evt) {
89 updateLaunchConfigurationDialog();
93 Label remoteLabel= new Label(group,SWT.NONE);
94 remoteLabel.setText("Remote Location:");
96 fRemoteLocationText = new Text(group,SWT.SINGLE | SWT.BORDER);
97 gd= new GridData(GridData.FILL_HORIZONTAL);
98 fRemoteLocationText.setLayoutData(gd);
99 fRemoteLocationText.setFont(font);
100 fRemoteLocationText.addModifyListener(new ModifyListener() {
101 public void modifyText(ModifyEvent evt) {
102 updateLaunchConfigurationDialog();
107 private void createIdeIDEditor(Composite parent) {
108 Font font= parent.getFont();
109 Group group= new Group(parent, SWT.NONE);
110 group.setText("Ide Identification String :");
111 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
112 group.setLayoutData(gd);
113 GridLayout layout = new GridLayout();
114 layout.numColumns = 1;
115 group.setLayout(layout);
119 fIdeIDText = new Text(group, SWT.SINGLE | SWT.BORDER);
120 gd= new GridData(GridData.FILL_HORIZONTAL);
121 fIdeIDText.setLayoutData(gd);
122 fIdeIDText.setFont(font);
123 fIdeIDText.setTextLimit(48);
124 fIdeIDText.addModifyListener(new ModifyListener() {
125 public void modifyText(ModifyEvent evt) {
126 updateLaunchConfigurationDialog();
134 protected IProject getContext() {
135 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
136 //IWorkbenchPage page= XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
138 ISelection selection = page.getSelection();
139 if (selection instanceof IStructuredSelection) {
140 IStructuredSelection ss = (IStructuredSelection) selection;
142 Object obj = ss.getFirstElement();
143 if (obj instanceof IResource)
144 return ((IResource) obj).getProject();
147 IEditorPart part = page.getActiveEditor();
149 IEditorInput input = part.getEditorInput();
150 IResource file = (IResource) input.getAdapter(IResource.class);
152 return file.getProject();
159 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
160 IProject project = getContext();
162 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName());
165 public void initializeFrom(ILaunchConfiguration configuration) {
167 String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
168 if (project != null) {
169 projectSelector.setSelectionText(project);
171 String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID");
172 fIdeIDText.setText(ideID);
174 String remoteLocation=configuration.getAttribute(IXDebugConstants.ATTR_PHP_REMOTE_LOCATION, "");
175 fRemoteLocationText.setText(remoteLocation);
177 } catch (CoreException e) {
178 setErrorMessage(e.getMessage());
185 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
186 String project = projectSelector.getSelectionText().trim();
187 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project);
188 String ideID = fIdeIDText.getText().trim();
189 configuration.setAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, ideID);
190 String remoteLocation = fRemoteLocationText.getText().trim();
191 configuration.setAttribute(IXDebugConstants.ATTR_PHP_REMOTE_LOCATION, remoteLocation);
195 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
197 public boolean isValid(ILaunchConfiguration launchConfig) {
198 setErrorMessage(null);
199 String projectName=projectSelector.getSelectionText().trim();
200 IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
201 if (!project.exists()) {
202 setErrorMessage("Project does not exist");
205 String ideID=fIdeIDText.getText();
206 if (ideID.indexOf(' ')>0) {
207 setErrorMessage("No spaces in Identification String allowed");
213 public Image getImage() {
214 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
217 public String getName() {