1 |
1 |
package org.txm.rcp.swt.widget.parameters;
|
2 |
2 |
|
3 |
3 |
import java.io.File;
|
4 |
|
import java.io.FileNotFoundException;
|
5 |
4 |
import java.io.FileReader;
|
6 |
5 |
import java.io.FileWriter;
|
7 |
6 |
import java.io.IOException;
|
... | ... | |
18 |
17 |
import org.eclipse.jface.dialogs.Dialog;
|
19 |
18 |
import org.eclipse.jface.dialogs.IDialogConstants;
|
20 |
19 |
import org.eclipse.swt.SWT;
|
|
20 |
import org.eclipse.swt.custom.ScrolledComposite;
|
|
21 |
import org.eclipse.swt.events.ControlAdapter;
|
|
22 |
import org.eclipse.swt.events.ControlEvent;
|
21 |
23 |
import org.eclipse.swt.events.SelectionAdapter;
|
22 |
24 |
import org.eclipse.swt.events.SelectionEvent;
|
|
25 |
import org.eclipse.swt.graphics.Point;
|
|
26 |
import org.eclipse.swt.graphics.Rectangle;
|
23 |
27 |
import org.eclipse.swt.layout.GridData;
|
24 |
28 |
import org.eclipse.swt.layout.GridLayout;
|
25 |
29 |
import org.eclipse.swt.widgets.Button;
|
26 |
30 |
import org.eclipse.swt.widgets.Composite;
|
27 |
31 |
import org.eclipse.swt.widgets.Control;
|
28 |
32 |
import org.eclipse.swt.widgets.Display;
|
29 |
|
import org.eclipse.swt.widgets.FileDialog;
|
30 |
33 |
import org.eclipse.swt.widgets.Label;
|
31 |
34 |
import org.eclipse.swt.widgets.Shell;
|
32 |
35 |
import org.kohsuke.args4j.CmdLineParser;
|
33 |
36 |
import org.kohsuke.args4j.NamedOptionDef;
|
34 |
37 |
import org.kohsuke.args4j.spi.OptionHandler;
|
35 |
38 |
import org.txm.Toolbox;
|
36 |
|
import org.txm.core.preferences.TBXPreferences;
|
37 |
39 |
import org.txm.rcp.messages.TXMUIMessages;
|
|
40 |
import org.txm.rcp.swt.GLComposite;
|
38 |
41 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
|
39 |
42 |
import org.txm.utils.Timer;
|
40 |
43 |
import org.txm.utils.logger.Log;
|
41 |
44 |
|
42 |
45 |
@SuppressWarnings("rawtypes")
|
43 |
46 |
public class ParametersDialog extends Dialog {
|
44 |
|
|
|
47 |
|
|
48 |
public int MAX_PARAMETERS_PER_LINE = 10;
|
|
49 |
|
45 |
50 |
Object bean;
|
46 |
|
|
|
51 |
|
47 |
52 |
String script;
|
48 |
|
|
|
53 |
|
49 |
54 |
String title;
|
50 |
|
|
|
55 |
|
51 |
56 |
List<NamedOptionDef> parameters;
|
52 |
|
|
|
57 |
|
53 |
58 |
List<String> fieldNames = new ArrayList<>(); // store all the declared parameters names
|
54 |
|
|
|
59 |
|
55 |
60 |
LinkedHashMap<String, ParameterField> widgets = new LinkedHashMap<>();
|
56 |
|
|
|
61 |
|
57 |
62 |
protected boolean error = false;
|
58 |
|
|
|
63 |
|
59 |
64 |
protected Map args; // store values given by another Macro, if contains all the needed values, no dialog is shown
|
60 |
|
|
|
65 |
|
61 |
66 |
protected int numberOfParameters; // number of parameters to show in the dialog box (not set by 'args'), if 0 parameters no dialog is shown
|
62 |
|
|
|
67 |
|
63 |
68 |
protected boolean mustShowDialog; // show dialog if args.size == 0 OR if there is at least one mandatory field to set
|
64 |
|
|
|
69 |
|
65 |
70 |
HashMap<String, Object> values = new HashMap<>(); // store the values of the parameters (may not contains all the values needed
|
66 |
|
|
|
71 |
|
67 |
72 |
Properties defaultValues; // default values set by the .properties file
|
68 |
|
|
|
73 |
|
69 |
74 |
Properties defaultScriptValues = new Properties(); // default values set by the Groovy script @Field@def annotation attribute
|
70 |
|
|
|
75 |
|
71 |
76 |
File propFile;
|
72 |
77 |
// private int titleWidth;
|
73 |
78 |
// private Composite parent;
|
74 |
|
|
|
79 |
|
75 |
80 |
/**
|
76 |
81 |
*
|
77 |
82 |
* @param parentShell
|
... | ... | |
81 |
86 |
*/
|
82 |
87 |
public ParametersDialog(Shell parentShell, Object bean, List<OptionHandler> allParameters, Map args) {
|
83 |
88 |
super(parentShell);
|
84 |
|
if (bean != null)
|
|
89 |
if (bean != null) {
|
85 |
90 |
this.script = bean.getClass().getName();
|
|
91 |
}
|
86 |
92 |
this.parameters = new ArrayList<>();
|
87 |
93 |
this.bean = bean;
|
88 |
94 |
this.args = args;
|
89 |
95 |
setShellStyle(getShellStyle() | SWT.RESIZE);
|
90 |
|
|
|
96 |
|
91 |
97 |
// count the number of fields to show. If "0" then don't show the dialog, see the "open()" function
|
92 |
98 |
// and select only the NamedOptionDef annotations
|
93 |
99 |
numberOfParameters = 0; // number of parameters not set by args
|
... | ... | |
100 |
106 |
if (args.containsKey(option.name())) {
|
101 |
107 |
continue; // don't show the field
|
102 |
108 |
}
|
103 |
|
|
|
109 |
|
104 |
110 |
// count number of mandatory fields set AND add exception for "Separator" widget types
|
105 |
111 |
if (option.required() || "Separator".equals(option.widget())) numberOfMandatoryFields++;
|
106 |
112 |
numberOfParameters++;
|
107 |
113 |
}
|
108 |
114 |
}
|
109 |
|
|
|
115 |
|
110 |
116 |
mustShowDialog = numberOfMandatoryFields > 0 || (args.size() == 0 && numberOfParameters > 0);
|
111 |
|
|
|
117 |
|
112 |
118 |
// initialize the properties file default values store
|
113 |
119 |
defaultValues = new Properties();
|
114 |
120 |
String scriptRootDir = Toolbox.getTxmHomePath() + "/scripts/groovy/user"; //$NON-NLS-1$
|
115 |
|
|
|
121 |
|
116 |
122 |
propFile = new File(scriptRootDir, this.script.replace(".", "/") + ".properties");
|
117 |
|
|
|
123 |
|
118 |
124 |
loadDefaultValuesFromPropFile();
|
119 |
|
|
120 |
|
|
121 |
125 |
}
|
122 |
|
|
123 |
|
|
|
126 |
|
|
127 |
|
124 |
128 |
private void loadDefaultValuesFromPropFile() {
|
125 |
129 |
if (propFile.exists()) {
|
126 |
130 |
try {
|
... | ... | |
132 |
136 |
Log.printStackTrace(e);
|
133 |
137 |
}
|
134 |
138 |
}
|
135 |
|
|
|
139 |
|
136 |
140 |
// initialize the script default values
|
137 |
141 |
for (NamedOptionDef option : this.parameters) {
|
138 |
142 |
String widgetName = option.widget();
|
... | ... | |
197 |
201 |
}
|
198 |
202 |
}
|
199 |
203 |
}
|
200 |
|
|
201 |
|
|
|
204 |
|
202 |
205 |
/*
|
203 |
206 |
* (non-Javadoc)
|
204 |
207 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
... | ... | |
210 |
213 |
if (idx2 < 0) idx2 = script.length();
|
211 |
214 |
title = TXMUIMessages.bind(TXMUIMessages.p0ParametersInput, script.substring(script.lastIndexOf(".") + 1, idx2));
|
212 |
215 |
newShell.setText(title);
|
|
216 |
newShell.setMinimumSize(250, 450);
|
|
217 |
|
|
218 |
// newShell.addControlListener(new ControlAdapter() {
|
|
219 |
// public void controlResized(ControlEvent e) {
|
|
220 |
// Rectangle area = newShell.getClientArea();
|
|
221 |
// Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
|
222 |
// int width = area.width - 2*table.getBorderWidth();
|
|
223 |
// if (preferredSize.y > area.height + table.getHeaderHeight()) {
|
|
224 |
// // Subtract the scrollbar width from the total column width
|
|
225 |
// // if a vertical scrollbar will be required
|
|
226 |
// Point vBarSize = table.getVerticalBar().getSize();
|
|
227 |
// width -= vBarSize.x;
|
|
228 |
// }
|
|
229 |
// Point oldSize = table.getSize();
|
|
230 |
// if (oldSize.x > area.width) {
|
|
231 |
// // table is getting smaller so make the columns // smaller first and then resize the table to
|
|
232 |
// // match the client area width
|
|
233 |
// column1.setWidth(width/3);
|
|
234 |
// column2.setWidth(width - column1.getWidth());
|
|
235 |
// table.setSize(area.width, area.height);
|
|
236 |
// } else {
|
|
237 |
// // table is getting bigger so make the table // bigger first and then make the columns wider
|
|
238 |
// // to match the client area width
|
|
239 |
// table.setSize(area.width, area.height);
|
|
240 |
// column1.setWidth(width/3);
|
|
241 |
// column2.setWidth(width - column1.getWidth());
|
|
242 |
// }
|
|
243 |
// }
|
|
244 |
// });
|
213 |
245 |
}
|
214 |
246 |
|
215 |
247 |
@Override
|
|
248 |
protected boolean isResizable() {
|
|
249 |
return true;
|
|
250 |
}
|
|
251 |
|
|
252 |
@Override
|
216 |
253 |
protected void createButtonsForButtonBar(Composite parent) {
|
217 |
254 |
// create the reset button (hack of the Back button)
|
218 |
255 |
// Button propButton = createButton(parent, IDialogConstants.BACK_ID,
|
... | ... | |
233 |
270 |
// }
|
234 |
271 |
// }
|
235 |
272 |
// });
|
236 |
|
|
237 |
|
Button button = createButton(parent, IDialogConstants.BACK_ID,
|
238 |
|
"Reset values", false);
|
|
273 |
|
|
274 |
Button button = createButton(parent, IDialogConstants.BACK_ID, "Reset values", false);
|
239 |
275 |
button.removeListener(SWT.Selection, button.getListeners(SWT.Selection)[0]);
|
240 |
|
|
|
276 |
|
241 |
277 |
button.addSelectionListener(new SelectionAdapter() {
|
242 |
|
|
|
278 |
|
243 |
279 |
@Override
|
244 |
280 |
public void widgetSelected(SelectionEvent e) {
|
245 |
281 |
// System.out.println("Reseting fields to default values");
|
... | ... | |
249 |
285 |
}
|
250 |
286 |
});
|
251 |
287 |
if (numberOfParameters == 0) button.setEnabled(false);
|
252 |
|
|
|
288 |
|
253 |
289 |
super.createButtonsForButtonBar(parent);
|
254 |
290 |
this.getButton(IDialogConstants.OK_ID).setText(TXMUIMessages.run);
|
255 |
291 |
}
|
256 |
|
|
|
292 |
|
257 |
293 |
@Override
|
258 |
294 |
protected Control createButtonBar(Composite parent) {
|
259 |
295 |
Control c = super.createButtonBar(parent);
|
260 |
|
|
|
296 |
|
261 |
297 |
// int barWidth = c.getSize().x;
|
262 |
298 |
// if (barWidth > titleWidth) {
|
263 |
299 |
// GridData cdata = (GridData)(this.parent.getLayoutData());
|
264 |
300 |
// cdata.widthHint = barWidth;
|
265 |
301 |
// }
|
266 |
|
|
|
302 |
|
267 |
303 |
return c;
|
268 |
304 |
}
|
269 |
|
|
|
305 |
|
270 |
306 |
/*
|
271 |
307 |
* (non-Javadoc)
|
272 |
308 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
... | ... | |
275 |
311 |
protected Control createDialogArea(Composite composite) {
|
276 |
312 |
// this.parent = composite;
|
277 |
313 |
super.createDialogArea(composite);
|
278 |
|
|
279 |
|
composite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, true));
|
280 |
|
|
|
314 |
|
|
315 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
281 |
316 |
GridLayout layout = new GridLayout(1, true);
|
282 |
317 |
composite.setLayout(layout);
|
|
318 |
|
|
319 |
// ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.BORDER| SWT.H_SCROLL | SWT.V_SCROLL);
|
|
320 |
// scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
|
321 |
// scrolledComposite.setLayout(new GridLayout(1, true));
|
|
322 |
|
|
323 |
GLComposite columns = new GLComposite(composite, SWT.NONE, "columns");
|
|
324 |
columns.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
|
325 |
columns.getLayout().numColumns = 1;
|
|
326 |
|
|
327 |
// scrolledComposite.setContent(columns);
|
|
328 |
// scrolledComposite.addListener( SWT.Resize, event -> {
|
|
329 |
// int width = scrolledComposite.getClientArea().width;
|
|
330 |
// scrolledComposite.setMinSize( composite.computeSize( width, SWT.DEFAULT ) );
|
|
331 |
// } );
|
|
332 |
|
|
333 |
|
|
334 |
if (numberOfParameters > MAX_PARAMETERS_PER_LINE) {
|
|
335 |
columns.getLayout().numColumns = 1 + (numberOfParameters / MAX_PARAMETERS_PER_LINE);
|
|
336 |
}
|
|
337 |
|
|
338 |
GLComposite column = new GLComposite(columns, SWT.NONE, "column");
|
|
339 |
GridData gdata = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
340 |
gdata.minimumWidth = 200;
|
|
341 |
column.setLayoutData(gdata);
|
|
342 |
column.getLayout().makeColumnsEqualWidth = false;
|
283 |
343 |
|
284 |
|
// TODO: this width initialization does not works : it does not depends on the buttonBar width
|
285 |
|
// GridData cdata = (GridData)(composite.getLayoutData());
|
286 |
|
// titleWidth = FitFontSize.calculate(composite, title) + 100;
|
287 |
|
// cdata.widthHint = titleWidth;
|
288 |
|
|
289 |
344 |
// initialize each widget + default value *of the widget*
|
|
345 |
int n = 0;
|
290 |
346 |
for (NamedOptionDef option : parameters) {
|
291 |
|
// if (arg.option instanceof NamedOptionDef) {
|
292 |
|
|
293 |
|
// NamedOptionDef option = (NamedOptionDef)arg.option;
|
294 |
|
|
295 |
|
// if the 'args' contains a value filled by another Macro, don't show the widget
|
296 |
|
if (args.containsKey(option.name())) {
|
297 |
|
// System.out.println("Args contains '"+option.name()+"' with value '"+args.get(option.name())+"'");
|
298 |
|
continue; // don't show the field
|
|
347 |
n++;
|
|
348 |
if (n % MAX_PARAMETERS_PER_LINE == 0) {
|
|
349 |
column = new GLComposite(columns, SWT.NONE, "column");
|
|
350 |
gdata = new GridData(SWT.FILL, SWT.FILL, true, true);
|
|
351 |
gdata.minimumWidth = 200;
|
|
352 |
column.setLayoutData(gdata);
|
|
353 |
column.getLayout().makeColumnsEqualWidth = false;
|
299 |
354 |
}
|
300 |
|
|
|
355 |
|
301 |
356 |
// each widget is initialized with de default value set in @Field@def attribute
|
302 |
357 |
String widgetName = option.widget();
|
303 |
358 |
ParameterField widget = null;
|
304 |
359 |
if ("File".equals(widgetName) || "FileOpen".equals(widgetName)) { //$NON-NLS-1$
|
305 |
|
widget = new FileField(composite, SWT.NONE, option);
|
|
360 |
widget = new FileField(column, SWT.NONE, option);
|
306 |
361 |
}
|
307 |
362 |
else if ("CreateFile".equals(widgetName) || "FileSave".equals(widgetName)) { //$NON-NLS-1$
|
308 |
|
widget = new CreateFileField(composite, SWT.NONE, option);
|
|
363 |
widget = new CreateFileField(column, SWT.NONE, option);
|
309 |
364 |
}
|
310 |
365 |
else if ("Folder".equals(widgetName)) { //$NON-NLS-1$
|
311 |
|
widget = new FolderField(composite, SWT.NONE, option);
|
|
366 |
widget = new FolderField(column, SWT.NONE, option);
|
312 |
367 |
}
|
313 |
368 |
else if ("Query".equals(widgetName)) { //$NON-NLS-1$
|
314 |
|
widget = new QueryField(composite, SWT.NONE, option);
|
|
369 |
widget = new QueryField(column, SWT.NONE, option);
|
315 |
370 |
}
|
316 |
371 |
else if ("Date".equals(widgetName)) { //$NON-NLS-1$
|
317 |
|
widget = new DateField(composite, SWT.NONE, option);
|
|
372 |
widget = new DateField(column, SWT.NONE, option);
|
318 |
373 |
}
|
319 |
374 |
else if ("Time".equals(widgetName)) { //$NON-NLS-1$
|
320 |
|
widget = new TimeField(composite, SWT.NONE, option);
|
|
375 |
widget = new TimeField(column, SWT.NONE, option);
|
321 |
376 |
}
|
322 |
377 |
else if ("Separator".equals(widgetName)) { //$NON-NLS-1$
|
323 |
|
widget = new SeparatorField(composite, SWT.NONE, option);
|
|
378 |
widget = new SeparatorField(column, SWT.NONE, option);
|
324 |
379 |
}
|
325 |
380 |
else if ("String".equals(widgetName)) { //$NON-NLS-1$
|
326 |
|
widget = new StringField(composite, SWT.NONE, option);
|
|
381 |
widget = new StringField(column, SWT.NONE, option);
|
327 |
382 |
}
|
328 |
383 |
else if ("Password".equals(widgetName)) { //$NON-NLS-1$
|
329 |
|
widget = new PasswordField(composite, SWT.NONE, option);
|
|
384 |
widget = new PasswordField(column, SWT.NONE, option);
|
330 |
385 |
}
|
331 |
386 |
else if ("StringArray".equals(widgetName)) { //$NON-NLS-1$
|
332 |
|
widget = new StringArrayField(composite, SWT.NONE, option);
|
|
387 |
widget = new StringArrayField(column, SWT.NONE, option);
|
333 |
388 |
}
|
334 |
389 |
else if ("StringArrayMultiple".equals(widgetName)) { //$NON-NLS-1$
|
335 |
|
widget = new StringArrayMultipleField(composite, SWT.NONE, option);
|
|
390 |
widget = new StringArrayMultipleField(column, SWT.NONE, option);
|
336 |
391 |
}
|
337 |
392 |
else if ("StructuralUnits".equals(widgetName)) { //$NON-NLS-1$
|
338 |
|
widget = new CospusStructuresField(composite, SWT.NONE, option);
|
|
393 |
widget = new CospusStructuresField(column, SWT.NONE, option);
|
339 |
394 |
}
|
340 |
395 |
else if ("Text".equals(widgetName)) { //$NON-NLS-1$
|
341 |
|
widget = new LongStringField(composite, SWT.NONE, option);
|
|
396 |
widget = new LongStringField(column, SWT.NONE, option);
|
342 |
397 |
}
|
343 |
398 |
else if ("Integer".equals(widgetName)) { //$NON-NLS-1$
|
344 |
|
widget = new IntegerField(composite, SWT.NONE, option);
|
|
399 |
widget = new IntegerField(column, SWT.NONE, option);
|
345 |
400 |
}
|
346 |
401 |
else if ("Float".equals(widgetName)) { //$NON-NLS-1$
|
347 |
|
widget = new FloatField(composite, SWT.NONE, option);
|
|
402 |
widget = new FloatField(column, SWT.NONE, option);
|
348 |
403 |
}
|
349 |
404 |
else if ("Boolean".equals(widgetName)) { //$NON-NLS-1$
|
350 |
|
widget = new BooleanField(composite, SWT.NONE, option);
|
|
405 |
widget = new BooleanField(column, SWT.NONE, option);
|
351 |
406 |
}
|
352 |
407 |
else {
|
353 |
408 |
System.out.println(TXMUIMessages.unknowedWidgetNameColon + widgetName + TXMUIMessages.FileTreeContentProvider_4);
|
354 |
409 |
}
|
355 |
|
|
|
410 |
|
356 |
411 |
if (widget != null) {
|
357 |
412 |
widgets.put(option.name(), widget);
|
358 |
|
|
|
413 |
|
359 |
414 |
// set default value in the fields, not enough if args contains the value
|
360 |
415 |
String value = defaultValues.getProperty(option.name());
|
361 |
416 |
if (value != null) { // set the default value using the properties stored
|
362 |
417 |
widget.setDefault(value);
|
363 |
418 |
}
|
364 |
419 |
}
|
365 |
|
// }
|
366 |
420 |
}
|
367 |
421 |
new Label(composite, SWT.NONE).setText(TXMUIMessages.mandatoryFields);
|
368 |
|
|
|
422 |
|
369 |
423 |
return composite;
|
370 |
424 |
}
|
371 |
|
|
|
425 |
|
372 |
426 |
/*
|
373 |
427 |
* (non-Javadoc)
|
374 |
428 |
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
|
... | ... | |
376 |
430 |
@Override
|
377 |
431 |
protected void okPressed() {
|
378 |
432 |
error = false;
|
379 |
|
|
|
433 |
|
380 |
434 |
// get widget values
|
381 |
435 |
for (String field : widgets.keySet()) {
|
382 |
436 |
ParameterField w = widgets.get(field);
|
383 |
437 |
Object value = w.getWidgetValue();
|
384 |
|
|
|
438 |
|
385 |
439 |
// is widget set if mandatory EXCEPT "Separator" widgets
|
386 |
440 |
if (w.isWidgetMandatory() && value == null && !("Separator".equals(w.getWidgetType()))) {
|
387 |
441 |
System.out.println(TXMUIMessages.errorColonMissingValueColon + field);
|
... | ... | |
392 |
446 |
// System.out.println(""+field+"\t"+values.get(field));
|
393 |
447 |
} // else value is not filled
|
394 |
448 |
}
|
395 |
|
|
|
449 |
|
396 |
450 |
// initialize variables
|
397 |
451 |
if (!error) {
|
398 |
452 |
initializeMacroVariables();
|
399 |
453 |
saveParameters();
|
400 |
|
|
|
454 |
|
401 |
455 |
if (!error) {
|
402 |
456 |
super.okPressed();
|
403 |
457 |
}
|
404 |
458 |
}
|
405 |
459 |
}
|
406 |
|
|
|
460 |
|
407 |
461 |
private void saveParameters() {
|
408 |
462 |
if (!error) {
|
409 |
463 |
try {
|
... | ... | |
416 |
470 |
}
|
417 |
471 |
}
|
418 |
472 |
}
|
419 |
|
|
420 |
|
|
|
473 |
|
|
474 |
|
421 |
475 |
/**
|
422 |
476 |
* can use the args map to initialize variable not set with the dialog box
|
423 |
477 |
*/
|
424 |
478 |
private void initializeMacroVariables() {
|
425 |
479 |
// System.out.println("Initialize macro variables of "+fieldNames);
|
426 |
480 |
if (bean == null) return;
|
427 |
|
|
|
481 |
|
428 |
482 |
Class c = bean.getClass();
|
429 |
483 |
for (String name : fieldNames) {
|
430 |
484 |
Object value = values.get(name);
|
... | ... | |
443 |
497 |
defaultValues.setProperty(name, value.toString());
|
444 |
498 |
}
|
445 |
499 |
}
|
446 |
|
|
|
500 |
|
447 |
501 |
try {
|
448 |
502 |
// System.out.println("setting "+name+ " with "+values.get(name));
|
449 |
503 |
Field field = c.getDeclaredField(name);
|
... | ... | |
455 |
509 |
Log.printStackTrace(e);
|
456 |
510 |
error = true;
|
457 |
511 |
}
|
458 |
|
|
|
512 |
|
459 |
513 |
}
|
460 |
514 |
}
|
461 |
|
|
462 |
|
|
|
515 |
|
|
516 |
|
463 |
517 |
protected boolean isError() {
|
464 |
518 |
return error;
|
465 |
519 |
}
|
466 |
|
|
|
520 |
|
467 |
521 |
public HashMap<String, Object> getValues() {
|
468 |
522 |
return values;
|
469 |
523 |
}
|
470 |
|
|
|
524 |
|
471 |
525 |
static boolean errorOpen, retOpen;
|
472 |
|
|
|
526 |
|
473 |
527 |
/**
|
474 |
528 |
* Conveniance method to initialize the parameters dialog.
|
475 |
529 |
* Can detect the "args" Groovy binding and use it to set variables
|
... | ... | |
481 |
535 |
public static boolean open(final Object bean) {
|
482 |
536 |
errorOpen = true;
|
483 |
537 |
retOpen = false;
|
484 |
|
|
|
538 |
|
485 |
539 |
// if (!(bean instanceof groovy.lang.Script)) {
|
486 |
540 |
// System.out.println(Messages.ParametersDialog_15);
|
487 |
541 |
// return false;
|
488 |
542 |
// }
|
489 |
|
|
|
543 |
|
490 |
544 |
Object oArgs = null;
|
491 |
545 |
if (bean instanceof groovy.lang.Script) {
|
492 |
546 |
groovy.lang.Script script = (groovy.lang.Script) bean;
|
493 |
|
|
|
547 |
|
494 |
548 |
// if the "args" variable exists then use its values. Can be used to set a default value by another Macro
|
495 |
549 |
if (script.getBinding().hasVariable("args")) {
|
496 |
550 |
oArgs = script.getBinding().getVariable("args"); //$NON-NLS-1$
|
497 |
551 |
}
|
498 |
552 |
}
|
499 |
|
|
|
553 |
|
500 |
554 |
final Map args;
|
501 |
555 |
if (oArgs == null || !(oArgs instanceof Map)) {
|
502 |
556 |
args = new HashMap<String, Object>();
|
... | ... | |
504 |
558 |
else {
|
505 |
559 |
args = (Map) oArgs;
|
506 |
560 |
}
|
507 |
|
|
|
561 |
|
508 |
562 |
if (bean instanceof groovy.lang.Script) { // create the args binding if not already existing
|
509 |
563 |
groovy.lang.Script script = (groovy.lang.Script) bean;
|
510 |
564 |
if (!script.getBinding().hasVariable("args")) {
|
511 |
565 |
script.getBinding().setVariable("args", args);
|
512 |
566 |
}
|
513 |
567 |
}
|
514 |
|
|
|
568 |
|
515 |
569 |
Display.getDefault().syncExec(new Runnable() {
|
516 |
|
|
|
570 |
|
517 |
571 |
@Override
|
518 |
572 |
public void run() {
|
519 |
573 |
boolean okNames = true;
|
520 |
574 |
CmdLineParser parser = new CmdLineParser(bean);
|
521 |
|
|
|
575 |
|
522 |
576 |
Display display = Display.getCurrent();
|
523 |
577 |
Shell shell = display.getActiveShell();
|
524 |
|
|
|
578 |
|
525 |
579 |
// check names
|
526 |
580 |
Class c = bean.getClass();
|
527 |
581 |
for (OptionHandler opt : parser.getOptions()) {
|
... | ... | |
550 |
604 |
retOpen = true;
|
551 |
605 |
errorOpen = false;
|
552 |
606 |
}
|
553 |
|
|
|
607 |
|
554 |
608 |
if (bean instanceof groovy.lang.Script) { // reset the timer binding if already existing
|
555 |
609 |
groovy.lang.Script script = (groovy.lang.Script) bean;
|
556 |
610 |
if (script.getBinding().hasVariable("timer")) {
|
... | ... | |
563 |
617 |
});
|
564 |
618 |
return retOpen && !errorOpen;
|
565 |
619 |
}
|
566 |
|
|
|
620 |
|
567 |
621 |
public boolean getMustShowDialog() {
|
568 |
622 |
return mustShowDialog;
|
569 |
623 |
}
|
570 |
|
|
|
624 |
|
571 |
625 |
protected int getNumberOfFields() {
|
572 |
626 |
return numberOfParameters;
|
573 |
627 |
}
|
574 |
|
|
|
628 |
|
575 |
629 |
// TODO: uncomment this to enable "args" detection
|
576 |
630 |
// public int open() {
|
577 |
631 |
// System.out.println("Number of parameters: "+numberOfParameters);
|