2368be53caf80be24018140bcc1b2a7c4f20379b
[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.Label;
25 import org.eclipse.swt.widgets.Text;
26
27 public class PHPArgumentsTab extends AbstractLaunchConfigurationTab {
28         protected Text interpreterArgsText, programArgsText;
29
30         protected DirectorySelector workingDirectorySelector;
31
32         protected Button useDefaultWorkingDirectoryButton;
33
34         public PHPArgumentsTab() {
35                 super();
36         }
37
38         public void createControl(Composite parent) {
39                 Composite composite = createPageRoot(parent);
40
41                 new Label(composite, SWT.NONE).setText(PHPDebugUiMessages
42                                 .getString("LaunchConfigurationTab.PHPArguments.working_dir"));
43                 workingDirectorySelector = new DirectorySelector(composite);
44                 workingDirectorySelector
45                                 .setBrowseDialogMessage(PHPDebugUiMessages
46                                                 .getString("LaunchConfigurationTab.PHPArguments.working_dir_browser_message"));
47                 workingDirectorySelector.setLayoutData(new GridData(
48                                 GridData.FILL_HORIZONTAL));
49                 workingDirectorySelector.addModifyListener(new ModifyListener() {
50                         public void modifyText(ModifyEvent e) {
51                                 updateLaunchConfigurationDialog();
52                         }
53                 });
54
55                 Composite defaultWorkingDirectoryComposite = new Composite(composite,
56                                 SWT.NONE);
57                 GridLayout layout = new GridLayout();
58                 layout.numColumns = 2;
59                 defaultWorkingDirectoryComposite.setLayout(layout);
60                 useDefaultWorkingDirectoryButton = new Button(
61                                 defaultWorkingDirectoryComposite, SWT.CHECK);
62                 useDefaultWorkingDirectoryButton
63                                 .addSelectionListener(new SelectionAdapter() {
64                                         public void widgetSelected(SelectionEvent e) {
65                                                 setUseDefaultWorkingDirectory(((Button) e.getSource())
66                                                                 .getSelection());
67                                         }
68                                 });
69                 new Label(defaultWorkingDirectoryComposite, SWT.NONE)
70                                 .setText(PHPDebugUiMessages
71                                                 .getString("LaunchConfigurationTab.PHPArguments.working_dir_use_default_message"));
72                 defaultWorkingDirectoryComposite.pack();
73
74                 new Label(composite, SWT.NONE)
75                                 .setText(PHPDebugUiMessages
76                                                 .getString("LaunchConfigurationTab.PHPArguments.interpreter_args_box_title"));
77                 interpreterArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL
78                                 | SWT.BORDER);
79                 interpreterArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
80
81                 new Label(composite, SWT.NONE)
82                                 .setText(PHPDebugUiMessages
83                                                 .getString("LaunchConfigurationTab.PHPArguments.program_args_box_title"));
84                 programArgsText = new Text(composite, SWT.MULTI | SWT.V_SCROLL
85                                 | SWT.BORDER);
86                 programArgsText.setLayoutData(new GridData(GridData.FILL_BOTH));
87         }
88
89         protected void setUseDefaultWorkingDirectory(boolean useDefault) {
90                 if (!useDefaultWorkingDirectoryButton.getSelection() == useDefault)
91                         useDefaultWorkingDirectoryButton.setSelection(useDefault);
92                 if (useDefault)
93                         workingDirectorySelector
94                                         .setSelectionText(PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
95                 workingDirectorySelector.setEnabled(!useDefault);
96         }
97
98         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
99                 configuration.setAttribute(
100                                 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
101                                 PHPDebugUiConstants.DEFAULT_WORKING_DIRECTORY);
102                 // set hidden attribute
103                 configuration.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID,
104                                 "net.sourceforge.phpdt.debug.ui.PHPSourceLocator");
105         }
106
107         public void initializeFrom(ILaunchConfiguration configuration) {
108                 String workingDirectory = "", interpreterArgs = "", programArgs = "";
109                 boolean useDefaultWorkDir = true;
110                 try {
111                         workingDirectory = configuration.getAttribute(
112                                         PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
113                         interpreterArgs = configuration.getAttribute(
114                                         PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
115                         programArgs = configuration.getAttribute(
116                                         PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
117                         useDefaultWorkDir = configuration
118                                         .getAttribute(
119                                                         PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
120                                                         true);
121                 } catch (CoreException e) {
122                         log(e);
123                 }
124
125                 workingDirectorySelector.setSelectionText(workingDirectory);
126                 interpreterArgsText.setText(interpreterArgs);
127                 programArgsText.setText(programArgs);
128                 setUseDefaultWorkingDirectory(useDefaultWorkDir);
129         }
130
131         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
132                 configuration.setAttribute(
133                                 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY,
134                                 workingDirectorySelector.getValidatedSelectionText());
135                 configuration.setAttribute(
136                                 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS,
137                                 interpreterArgsText.getText());
138                 configuration.setAttribute(
139                                 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS,
140                                 programArgsText.getText());
141                 configuration.setAttribute(
142                                 PHPLaunchConfigurationAttribute.USE_DEFAULT_WORKING_DIRECTORY,
143                                 useDefaultWorkingDirectoryButton.getSelection());
144         }
145
146         protected Composite createPageRoot(Composite parent) {
147                 Composite composite = new Composite(parent, SWT.NONE);
148                 GridLayout compositeLayout = new GridLayout();
149                 compositeLayout.marginWidth = 0;
150                 compositeLayout.numColumns = 1;
151                 composite.setLayout(compositeLayout);
152
153                 setControl(composite);
154                 return composite;
155         }
156
157         public String getName() {
158                 return PHPDebugUiMessages
159                                 .getString("LaunchConfigurationTab.PHPArguments.name");
160         }
161
162         public boolean isValid(ILaunchConfiguration launchConfig) {
163                 try {
164                         String workingDirectory = launchConfig.getAttribute(
165                                         PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
166                         if (workingDirectory.length() == 0) {
167                                 setErrorMessage(PHPDebugUiMessages
168                                                 .getString("LaunchConfigurationTab.PHPArguments.working_dir_error_message"));
169                                 return false;
170                         }
171                 } catch (CoreException e) {
172                         log(e);
173                 }
174
175                 setErrorMessage(null);
176                 return true;
177         }
178
179         protected void log(Throwable t) {
180                 PHPDebugUiPlugin.log(t);
181         }
182
183         public Image getImage() {
184                 return PHPDebugUiImages.get(PHPDebugUiImages.IMG_EVIEW_ARGUMENTS_TAB);
185         }
186
187 }