1
2
3
4
5 package org.apache.commons.jelly.eclipse.ui;
6
7 import java.io.File;
8
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.debug.core.ILaunchConfiguration;
11 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
12 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.ModifyEvent;
15 import org.eclipse.swt.events.ModifyListener;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.graphics.Font;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.FileDialog;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26
27 /***
28 * <code>JellyLaunchMainTab</code> is the main tab of the launch configuration
29 * dialog. The file of the Jelly script and the output file for the script processing
30 * result can be set.
31 * @author Juergen Mayrbaeurl
32 * @since 0.9
33 */
34 public class JellyLaunchMainTab extends AbstractLaunchConfigurationTab
35 {
36
37 /***
38 * <code>showMainClassJarPath</code> must be set to true, if setting the
39 * jar of the Jelly main class should be enabled
40 */
41 private boolean showMainClassJarPath = false;
42 /***
43 * <code>fMainClassJarPathLabel</code> is the label of the jelly file path
44 * jar
45 */
46 private Label fMainClassJarPathLabel;
47 private Text fMainClassJarPathText;
48 private Button fMainClassJarPathButton;
49
50
51 /***
52 * The label for the Jelly script file path
53 */
54 private Label fScriptFilePathLabel;
55 /***
56 * The text input control for the Jelly script file path
57 */
58 private Text fScriptFilePathText;
59 /***
60 * The search button for the Jelly script file
61 */
62 private Button fSearchButton;
63
64 /***
65 * The label of the output file of the Jelly script
66 */
67 private Label fOutLabel;
68 /***
69 * The text input control for the output file path of the Jelly script
70 */
71 private Text fOutText;
72 /***
73 * The search button for the output file location of the Jelly script
74 */
75 private Button fOutButton;
76
77 private static final String EMPTY_STRING= "";
78
79 private ModifyListener fModifyListener= new ModifyListener() {
80 public void modifyText(ModifyEvent e) {
81 updateLaunchConfigurationDialog();
82 }
83 };
84
85 private SelectionAdapter fSelectionListener= new SelectionAdapter() {
86 public void widgetSelected(SelectionEvent e) {
87 Object source= e.getSource();
88 if (source == fSearchButton) {
89 handleSearchButtonSelected();
90 } else if ( (source == fMainClassJarPathButton) && showMainClassJarPath) {
91 handleMainClassJarSearchButtonSelected();
92 } else if (source == fOutButton) {
93 handleOutButtonSelected();
94 }
95 }
96 };
97
98 /***
99 * Empty default constructor
100 */
101 public JellyLaunchMainTab() {
102 super();
103 }
104
105
106
107
108 public void createControl(Composite parent)
109 {
110 Font font= parent.getFont();
111
112
113 Composite projComp= new Composite(parent, SWT.NONE);
114 setControl(projComp);
115
116
117 GridLayout projLayout= new GridLayout();
118 projLayout.numColumns= 2;
119 projComp.setLayout(projLayout);
120 projComp.setFont(font);
121
122 GridData gd;
123
124 if(this.showMainClassJarPath)
125 {
126 fMainClassJarPathLabel= new Label(projComp, SWT.NONE);
127 fMainClassJarPathLabel.setText(JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.mainClassJar"));
128 gd= new GridData();
129 gd.horizontalSpan = 2;
130 fMainClassJarPathLabel.setLayoutData(gd);
131 fMainClassJarPathLabel.setFont(font);
132
133 fMainClassJarPathText= new Text(projComp, SWT.SINGLE | SWT.BORDER);
134 gd= new GridData(GridData.FILL_HORIZONTAL);
135 fMainClassJarPathText.setLayoutData(gd);
136 fMainClassJarPathText.setFont(font);
137 fMainClassJarPathText.addModifyListener(fModifyListener);
138
139 fMainClassJarPathButton= createPushButton(projComp,
140 JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.mainClassJarSearchButton"), null);
141 fMainClassJarPathButton.addSelectionListener(fSelectionListener);
142
143 createVerticalSpacer(projComp, 2);
144 }
145
146
147 fScriptFilePathLabel= new Label(projComp, SWT.NONE);
148 fScriptFilePathLabel.setText(JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.scriptLabel"));
149 gd= new GridData();
150 gd.horizontalSpan = 2;
151 fScriptFilePathLabel.setLayoutData(gd);
152 fScriptFilePathLabel.setFont(font);
153
154 fScriptFilePathText= new Text(projComp, SWT.SINGLE | SWT.BORDER);
155 gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
156 fScriptFilePathText.setLayoutData(gd);
157 fScriptFilePathText.setFont(font);
158 fScriptFilePathText.addModifyListener(fModifyListener);
159
160 fSearchButton= createPushButton(projComp,JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.scriptSearchButton"), null);
161 fSearchButton.addSelectionListener(fSelectionListener);
162
163 createVerticalSpacer(projComp, 2);
164
165
166 fOutLabel= new Label(projComp, SWT.NONE);
167 fOutLabel.setText(JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.outputLabel"));
168 gd= new GridData();
169 gd.horizontalSpan = 2;
170 fOutLabel.setLayoutData(gd);
171 fOutLabel.setFont(font);
172
173 fOutText= new Text(projComp, SWT.SINGLE | SWT.BORDER);
174 gd= new GridData(GridData.FILL_HORIZONTAL);
175 fOutText.setLayoutData(gd);
176 fOutText.setFont(font);
177 fOutText.addModifyListener(fModifyListener);
178
179 fOutButton= createPushButton(projComp, JellyLauncherPlugin.getResourceString("jelly.launch.ui.mainTab.outputSearchButton"), null);
180 fOutButton.addSelectionListener(fSelectionListener);
181
182 createVerticalSpacer(projComp, 2);
183 }
184
185
186
187
188 public void setDefaults(ILaunchConfigurationWorkingCopy config)
189 {
190
191 JellyLaunchUtils.initializeJellyInstallpath(config, null);
192
193
194 config.setAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYSCRIPT_PATH, EMPTY_STRING);
195 config.setAttribute(JellyLaunchConfigurationConstants.ATTR_OUTPUT_PATH, EMPTY_STRING);
196 }
197
198
199
200
201 public void initializeFrom(ILaunchConfiguration config)
202 {
203 try {
204 if(this.showMainClassJarPath)
205 fMainClassJarPathText.setText(config.getAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYINSTALL_PATH, EMPTY_STRING));
206 fScriptFilePathText.setText(config.getAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYSCRIPT_PATH, EMPTY_STRING));
207 fOutText.setText(config.getAttribute(JellyLaunchConfigurationConstants.ATTR_OUTPUT_PATH, EMPTY_STRING));
208 } catch (CoreException ce) {
209 JellyLauncherPlugin.getDefault().
210 showErrorForException(JellyLaunchConfigurationConstants.ERR_CANT_INITIALIZE_FROMCONFIG,ce);
211 }
212 }
213
214
215
216
217 public void performApply(ILaunchConfigurationWorkingCopy config)
218 {
219 if(this.showMainClassJarPath)
220 config.setAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYINSTALL_PATH, fMainClassJarPathText.getText());
221 config.setAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYSCRIPT_PATH, fScriptFilePathText.getText());
222 config.setAttribute(JellyLaunchConfigurationConstants.ATTR_OUTPUT_PATH, fOutText.getText());
223 }
224
225
226
227
228 public String getName() {
229 return "Jelly";
230 }
231
232 private void handleMainClassJarSearchButtonSelected()
233 {
234 FileDialog aDLOG = new FileDialog(this.getShell(), SWT.OPEN);
235 aDLOG.setFilterExtensions(new String[] {"*.jar"});
236
237 String projectName= aDLOG.open();
238 if(projectName != null)
239 fMainClassJarPathText.setText(projectName);
240 }
241
242 private void handleOutButtonSelected()
243 {
244 FileDialog aDLOG = new FileDialog(this.getShell(), SWT.OPEN);
245 aDLOG.setFilterExtensions(new String[] {"*.xml", "*.*"});
246
247 String projectName= aDLOG.open();
248 if(projectName != null)
249 fOutText.setText(projectName);
250 }
251
252 private void handleSearchButtonSelected()
253 {
254 FileDialog aDLOG = new FileDialog(this.getShell(), SWT.OPEN);
255 aDLOG.setFilterExtensions(new String[] {"*.jelly", "*.xml"});
256
257 String projectName= aDLOG.open();
258 if(projectName != null)
259 fScriptFilePathText.setText(projectName);
260 }
261
262
263
264 public boolean isValid(ILaunchConfiguration config)
265 {
266 boolean result = false;
267
268 try {
269 String scriptFilePath = config.getAttribute(JellyLaunchConfigurationConstants.ATTR_JELLYSCRIPT_PATH, EMPTY_STRING);
270 if( (scriptFilePath == null) || (scriptFilePath.length() == 0))
271 result = false;
272 else {
273 File scriptFile = new File(scriptFilePath);
274 result = scriptFile.exists() && scriptFile.isFile();
275 }
276
277 if(result == true)
278 {
279 String outputFilePath = config.getAttribute(JellyLaunchConfigurationConstants.ATTR_OUTPUT_PATH, EMPTY_STRING);
280 if( (outputFilePath == null) || (outputFilePath.length() == 0))
281 result = true;
282 else {
283 File outputFile = new File(outputFilePath);
284 result = outputFile.exists() && outputFile.isFile();
285 }
286 }
287
288 return result;
289 } catch (CoreException e) {
290 return false;
291 }
292 }
293 }