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.Group;
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);
49 Group grpProject = new Group(composite, SWT.NONE);
51 .setText(PHPDebugUiMessages
52 .getString("LaunchConfigurationTab.PHPEntryPoint.projectLabel"));
53 grpProject.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
54 grpProject.setLayout(new GridLayout());
55 projectSelector = new PHPProjectSelector(grpProject);
57 .setBrowseDialogMessage(PHPDebugUiMessages
58 .getString("LaunchConfigurationTab.PHPEntryPoint.projectSelectorMessage"));
59 projectSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60 projectSelector.addModifyListener(new ModifyListener() {
61 public void modifyText(ModifyEvent evt) {
62 updateLaunchConfigurationDialog();
66 // new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
67 // .getString("LaunchConfigurationTab.PHPEntryPoint.fileLabel"));
68 // fileSelector = new PHPFileSelector(composite, projectSelector);
69 Group grpFile = new Group(composite, SWT.NONE);
70 grpFile.setText(PHPDebugUiMessages
71 .getString("LaunchConfigurationTab.PHPEntryPoint.fileLabel"));
72 grpFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
73 grpFile.setLayout(new GridLayout());
74 fileSelector = new PHPFileSelector(grpFile, projectSelector);
76 .setBrowseDialogMessage(PHPDebugUiMessages
77 .getString("LaunchConfigurationTab.PHPEntryPoint.fileSelectorMessage"));
78 fileSelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79 fileSelector.addModifyListener(new ModifyListener() {
80 public void modifyText(ModifyEvent evt) {
81 updateLaunchConfigurationDialog();
86 protected IResource getContext() {
87 IWorkbenchPage page = PHPDebugUiPlugin.getActivePage();
89 ISelection selection = page.getSelection();
90 if (selection instanceof IStructuredSelection) {
91 IStructuredSelection ss = (IStructuredSelection) selection;
93 Object obj = ss.getFirstElement();
94 if (obj instanceof IResource)
95 return ((IResource) obj);
98 IEditorPart part = page.getActiveEditor();
100 IEditorInput input = part.getEditorInput();
101 IResource file = (IResource) input.getAdapter(IResource.class);
110 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
111 IResource file = getContext();
113 configuration.setAttribute(
114 PHPLaunchConfigurationAttribute.PROJECT_NAME, file
115 .getProject().getName());
116 configuration.setAttribute(
117 PHPLaunchConfigurationAttribute.FILE_NAME, file
118 .getProjectRelativePath().toOSString());
122 public void initializeFrom(ILaunchConfiguration configuration) {
124 originalProjectName = configuration.getAttribute(
125 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
126 originalFileName = configuration.getAttribute(
127 PHPLaunchConfigurationAttribute.FILE_NAME, "");
128 } catch (CoreException e) {
132 projectSelector.setSelectionText(originalProjectName);
133 if (!"".equals(originalFileName))
134 fileSelector.setSelectionText(new Path(originalFileName)
138 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
139 configuration.setAttribute(
140 PHPLaunchConfigurationAttribute.PROJECT_NAME, projectSelector
141 .getSelectionText());
142 IFile file = fileSelector.getSelection();
143 configuration.setAttribute(PHPLaunchConfigurationAttribute.FILE_NAME,
144 file == null ? "" : file.getProjectRelativePath().toString());
147 protected Composite createPageRoot(Composite parent) {
148 Composite composite = new Composite(parent, SWT.NONE);
149 GridLayout layout = new GridLayout();
150 // layout.marginWidth = 0;
151 composite.setLayout(layout);
153 setControl(composite);
157 public String getName() {
158 return PHPDebugUiMessages
159 .getString("LaunchConfigurationTab.PHPEntryPoint.name");
162 public boolean isValid(ILaunchConfiguration launchConfig) {
165 String projectName = launchConfig.getAttribute(
166 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
167 if (projectName.length() == 0) {
168 setErrorMessage(PHPDebugUiMessages
169 .getString("LaunchConfigurationTab.PHPEntryPoint.invalidProjectSelectionMessage"));
173 String fileName = launchConfig.getAttribute(
174 PHPLaunchConfigurationAttribute.FILE_NAME, "");
175 if (fileName.length() == 0) {
176 setErrorMessage(PHPDebugUiMessages
177 .getString("LaunchConfigurationTab.PHPEntryPoint.invalidFileSelectionMessage"));
180 } catch (CoreException e) {
184 setErrorMessage(null);
188 protected void log(Throwable t) {
189 PHPDebugUiPlugin.log(t);
192 public boolean canSave() {
193 return getErrorMessage() == null;
196 public Image getImage() {
197 return PHPUiImages.get(PHPUiImages.IMG_CTOOLS_PHP_PAGE);