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.PHPFileSelector;
5 import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector;
6 import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
7 import net.sourceforge.phpeclipse.xdebug.php.launching.IXDebugConstants;
9 import org.eclipse.core.resources.IFile;
10 import org.eclipse.core.resources.IProject;
11 import org.eclipse.core.resources.IResource;
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.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.ModifyEvent;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.graphics.Font;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.FileDialog;
30 import org.eclipse.swt.widgets.Group;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Text;
33 import org.eclipse.ui.IEditorInput;
34 import org.eclipse.ui.IEditorPart;
35 import org.eclipse.ui.IWorkbenchPage;
37 public class PHPMainTab extends AbstractLaunchConfigurationTab {
40 protected Text fProjText;
41 protected Button fProjButton;
43 // Main class UI widgets
44 protected Text fMainText;
45 protected Button fSearchButton;
46 protected PHPProjectSelector projectSelector;
47 protected PHPFileSelector fileSelector;
48 private Button fUseDefaultInterpreterButton;
49 private Button fInterpreterButton;
50 private Text fInterpreterText;
51 private Label fInterpreterLabel;
57 public void createControl(Composite parent) {
58 Font font = parent.getFont();
60 Composite comp = new Composite(parent, SWT.NONE);
62 // PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_MAIN_TAB);
63 GridLayout topLayout = new GridLayout();
64 topLayout.verticalSpacing = 0;
65 comp.setLayout(topLayout);
68 createProjectEditor(comp);
69 createVerticalSpacer(comp, 1);
70 createMainTypeEditor(comp);
71 createVerticalSpacer(comp, 1);
72 createInterpreterEditor(comp);
76 * Creates the widgets for specifying a main type.
78 * @param parent the parent composite
80 private void createProjectEditor(Composite parent) {
81 Font font= parent.getFont();
82 Group group= new Group(parent, SWT.NONE);
83 group.setText("Project:");
84 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
85 group.setLayoutData(gd);
86 GridLayout layout = new GridLayout();
87 layout.numColumns = 2;
88 group.setLayout(layout);
91 projectSelector = new PHPProjectSelector(group);
92 projectSelector.setBrowseDialogMessage("Choose the project containing the application entry point:");
93 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
94 projectSelector.addModifyListener(new ModifyListener() {
95 public void modifyText(ModifyEvent evt) {
96 updateLaunchConfigurationDialog();
103 * Creates the widgets for specifying a php file.
105 * @param parent the parent composite
107 private void createMainTypeEditor(Composite parent) {
108 Font font= parent.getFont();
109 Group mainGroup= new Group(parent, SWT.NONE);
110 mainGroup.setText("File: ");
111 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
112 mainGroup.setLayoutData(gd);
113 GridLayout layout = new GridLayout();
114 layout.numColumns = 2;
115 mainGroup.setLayout(layout);
116 mainGroup.setFont(font);
118 fileSelector = new PHPFileSelector(mainGroup, projectSelector);
119 fileSelector.setBrowseDialogMessage("Choose the PHP file that represents the application entry point:");
120 fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
121 fileSelector.addModifyListener(new ModifyListener() {
122 public void modifyText(ModifyEvent evt) {
123 updateLaunchConfigurationDialog();
129 * Creates the widgets for specifying debug settings.
131 * @param parent the parent composite
133 private void createInterpreterEditor(Composite parent) {
134 Font font= parent.getFont();
135 Group interpreterGroup= new Group(parent, SWT.NONE);
136 interpreterGroup.setText("Interpreter: ");
137 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
138 interpreterGroup.setLayoutData(gd);
139 GridLayout layout = new GridLayout();
140 layout.numColumns = 2;
141 interpreterGroup.setLayout(layout);
142 interpreterGroup.setFont(font);
144 // fInterpreterLabel= new Label(interpreterGroup, SWT.NONE);
145 // fInterpreterLabel.setText("Interpreter: ");
146 // gd= new GridData();
147 // gd.horizontalSpan = 2;
148 // fInterpreterLabel.setLayoutData(gd);
149 // fInterpreterLabel.setFont(font);
151 fInterpreterText= new Text(interpreterGroup, SWT.SINGLE | SWT.BORDER);
152 gd= new GridData(GridData.FILL_HORIZONTAL);
153 fInterpreterText.setLayoutData(gd);
154 fInterpreterText.setFont(font);
155 fInterpreterText.addModifyListener(new ModifyListener() {
156 public void modifyText(ModifyEvent evt) {
157 updateLaunchConfigurationDialog();
162 fInterpreterButton= createPushButton(interpreterGroup,"Browse..", null);
163 fInterpreterButton.addSelectionListener(new SelectionAdapter() {
164 public void widgetSelected(SelectionEvent event) {
165 handleBrowseSellected(event);
169 fUseDefaultInterpreterButton = new Button(interpreterGroup,SWT.CHECK);
170 fUseDefaultInterpreterButton.setText("Use default interpreter");
171 gd = new GridData(GridData.FILL_HORIZONTAL);
172 fUseDefaultInterpreterButton.setLayoutData(gd);
173 fUseDefaultInterpreterButton.setFont(font);
174 fUseDefaultInterpreterButton.addSelectionListener(new SelectionAdapter() {
175 public void widgetSelected(SelectionEvent event) {
176 handleDefaultSellected(event);
183 * Set the appropriate enabled state for the appletviewqer text widget.
185 protected void setInterpreterTextEnabledState() {
186 if (isDefaultInterpreter()) {
187 fInterpreterText.setEnabled(false);
188 fInterpreterButton.setEnabled(false);
190 fInterpreterText.setEnabled(true);
191 fInterpreterButton.setEnabled(true);
196 * Returns whether the default appletviewer is to be used
198 protected boolean isDefaultInterpreter() {
199 return fUseDefaultInterpreterButton.getSelection();
204 protected void handleDefaultSellected(SelectionEvent event) {
205 setInterpreterTextEnabledState();
206 updateLaunchConfigurationDialog();
207 // if (isDefaultInterpreter()) {
208 // fInterpreterText.setText("default Interpreter");
213 protected void handleBrowseSellected(SelectionEvent event) {
214 FileDialog dlg=new FileDialog(getShell(),SWT.OPEN);
215 String fileName=dlg.open();
216 if (fileName!=null) {
217 fInterpreterText.setText(fileName);
218 updateLaunchConfigurationDialog();
222 protected IProject getContext() {
223 IWorkbenchPage page= XDebugCorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
225 ISelection selection = page.getSelection();
226 if (selection instanceof IStructuredSelection) {
227 IStructuredSelection ss = (IStructuredSelection) selection;
229 Object obj = ss.getFirstElement();
230 if (obj instanceof IResource)
231 return ((IResource) obj).getProject();
234 IEditorPart part = page.getActiveEditor();
236 IEditorInput input = part.getEditorInput();
237 IResource file = (IResource) input.getAdapter(IResource.class);
239 return file.getProject();
246 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
247 IProject project = getContext();
249 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project.getName());
253 public void initializeFrom(ILaunchConfiguration configuration) {
255 String project = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
256 if (project != null) {
257 projectSelector.setSelectionText(project);
259 String file = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null);
261 fileSelector.setSelectionText(file);
264 String interpreterFile=configuration.getAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, (String) null);
265 if(interpreterFile!=null)
266 fInterpreterText.setText(interpreterFile);
267 boolean selection=configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true);
268 fUseDefaultInterpreterButton.setSelection(selection);
269 setInterpreterTextEnabledState();
271 } catch (CoreException e) {
272 setErrorMessage(e.getMessage());
276 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
277 String project = projectSelector.getSelectionText().trim();
278 if (project.length() == 0) {
281 configuration.setAttribute(IXDebugConstants.ATTR_PHP_PROJECT, project);
283 IFile file = fileSelector.getSelection();
284 configuration.setAttribute(IXDebugConstants.ATTR_PHP_FILE, file == null ? "" : file.getProjectRelativePath()
286 configuration.setAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, this.fUseDefaultInterpreterButton.getSelection());
287 configuration.setAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, this.fInterpreterText.getText());
292 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
294 public boolean isValid(ILaunchConfiguration launchConfig) {
297 String projectName = launchConfig.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, "");
298 if (projectName.length() == 0) {
299 setErrorMessage("Iinvalid Project");
303 String fileName = launchConfig.getAttribute(IXDebugConstants.ATTR_PHP_FILE, "");
304 if (fileName.length() == 0) {
305 setErrorMessage("Invalid File");
308 } catch (CoreException e) {
309 // XDebugCorePlugin.log(e);
312 setErrorMessage(null);
313 return super.isValid(launchConfig);
315 public Image getImage() {
316 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);
319 public String getName() {