1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
3 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
4 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
5 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
6 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
7 import net.sourceforge.phpdt.internal.ui.util.PHPFileSelector;
8 import net.sourceforge.phpdt.internal.ui.util.PHPProjectSelector;
10 import org.eclipse.core.resources.IFile;
11 import org.eclipse.core.resources.IProject;
12 import org.eclipse.core.resources.IResource;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
18 import org.eclipse.jface.viewers.ISelection;
19 import org.eclipse.jface.viewers.IStructuredSelection;
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.graphics.Image;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.ui.IEditorInput;
29 import org.eclipse.ui.IEditorPart;
30 import org.eclipse.ui.IWorkbenchPage;
32 public class PHPEntryPointTab extends AbstractLaunchConfigurationTab {
33 protected String originalFileName, originalProjectName;
35 protected PHPProjectSelector projectSelector;
37 protected PHPFileSelector fileSelector;
39 public PHPEntryPointTab() {
43 public void createControl(Composite parent) {
44 Composite composite = createPageRoot(parent);
46 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.projectLabel"));
47 projectSelector = new PHPProjectSelector(composite);
48 projectSelector.setBrowseDialogMessage(PHPDebugUiMessages
49 .getString("LaunchConfigurationTab.PHPEntryPoint.projectSelectorMessage"));
50 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
51 projectSelector.addModifyListener(new ModifyListener() {
52 public void modifyText(ModifyEvent evt) {
53 updateLaunchConfigurationDialog();
57 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.fileLabel"));
58 fileSelector = new PHPFileSelector(composite, projectSelector);
59 fileSelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.fileSelectorMessage"));
60 fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
61 fileSelector.addModifyListener(new ModifyListener() {
62 public void modifyText(ModifyEvent evt) {
63 updateLaunchConfigurationDialog();
68 protected IProject getContext() {
69 IWorkbenchPage page = PHPDebugUiPlugin.getActivePage();
71 ISelection selection = page.getSelection();
72 if (selection instanceof IStructuredSelection) {
73 IStructuredSelection ss = (IStructuredSelection) selection;
75 Object obj = ss.getFirstElement();
76 if (obj instanceof IResource)
77 return ((IResource) obj).getProject();
80 IEditorPart part = page.getActiveEditor();
82 IEditorInput input = part.getEditorInput();
83 IResource file = (IResource) input.getAdapter(IResource.class);
85 return file.getProject();
92 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
93 IProject project = getContext();
95 configuration.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, project.getName());
98 public void initializeFrom(ILaunchConfiguration configuration) {
100 originalProjectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
101 originalFileName = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "");
102 } catch (CoreException e) {
106 projectSelector.setSelectionText(originalProjectName);
107 if (!"".equals(originalFileName))
108 fileSelector.setSelectionText(new Path(originalFileName).toOSString());
111 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
112 configuration.setAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, projectSelector.getSelectionText());
113 IFile file = fileSelector.getSelection();
114 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, file == null ? "" : file.getProjectRelativePath()
118 protected Composite createPageRoot(Composite parent) {
119 Composite composite = new Composite(parent, SWT.NONE);
120 GridLayout layout = new GridLayout();
121 layout.marginWidth = 0;
122 composite.setLayout(layout);
124 setControl(composite);
128 public String getName() {
129 return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.name");
132 public boolean isValid(ILaunchConfiguration launchConfig) {
135 String projectName = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
136 if (projectName.length() == 0) {
137 setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.invalidProjectSelectionMessage"));
141 String fileName = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "");
142 if (fileName.length() == 0) {
143 setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPEntryPoint.invalidFileSelectionMessage"));
146 } catch (CoreException e) {
150 setErrorMessage(null);
154 protected void log(Throwable t) {
155 PHPDebugUiPlugin.log(t);
158 public boolean canSave() {
159 return getErrorMessage() == null;
162 public Image getImage() {
163 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);