Remove unused "Remote location" in Launch Configuration.
[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.php.launching.IXDebugConstants;
6
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;
30
31 public class PHPRemoteDebug extends AbstractLaunchConfigurationTab {
32
33         private PHPProjectSelector projectSelector;
34         private Text fIdeIDText;
35
36         public void createControl(Composite parent) {
37                 Font font = parent.getFont();
38                 
39                 Composite comp = new Composite(parent, SWT.NONE);
40                 setControl(comp);
41                 GridLayout topLayout = new GridLayout();
42                 topLayout.verticalSpacing = 0;
43                 comp.setLayout(topLayout);
44                 comp.setFont(font);
45                 
46                 createProjectEditor(comp);
47                 createVerticalSpacer(comp, 1);
48                 createIdeIDEditor(comp);
49                 
50         }
51         
52         /**
53          * Creates the widgets for specifying a main type.
54          * 
55          * @param parent the parent composite
56          */
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);
66                 group.setFont(font);
67
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();
74                         }
75                 });
76                 
77                 gd= new GridData(GridData.FILL_HORIZONTAL);
78         }
79         
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);
89                 group.setFont(font);
90                 
91                                 
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();
100                         }
101                 });
102
103         }
104         
105
106           
107         protected IProject getContext() {
108                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
109                 if (page != null) {
110                         ISelection selection = page.getSelection();
111                         if (selection instanceof IStructuredSelection) {
112                                 IStructuredSelection ss = (IStructuredSelection) selection;
113                                 if (!ss.isEmpty()) {
114                                         Object obj = ss.getFirstElement();
115                                         if (obj instanceof IResource)
116                                                 return ((IResource) obj).getProject();
117                                 }
118                         }
119                         IEditorPart part = page.getActiveEditor();
120                         if (part != null) {
121                                 IEditorInput input = part.getEditorInput();
122                                 IResource file = (IResource) input.getAdapter(IResource.class);
123                                 if (file != null) {
124                                         return file.getProject();
125                                 }
126                         }
127                 }
128                 return null;
129         }
130
131         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
132                 IProject project = getContext();
133                 if (project != null)
134                         configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName());
135         }
136
137         public void initializeFrom(ILaunchConfiguration configuration) {
138                 try {
139                         String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
140                         if (project != null) {
141                                 projectSelector.setSelectionText(project);
142                         }
143                         String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID");
144                         fIdeIDText.setText(ideID);
145                 } catch (CoreException e) {
146                         setErrorMessage(e.getMessage());
147                 }
148
149
150
151         }
152
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);
158         }
159         
160         /* (non-Javadoc)
161          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
162          */
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");
169                         return false;
170                 }
171                 String ideID=fIdeIDText.getText();
172                 if (ideID.indexOf(' ')>0) { 
173                         setErrorMessage("No spaces in Identification String allowed");
174                         return false;
175                 }
176                 return true;
177         }
178         
179         public Image getImage() {
180                 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
181         }
182         
183         public String getName() {
184                 return "Main";
185         }
186
187
188 }