e45fdb166b4098318fbb8e828216a2f3b6636796
[phpeclipse.git] /
1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
2
3 import org.eclipse.core.runtime.CoreException;
4 import org.eclipse.debug.core.ILaunchConfiguration;
5 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
6 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.ModifyEvent;
9 import org.eclipse.swt.events.ModifyListener;
10 import org.eclipse.swt.events.SelectionAdapter;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.graphics.Image;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
19 import net.sourceforge.phpdt.debug.ui.PHPDebugUiConstants;
20 import net.sourceforge.phpdt.debug.ui.PHPDebugUiImages;
21 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiMessages;
22 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
23 import net.sourceforge.phpdt.internal.launching.PHPLaunchConfigurationAttribute;
24 import net.sourceforge.phpdt.internal.ui.util.DirectorySelector;
25
26 public class PHPArgumentsTab extends AbstractLaunchConfigurationTab {
27         protected Text interpreterArgsText, programArgsText;
28         protected DirectorySelector workingDirectorySelector;
29         protected Button useDefaultWorkingDirectoryButton;
30
31         public PHPArgumentsTab() {
32                 super();
33         }
34
35         public void createControl(Composite parent) {
36                 Composite composite = createPageRoot(parent);
37
38                 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir"));
39                 workingDirectorySelector = new DirectorySelector(composite);
40                 workingDirectorySelector.setBrowseDialogMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
41                 workingDirectorySelector.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
42                 workingDirectorySelector.addModifyListener(new ModifyListener() {
43                         public void modifyText(ModifyEvent e) {
44                                 updateLaunchConfigurationDialog();
45                         }
46                 });
47
48                 Composite defaultWorkingDirectoryComposite = new Composite(composite, SWT.NONE);
49                 GridLayout layout = new GridLayout();
50                 layout.numColumns = 2;
51                 defaultWorkingDirectoryComposite.setLayout(layout);
52                 useDefaultWorkingDirectoryButton = new Button(defaultWorkingDirectoryComposite, SWT.CHECK);
53                 useDefaultWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() {
54                         public void widgetSelected(SelectionEvent e) {
55                                 setUseDefaultWorkingDirectory(((Button) e.getSource()).getSelection());
56                         }
57                 });
58                 new Label(defaultWorkingDirectoryComposite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
59                 defaultWorkingDirectoryComposite.pack();
60
61                 Label verticalSpacer = new Label(composite, SWT.NONE);
62
63                 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
64                 interpreterArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
65                 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
66
67                 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
68                 programArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
69                 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
70         }
71
72         protected void setUseDefaultWorkingDirectory(boolean useDefault) {
73                 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
74                         useDefaultWorkingDirectoryButton.setSelection(useDefault);
75                 if (useDefault)
76                         workingDirectorySelector.setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
77                 workingDirectorySelector.setEnabled(!useDefault);
78         }
79
80         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
81                 setUseDefaultWorkingDirectory(true);
82                 configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
83                 // set hidden attribute
84                 //configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "net.sourceforge.phpdt.internal.debug.ui.PHPSourceLocator") ;
85         }
86
87         public void initializeFrom(ILaunchConfiguration configuration) {
88                 String workingDirectory = "", interpreterArgs = "", programArgs = "";
89                 boolean useDefaultWorkDir = true;
90                 try {
91                         workingDirectory = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
92                         interpreterArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
93                         programArgs = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
94                         useDefaultWorkDir = configuration.getAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, true);
95                 } catch (CoreException e) {
96                         log(e);
97                 }
98
99                 workingDirectorySelector.setSelectionText(workingDirectory);
100                 interpreterArgsText.setText(interpreterArgs);
101                 programArgsText.setText(programArgs);
102                 setUseDefaultWorkingDirectory(useDefaultWorkDir);
103         }
104
105         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
106                 configuration.setAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, workingDirectorySelector.getValidatedSelectionText());
107                 configuration.setAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, interpreterArgsText.getText());
108                 configuration.setAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, programArgsText.getText());
109                 configuration.setAttribute(PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY, useDefaultWorkingDirectoryButton.getSelection());
110         }
111
112         protected Composite createPageRoot(Composite parent) {
113                 Composite composite = new Composite(parent, SWT.NONE);
114                 GridLayout compositeLayout = new GridLayout();
115                 compositeLayout.marginWidth = 0;
116                 compositeLayout.numColumns = 1;
117                 composite.setLayout(compositeLayout);
118
119                 setControl(composite);
120                 return composite;
121         }
122
123         public String getName() {
124                 return PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.name");
125         }
126
127         public boolean isValid(ILaunchConfiguration launchConfig) {
128                 try {
129                         String workingDirectory = launchConfig.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
130                         if (workingDirectory.length() == 0) {
131                                 setErrorMessage(PHPDebugUiMessages.getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
132                                 return false;
133                         }
134                 } catch (CoreException e) {
135                         log(e);
136                 }
137
138                 setErrorMessage(null);
139                 return true;
140         }
141         
142         protected void log(Throwable t) {
143                 PHPDebugUiPlugin.getDefault().log(t);
144         }
145
146         public Image getImage() {
147                 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);
148         }
149
150 }