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.Group;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
28 public class PHPArgumentsTab extends AbstractLaunchConfigurationTab {
29 protected Text interpreterArgsText, programArgsText;
31 protected DirectorySelector workingDirectorySelector;
33 protected Button useDefaultWorkingDirectoryButton;
35 private class ArgumentsTabListener extends SelectionAdapter implements
41 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
43 public void modifyText(ModifyEvent e) {
44 updateLaunchConfigurationDialog();
50 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
52 public void widgetSelected(SelectionEvent e) {
53 updateLaunchConfigurationDialog();
58 private ArgumentsTabListener fListener = new ArgumentsTabListener();
60 public PHPArgumentsTab() {
64 public void createControl(Composite parent) {
65 Composite composite = createPageRoot(parent);
67 // new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
68 // .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
69 // workingDirectorySelector = new DirectorySelector(composite);
70 Group grpWorkingDir = new Group(composite, SWT.NONE);
71 grpWorkingDir.setText(PHPDebugUiMessages
72 .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
73 grpWorkingDir.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
74 grpWorkingDir.setLayout(new GridLayout());
75 workingDirectorySelector = new DirectorySelector(grpWorkingDir);
76 workingDirectorySelector
77 .setBrowseDialogMessage(PHPDebugUiMessages
78 .getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
79 workingDirectorySelector.setLayoutData(new GridData(
80 GridData.FILL_HORIZONTAL));
81 workingDirectorySelector.addModifyListener(fListener);
83 Composite defaultWorkingDirectoryComposite = new Composite(
84 grpWorkingDir, SWT.NONE);
85 GridLayout layout = new GridLayout();
86 layout.numColumns = 2;
87 defaultWorkingDirectoryComposite.setLayout(layout);
88 useDefaultWorkingDirectoryButton = new Button(
89 defaultWorkingDirectoryComposite, SWT.CHECK);
90 useDefaultWorkingDirectoryButton
91 .addSelectionListener(new SelectionAdapter() {
92 public void widgetSelected(SelectionEvent e) {
93 setUseDefaultWorkingDirectory(((Button) e.getSource())
97 useDefaultWorkingDirectoryButton.addSelectionListener(fListener);
99 new Label(defaultWorkingDirectoryComposite, SWT.NONE)
100 .setText(PHPDebugUiMessages
101 .getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
102 defaultWorkingDirectoryComposite.pack();
103 workingDirectorySelector.addModifyListener(fListener);
106 // new Label(composite, SWT.NONE)
107 // .setText(PHPDebugUiMessages
108 // .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
109 Group grpArgs = new Group(composite, SWT.NONE);
110 grpArgs.setText(PHPDebugUiMessages
111 .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
112 grpArgs.setLayoutData(new GridData(GridData.FILL_BOTH));
113 grpArgs.setLayout(new GridLayout());
114 interpreterArgsText = new Text(grpArgs, SWT.MULTI | SWT.V_SCROLL
115 | SWT.BORDER | SWT.WRAP);
116 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
117 interpreterArgsText.addModifyListener(fListener);
120 // new Label(composite, SWT.NONE)
121 // .setText(PHPDebugUiMessages
122 // .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
123 Group grpProgArgs = new Group(composite, SWT.NONE);
124 grpProgArgs.setText(PHPDebugUiMessages
125 .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
126 grpProgArgs.setLayoutData(new GridData(GridData.FILL_BOTH));
127 grpProgArgs.setLayout(new GridLayout());
128 programArgsText = new Text(grpProgArgs, SWT.MULTI | SWT.V_SCROLL
129 | SWT.BORDER | SWT.WRAP);
130 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
131 programArgsText.addModifyListener(fListener);
134 protected void setUseDefaultWorkingDirectory(boolean useDefault) {
135 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
136 useDefaultWorkingDirectoryButton.setSelection(useDefault);
138 workingDirectorySelector
139 .setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
140 workingDirectorySelector.setEnabled(!useDefault);
143 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
144 configuration.setAttribute(
145 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
146 PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
147 // set hidden attribute
148 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID,
149 "net.sourceforge.phpdt.debug.ui.PHPSourceLocator");
152 public void initializeFrom(ILaunchConfiguration configuration) {
153 String workingDirectory = "", interpreterArgs = "", programArgs = "";
154 boolean useDefaultWorkDir = true;
156 workingDirectory = configuration.getAttribute(
157 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
158 interpreterArgs = configuration.getAttribute(
159 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
160 programArgs = configuration.getAttribute(
161 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
162 useDefaultWorkDir = configuration
164 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
166 } catch (CoreException e) {
170 workingDirectorySelector.setSelectionText(workingDirectory);
171 interpreterArgsText.setText(interpreterArgs);
172 programArgsText.setText(programArgs);
173 setUseDefaultWorkingDirectory(useDefaultWorkDir);
176 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
177 configuration.setAttribute(
178 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
179 workingDirectorySelector.getValidatedSelectionText());
180 configuration.setAttribute(
181 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS,
182 interpreterArgsText.getText());
183 configuration.setAttribute(
184 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS,
185 programArgsText.getText());
186 configuration.setAttribute(
187 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
188 useDefaultWorkingDirectoryButton.getSelection());
191 protected Composite createPageRoot(Composite parent) {
192 Composite composite = new Composite(parent, SWT.NONE);
193 GridLayout compositeLayout = new GridLayout();
194 // compositeLayout.marginWidth = 0;
195 compositeLayout.numColumns = 1;
196 composite.setLayout(compositeLayout);
198 setControl(composite);
202 public String getName() {
203 return PHPDebugUiMessages
204 .getString("LaunchConfigurationTab.PHPArguments.name");
207 public boolean isValid(ILaunchConfiguration launchConfig) {
209 String workingDirectory = launchConfig.getAttribute(
210 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
211 if (workingDirectory.length() == 0) {
212 setErrorMessage(PHPDebugUiMessages
213 .getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
216 } catch (CoreException e) {
220 setErrorMessage(null);
224 protected void log(Throwable t) {
225 PHPDebugUiPlugin.log(t);
228 public Image getImage() {
229 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);