Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / php / launching / PHPRemoteDebug.java
1 package net.sourceforge.phpeclipse.xdebug.ui.php.launching;
2
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;
8
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;
44
45 public class PHPRemoteDebug extends AbstractLaunchConfigurationTab {
46
47         private PHPProjectSelector projectSelector;
48         private Text fIdeIDText;
49         private Text fRemoteLocationText;
50
51         public void createControl(Composite parent) {
52                 Font font = parent.getFont();
53                 
54                 Composite comp = new Composite(parent, SWT.NONE);
55                 setControl(comp);
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);
60                 comp.setFont(font);
61                 
62                 createProjectEditor(comp);
63                 createVerticalSpacer(comp, 1);
64                 createIdeIDEditor(comp);
65                 
66         }
67         
68         /**
69          * Creates the widgets for specifying a main type.
70          * 
71          * @param parent the parent composite
72          */
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);
82                 group.setFont(font);
83
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();
90                         }
91                 });
92                 
93                 Label remoteLabel= new Label(group,SWT.NONE);
94                 remoteLabel.setText("Remote Location:");
95                 
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();
103                         }
104                 });
105         }
106         
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);
116                 group.setFont(font);
117                 
118                                 
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();
127                         }
128                 });
129
130         }
131         
132
133           
134         protected IProject getContext() {
135                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
136                 //IWorkbenchPage page= XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
137                 if (page != null) {
138                         ISelection selection = page.getSelection();
139                         if (selection instanceof IStructuredSelection) {
140                                 IStructuredSelection ss = (IStructuredSelection) selection;
141                                 if (!ss.isEmpty()) {
142                                         Object obj = ss.getFirstElement();
143                                         if (obj instanceof IResource)
144                                                 return ((IResource) obj).getProject();
145                                 }
146                         }
147                         IEditorPart part = page.getActiveEditor();
148                         if (part != null) {
149                                 IEditorInput input = part.getEditorInput();
150                                 IResource file = (IResource) input.getAdapter(IResource.class);
151                                 if (file != null) {
152                                         return file.getProject();
153                                 }
154                         }
155                 }
156                 return null;
157         }
158
159         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
160                 IProject project = getContext();
161                 if (project != null)
162                         configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName());
163         }
164
165         public void initializeFrom(ILaunchConfiguration configuration) {
166                 try {
167                         String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
168                         if (project != null) {
169                                 projectSelector.setSelectionText(project);
170                         }
171                         String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID");
172                         fIdeIDText.setText(ideID);
173                         
174                         String remoteLocation=configuration.getAttribute(IXDebugConstants.ATTR_PHP_REMOTE_LOCATION, "");
175                         fRemoteLocationText.setText(remoteLocation);
176                         
177                 } catch (CoreException e) {
178                         setErrorMessage(e.getMessage());
179                 }
180
181
182
183         }
184
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);
192         }
193         
194         /* (non-Javadoc)
195          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
196          */
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");
203                         return false;
204                 }
205                 String ideID=fIdeIDText.getText();
206                 if (ideID.indexOf(' ')>0) { 
207                         setErrorMessage("No spaces in Identification String allowed");
208                         return false;
209                 }
210                 return true;
211         }
212         
213         public Image getImage() {
214                 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
215         }
216         
217         public String getName() {
218                 return "Main";
219         }
220
221
222 }