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.php.launching.IXDebugConstants;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.resources.IResource;
9 import org.eclipse.core.resources.ResourcesPlugin;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.debug.core.ILaunchConfiguration;
12 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
13 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.ModifyEvent;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.graphics.Font;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Group;
25 import org.eclipse.swt.widgets.Text;
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.IEditorPart;
28 import org.eclipse.ui.IWorkbenchPage;
29 import org.eclipse.ui.PlatformUI;
31 public class PHPRemoteDebug extends AbstractLaunchConfigurationTab {
33 private PHPProjectSelector projectSelector;
34 private Text fIdeIDText;
36 public void createControl(Composite parent) {
37 Font font = parent.getFont();
39 Composite comp = new Composite(parent, SWT.NONE);
41 GridLayout topLayout = new GridLayout();
42 topLayout.verticalSpacing = 0;
43 comp.setLayout(topLayout);
46 createProjectEditor(comp);
47 createVerticalSpacer(comp, 1);
48 createIdeIDEditor(comp);
53 * Creates the widgets for specifying a main type.
55 * @param parent the parent composite
57 private void createProjectEditor(Composite parent) {
58 Font font= parent.getFont();
59 Group group= new Group(parent, SWT.NONE);
60 group.setText("Project:");
61 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
62 group.setLayoutData(gd);
63 GridLayout layout = new GridLayout();
64 layout.numColumns = 1;
65 group.setLayout(layout);
68 projectSelector = new PHPProjectSelector(group);
69 projectSelector.setBrowseDialogMessage("Choose the project containing the application entry point:");
70 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
71 projectSelector.addModifyListener(new ModifyListener() {
72 public void modifyText(ModifyEvent evt) {
73 updateLaunchConfigurationDialog();
77 gd= new GridData(GridData.FILL_HORIZONTAL);
80 private void createIdeIDEditor(Composite parent) {
81 Font font= parent.getFont();
82 Group group= new Group(parent, SWT.NONE);
83 group.setText("Ide Identification String :");
84 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
85 group.setLayoutData(gd);
86 GridLayout layout = new GridLayout();
87 layout.numColumns = 1;
88 group.setLayout(layout);
92 fIdeIDText = new Text(group, SWT.SINGLE | SWT.BORDER);
93 gd= new GridData(GridData.FILL_HORIZONTAL);
94 fIdeIDText.setLayoutData(gd);
95 fIdeIDText.setFont(font);
96 fIdeIDText.setTextLimit(48);
97 fIdeIDText.addModifyListener(new ModifyListener() {
98 public void modifyText(ModifyEvent evt) {
99 updateLaunchConfigurationDialog();
107 protected IProject getContext() {
108 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
110 ISelection selection = page.getSelection();
111 if (selection instanceof IStructuredSelection) {
112 IStructuredSelection ss = (IStructuredSelection) selection;
114 Object obj = ss.getFirstElement();
115 if (obj instanceof IResource)
116 return ((IResource) obj).getProject();
119 IEditorPart part = page.getActiveEditor();
121 IEditorInput input = part.getEditorInput();
122 IResource file = (IResource) input.getAdapter(IResource.class);
124 return file.getProject();
131 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
132 IProject project = getContext();
134 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName());
137 public void initializeFrom(ILaunchConfiguration configuration) {
139 String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
140 if (project != null) {
141 projectSelector.setSelectionText(project);
143 String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID");
144 fIdeIDText.setText(ideID);
145 } catch (CoreException e) {
146 setErrorMessage(e.getMessage());
153 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
154 String project = projectSelector.getSelectionText().trim();
155 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project);
156 String ideID = fIdeIDText.getText().trim();
157 configuration.setAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, ideID);
161 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
163 public boolean isValid(ILaunchConfiguration launchConfig) {
164 setErrorMessage(null);
165 String projectName=projectSelector.getSelectionText().trim();
166 IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
167 if (!project.exists()) {
168 setErrorMessage("Project does not exist");
171 String ideID=fIdeIDText.getText();
172 if (ideID.indexOf(' ')>0) {
173 setErrorMessage("No spaces in Identification String allowed");
179 public Image getImage() {
180 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
183 public String getName() {