ad11c41f02105f707d39ca688d9e2f57852cbd8d
[phpeclipse.git] /
1 package net.sourceforge.phpdt.internal.debug.ui.launcher;
2
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;
9
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;
27
28 public class PHPArgumentsTab extends AbstractLaunchConfigurationTab {
29         protected Text interpreterArgsText, programArgsText;
30
31         protected DirectorySelector workingDirectorySelector;
32
33         protected Button useDefaultWorkingDirectoryButton;
34
35         public PHPArgumentsTab() {
36                 super();
37         }
38
39         public void createControl(Composite parent) {
40                 Composite composite = createPageRoot(parent);
41
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();
59                         }
60                 });
61
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())
73                                                                 .getSelection());
74                                         }
75                                 });
76                 new Label(defaultWorkingDirectoryComposite, SWT.NONE)
77                                 .setText(PHPDebugUiMessages
78                                                 .getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
79                 defaultWorkingDirectoryComposite.pack();
80
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));
92
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));
104         }
105
106         protected void setUseDefaultWorkingDirectory(boolean useDefault) {
107                 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
108                         useDefaultWorkingDirectoryButton.setSelection(useDefault);
109                 if (useDefault)
110                         workingDirectorySelector
111                                         .setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
112                 workingDirectorySelector.setEnabled(!useDefault);
113         }
114
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");
122         }
123
124         public void initializeFrom(ILaunchConfiguration configuration) {
125                 String workingDirectory = "", interpreterArgs = "", programArgs = "";
126                 boolean useDefaultWorkDir = true;
127                 try {
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
135                                         .getAttribute(
136                                                         PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
137                                                         true);
138                 } catch (CoreException e) {
139                         log(e);
140                 }
141
142                 workingDirectorySelector.setSelectionText(workingDirectory);
143                 interpreterArgsText.setText(interpreterArgs);
144                 programArgsText.setText(programArgs);
145                 setUseDefaultWorkingDirectory(useDefaultWorkDir);
146         }
147
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());
161         }
162
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);
169
170                 setControl(composite);
171                 return composite;
172         }
173
174         public String getName() {
175                 return PHPDebugUiMessages
176                                 .getString("LaunchConfigurationTab.PHPArguments.name");
177         }
178
179         public boolean isValid(ILaunchConfiguration launchConfig) {
180                 try {
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"));
186                                 return false;
187                         }
188                 } catch (CoreException e) {
189                         log(e);
190                 }
191
192                 setErrorMessage(null);
193                 return true;
194         }
195
196         protected void log(Throwable t) {
197                 PHPDebugUiPlugin.log(t);
198         }
199
200         public Image getImage() {
201                 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);
202         }
203
204 }