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.IResource;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.Path;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.ModifyEvent;
21 import org.eclipse.swt.events.ModifyListener;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.ui.IEditorInput;
28 import org.eclipse.ui.IEditorPart;
29 import org.eclipse.ui.IWorkbenchPage;
31 public class PHPEntryPointTab extends AbstractLaunchConfigurationTab {
32 protected String originalFileName, originalProjectName;
34 protected PHPProjectSelector projectSelector;
36 protected PHPFileSelector fileSelector;
38 public PHPEntryPointTab() {
42 public void createControl(Composite parent) {
43 Composite composite = createPageRoot(parent);
45 new Label(composite, SWT.NONE)
46 .setText(PHPDebugUiMessages
47 .getString("LaunchConfigurationTab.PHPEntryPoint.projectLabel"));
48 projectSelector = new PHPProjectSelector(composite);
50 .setBrowseDialogMessage(PHPDebugUiMessages
51 .getString("LaunchConfigurationTab.PHPEntryPoint.projectSelectorMessage"));
52 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
53 projectSelector.addModifyListener(new ModifyListener() {
54 public void modifyText(ModifyEvent evt) {
55 updateLaunchConfigurationDialog();
59 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
60 .getString("LaunchConfigurationTab.PHPEntryPoint.fileLabel"));
61 fileSelector = new PHPFileSelector(composite, projectSelector);
63 .setBrowseDialogMessage(PHPDebugUiMessages
64 .getString("LaunchConfigurationTab.PHPEntryPoint.fileSelectorMessage"));
65 fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
66 fileSelector.addModifyListener(new ModifyListener() {
67 public void modifyText(ModifyEvent evt) {
68 updateLaunchConfigurationDialog();
73 protected IResource getContext() {
74 IWorkbenchPage page = PHPDebugUiPlugin.getActivePage();
76 ISelection selection = page.getSelection();
77 if (selection instanceof IStructuredSelection) {
78 IStructuredSelection ss = (IStructuredSelection) selection;
80 Object obj = ss.getFirstElement();
81 if (obj instanceof IResource)
82 return ((IResource) obj);
85 IEditorPart part = page.getActiveEditor();
87 IEditorInput input = part.getEditorInput();
88 IResource file = (IResource) input.getAdapter(IResource.class);
97 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
98 IResource file = getContext();
100 configuration.setAttribute(
101 PHPLaunchConfigurationAttribute.PROJECT_NAME, file
102 .getProject().getName());
103 configuration.setAttribute(
104 PHPLaunchConfigurationAttribute.FILE_NAME, file
105 .getProjectRelativePath().toOSString());
109 public void initializeFrom(ILaunchConfiguration configuration) {
111 originalProjectName = configuration.getAttribute(
112 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
113 originalFileName = configuration.getAttribute(
114 PHPLaunchConfigurationAttribute.FILE_NAME, "");
115 } catch (CoreException e) {
119 projectSelector.setSelectionText(originalProjectName);
120 if (!"".equals(originalFileName))
121 fileSelector.setSelectionText(new Path(originalFileName)
125 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
126 configuration.setAttribute(
127 PHPLaunchConfigurationAttribute.PROJECT_NAME, projectSelector
128 .getSelectionText());
129 IFile file = fileSelector.getSelection();
130 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME,
131 file == null ? "" : file.getProjectRelativePath().toString());
134 protected Composite createPageRoot(Composite parent) {
135 Composite composite = new Composite(parent, SWT.NONE);
136 GridLayout layout = new GridLayout();
137 layout.marginWidth = 0;
138 composite.setLayout(layout);
140 setControl(composite);
144 public String getName() {
145 return PHPDebugUiMessages
146 .getString("LaunchConfigurationTab.PHPEntryPoint.name");
149 public boolean isValid(ILaunchConfiguration launchConfig) {
152 String projectName = launchConfig.getAttribute(
153 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
154 if (projectName.length() == 0) {
155 setErrorMessage(PHPDebugUiMessages
156 .getString("LaunchConfigurationTab.PHPEntryPoint.invalidProjectSelectionMessage"));
160 String fileName = launchConfig.getAttribute(
161 PHPLaunchConfigurationAttribute.FILE_NAME, "");
162 if (fileName.length() == 0) {
163 setErrorMessage(PHPDebugUiMessages
164 .getString("LaunchConfigurationTab.PHPEntryPoint.invalidFileSelectionMessage"));
167 } catch (CoreException e) {
171 setErrorMessage(null);
175 protected void log(Throwable t) {
176 PHPDebugUiPlugin.log(t);
179 public boolean canSave() {
180 return getErrorMessage() == null;
183 public Image getImage() {
184 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);