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;
29 protected DirectorySelector workingDirectorySelector;
30 protected Button useDefaultWorkingDirectoryButton;
32 public PHPArgumentsTab() {
36 public void createControl(Composite parent) {
37 Composite composite = createPageRoot(parent);
39 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir"));
40 workingDirectorySelector = new DirectorySelector(composite);
41 workingDirectorySelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
42 workingDirectorySelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
43 workingDirectorySelector.addModifyListener(new ModifyListener() {
44 public void modifyText(ModifyEvent e) {
45 updateLaunchConfigurationDialog();
49 Composite defaultWorkingDirectoryComposite = new Composite(composite, SWT.NONE);
50 GridLayout layout = new GridLayout();
51 layout.numColumns = 2;
52 defaultWorkingDirectoryComposite.setLayout(layout);
53 useDefaultWorkingDirectoryButton = new Button(defaultWorkingDirectoryComposite, SWT.CHECK);
54 useDefaultWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() {
55 public void widgetSelected(SelectionEvent e) {
56 setUseDefaultWorkingDirectory(((Button) e.getSource()).getSelection());
59 new Label(defaultWorkingDirectoryComposite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
60 defaultWorkingDirectoryComposite.pack();
62 Label verticalSpacer = new Label(composite, SWT.NONE);
64 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
65 interpreterArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
66 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
68 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
69 programArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
70 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
73 protected void setUseDefaultWorkingDirectory(boolean useDefault) {
74 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
75 useDefaultWorkingDirectoryButton.setSelection(useDefault);
77 workingDirectorySelector.setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
78 workingDirectorySelector.setEnabled(!useDefault);
81 public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
82 //setUseDefaultWorkingDirectory(true);
83 configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
84 // set hidden attribute
85 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "net.sourceforge.phpdt.debug.ui.PHPSourceLocator") ;
88 public void initializeFrom(ILaunchConfiguration configuration) {
89 String workingDirectory = "", interpreterArgs = "", programArgs = "";
90 boolean useDefaultWorkDir = true;
92 workingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
93 interpreterArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
94 programArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
95 useDefaultWorkDir = configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, true);
96 } catch (CoreException e) {
100 workingDirectorySelector.setSelectionText(workingDirectory);
101 interpreterArgsText.setText(interpreterArgs);
102 programArgsText.setText(programArgs);
103 setUseDefaultWorkingDirectory(useDefaultWorkDir);
106 public void performApply(ILaunchConfigurationWorkingCopy configuration) {
107 configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, workingDirectorySelector.getValidatedSelectionText());
108 configuration.setAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, interpreterArgsText.getText());
109 configuration.setAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, programArgsText.getText());
110 configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, useDefaultWorkingDirectoryButton.getSelection());
113 protected Composite createPageRoot(Composite parent) {
114 Composite composite = new Composite(parent, SWT.NONE);
115 GridLayout compositeLayout = new GridLayout();
116 compositeLayout.marginWidth = 0;
117 compositeLayout.numColumns = 1;
118 composite.setLayout(compositeLayout);
120 setControl(composite);
124 public String getName() {
125 return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.name");
128 public boolean isValid(ILaunchConfiguration launchConfig) {
130 String workingDirectory = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
131 if (workingDirectory.length() == 0) {
132 setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
135 } catch (CoreException e) {
139 setErrorMessage(null);
143 protected void log(Throwable t) {
144 PHPDebugUiPlugin.log(t);
147 public Image getImage() {
148 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);