1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
3 import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants;
4 import net.sourceforge.phpdt.debug.ui.PHPDebugUiImages;
5 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
6 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
7 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
8 import net.sourceforge.phpdt.internal.ui.util.DirectorySelector;
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.swt.SWT;
15 import org.eclipse.swt.events.ModifyEvent;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
27 public class PHPArgumentsTab extends AbstractLaunchConfigurationTab {
28 protected Text interpreterArgsText, programArgsText;
30 protected DirectorySelector workingDirectorySelector;
32 protected Button useDefaultWorkingDirectoryButton;
34 public PHPArgumentsTab() {
38 public void createControl(Composite parent) {
39 Composite composite = createPageRoot(parent);
41 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
42 .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
43 workingDirectorySelector = new DirectorySelector(composite);
44 workingDirectorySelector
45 .setBrowseDialogMessage(PHPDebugUiMessages
46 .getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
47 workingDirectorySelector.setLayoutData(new GridData(
48 GridData.FILL_HORIZONTAL));
49 workingDirectorySelector.addModifyListener(new ModifyListener() {
50 public void modifyText(ModifyEvent e) {
51 updateLaunchConfigurationDialog();
55 Composite defaultWorkingDirectoryComposite = new Composite(composite,
57 GridLayout layout = new GridLayout();
58 layout.numColumns = 2;
59 defaultWorkingDirectoryComposite.setLayout(layout);
60 useDefaultWorkingDirectoryButton = new Button(
61 defaultWorkingDirectoryComposite, SWT.CHECK);
62 useDefaultWorkingDirectoryButton
63 .addSelectionListener(new SelectionAdapter() {
64 public void widgetSelected(SelectionEvent e) {
65 setUseDefaultWorkingDirectory(((Button) e.getSource())
69 new Label(defaultWorkingDirectoryComposite, SWT.NONE)
70 .setText(PHPDebugUiMessages
71 .getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
72 defaultWorkingDirectoryComposite.pack();
74 new Label(composite, SWT.NONE)
75 .setText(PHPDebugUiMessages
76 .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
77 interpreterArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL
79 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
81 new Label(composite, SWT.NONE)
82 .setText(PHPDebugUiMessages
83 .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
84 programArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL
86 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
89 protected void setUseDefaultWorkingDirectory(boolean useDefault) {
90 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
91 useDefaultWorkingDirectoryButton.setSelection(useDefault);
93 workingDirectorySelector
94 .setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
95 workingDirectorySelector.setEnabled(!useDefault);
98 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
99 configuration.setAttribute(
100 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
101 PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
102 // set hidden attribute
103 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID,
104 "net.sourceforge.phpdt.debug.ui.PHPSourceLocator");
107 public void initializeFrom(ILaunchConfiguration configuration) {
108 String workingDirectory = "", interpreterArgs = "", programArgs = "";
109 boolean useDefaultWorkDir = true;
111 workingDirectory = configuration.getAttribute(
112 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
113 interpreterArgs = configuration.getAttribute(
114 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
115 programArgs = configuration.getAttribute(
116 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
117 useDefaultWorkDir = configuration
119 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
121 } catch (CoreException e) {
125 workingDirectorySelector.setSelectionText(workingDirectory);
126 interpreterArgsText.setText(interpreterArgs);
127 programArgsText.setText(programArgs);
128 setUseDefaultWorkingDirectory(useDefaultWorkDir);
131 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
132 configuration.setAttribute(
133 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
134 workingDirectorySelector.getValidatedSelectionText());
135 configuration.setAttribute(
136 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS,
137 interpreterArgsText.getText());
138 configuration.setAttribute(
139 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS,
140 programArgsText.getText());
141 configuration.setAttribute(
142 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
143 useDefaultWorkingDirectoryButton.getSelection());
146 protected Composite createPageRoot(Composite parent) {
147 Composite composite = new Composite(parent, SWT.NONE);
148 GridLayout compositeLayout = new GridLayout();
149 compositeLayout.marginWidth = 0;
150 compositeLayout.numColumns = 1;
151 composite.setLayout(compositeLayout);
153 setControl(composite);
157 public String getName() {
158 return PHPDebugUiMessages
159 .getString("LaunchConfigurationTab.PHPArguments.name");
162 public boolean isValid(ILaunchConfiguration launchConfig) {
164 String workingDirectory = launchConfig.getAttribute(
165 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
166 if (workingDirectory.length() == 0) {
167 setErrorMessage(PHPDebugUiMessages
168 .getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
171 } catch (CoreException e) {
175 setErrorMessage(null);
179 protected void log(Throwable t) {
180 PHPDebugUiPlugin.log(t);
183 public Image getImage() {
184 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);