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 public PHPArgumentsTab() {
39 public void createControl(Composite parent) {
40 Composite composite = createPageRoot(parent);
42 // new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
43 // .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
44 // workingDirectorySelector = new DirectorySelector(composite);
45 Group grpWorkingDir = new Group(composite, SWT.NONE);
46 grpWorkingDir.setText(PHPDebugUiMessages
47 .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
48 grpWorkingDir.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
49 grpWorkingDir.setLayout(new GridLayout());
50 workingDirectorySelector = new DirectorySelector(grpWorkingDir);
51 workingDirectorySelector
52 .setBrowseDialogMessage(PHPDebugUiMessages
53 .getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
54 workingDirectorySelector.setLayoutData(new GridData(
55 GridData.FILL_HORIZONTAL));
56 workingDirectorySelector.addModifyListener(new ModifyListener() {
57 public void modifyText(ModifyEvent e) {
58 updateLaunchConfigurationDialog();
62 Composite defaultWorkingDirectoryComposite = new Composite(
63 grpWorkingDir, SWT.NONE);
64 GridLayout layout = new GridLayout();
65 layout.numColumns = 2;
66 defaultWorkingDirectoryComposite.setLayout(layout);
67 useDefaultWorkingDirectoryButton = new Button(
68 defaultWorkingDirectoryComposite, SWT.CHECK);
69 useDefaultWorkingDirectoryButton
70 .addSelectionListener(new SelectionAdapter() {
71 public void widgetSelected(SelectionEvent e) {
72 setUseDefaultWorkingDirectory(((Button) e.getSource())
76 new Label(defaultWorkingDirectoryComposite, SWT.NONE)
77 .setText(PHPDebugUiMessages
78 .getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
79 defaultWorkingDirectoryComposite.pack();
81 // new Label(composite, SWT.NONE)
82 // .setText(PHPDebugUiMessages
83 // .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
84 Group grpArgs = new Group(composite, SWT.NONE);
85 grpArgs.setText(PHPDebugUiMessages
86 .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
87 grpArgs.setLayoutData(new GridData(GridData.FILL_BOTH));
88 grpArgs.setLayout(new GridLayout());
89 interpreterArgsText = new Text(grpArgs, SWT.MULTI | SWT.V_SCROLL
90 | SWT.BORDER | SWT.WRAP);
91 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
93 // new Label(composite, SWT.NONE)
94 // .setText(PHPDebugUiMessages
95 // .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
96 Group grpProgArgs = new Group(composite, SWT.NONE);
97 grpProgArgs.setText(PHPDebugUiMessages
98 .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
99 grpProgArgs.setLayoutData(new GridData(GridData.FILL_BOTH));
100 grpProgArgs.setLayout(new GridLayout());
101 programArgsText = new Text(grpProgArgs, SWT.MULTI | SWT.V_SCROLL
102 | SWT.BORDER | SWT.WRAP);
103 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
106 protected void setUseDefaultWorkingDirectory(boolean useDefault) {
107 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
108 useDefaultWorkingDirectoryButton.setSelection(useDefault);
110 workingDirectorySelector
111 .setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
112 workingDirectorySelector.setEnabled(!useDefault);
115 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
116 configuration.setAttribute(
117 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
118 PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
119 // set hidden attribute
120 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID,
121 "net.sourceforge.phpdt.debug.ui.PHPSourceLocator");
124 public void initializeFrom(ILaunchConfiguration configuration) {
125 String workingDirectory = "", interpreterArgs = "", programArgs = "";
126 boolean useDefaultWorkDir = true;
128 workingDirectory = configuration.getAttribute(
129 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
130 interpreterArgs = configuration.getAttribute(
131 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
132 programArgs = configuration.getAttribute(
133 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
134 useDefaultWorkDir = configuration
136 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
138 } catch (CoreException e) {
142 workingDirectorySelector.setSelectionText(workingDirectory);
143 interpreterArgsText.setText(interpreterArgs);
144 programArgsText.setText(programArgs);
145 setUseDefaultWorkingDirectory(useDefaultWorkDir);
148 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
149 configuration.setAttribute(
150 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
151 workingDirectorySelector.getValidatedSelectionText());
152 configuration.setAttribute(
153 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS,
154 interpreterArgsText.getText());
155 configuration.setAttribute(
156 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS,
157 programArgsText.getText());
158 configuration.setAttribute(
159 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
160 useDefaultWorkingDirectoryButton.getSelection());
163 protected Composite createPageRoot(Composite parent) {
164 Composite composite = new Composite(parent, SWT.NONE);
165 GridLayout compositeLayout = new GridLayout();
166 // compositeLayout.marginWidth = 0;
167 compositeLayout.numColumns = 1;
168 composite.setLayout(compositeLayout);
170 setControl(composite);
174 public String getName() {
175 return PHPDebugUiMessages
176 .getString("LaunchConfigurationTab.PHPArguments.name");
179 public boolean isValid(ILaunchConfiguration launchConfig) {
181 String workingDirectory = launchConfig.getAttribute(
182 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
183 if (workingDirectory.length() == 0) {
184 setErrorMessage(PHPDebugUiMessages
185 .getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
188 } catch (CoreException e) {
192 setErrorMessage(null);
196 protected void log(Throwable t) {
197 PHPDebugUiPlugin.log(t);
200 public Image getImage() {
201 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);