-
Notifications
You must be signed in to change notification settings - Fork 1
/
JobEntryZipFileDialog.java
542 lines (449 loc) · 18.5 KB
/
JobEntryZipFileDialog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/**********************************************************************
** **
** This code belongs to the KETTLE project. **
** **
** **
** **
**********************************************************************/
package be.ibridge.kettle.job.entry.zipfile;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import be.ibridge.kettle.core.Const;
import be.ibridge.kettle.core.Props;
import be.ibridge.kettle.core.WindowProperty;
import be.ibridge.kettle.core.util.StringUtil;
import be.ibridge.kettle.core.widget.TextVar;
import be.ibridge.kettle.job.JobMeta;
import be.ibridge.kettle.job.dialog.JobDialog;
import be.ibridge.kettle.job.entry.JobEntryDialogInterface;
import be.ibridge.kettle.job.entry.JobEntryInterface;
import be.ibridge.kettle.trans.step.BaseStepDialog;
/**
* This dialog allows you to edit the Create File job entry settings.
*
* @author Samatar Hassan
* @since 27-02-2007
*/
public class JobEntryZipFileDialog extends Dialog implements JobEntryDialogInterface
{
private static final String[] FILETYPES = new String[] {
Messages.getString("JobZipFiles.Filetype.Zip"),
Messages.getString("JobZipFiles.Filetype.All")};
private Label wlName;
private Text wName;
private FormData fdlName, fdName;
private Label wlZipFilename;
private Button wbZipFilename;
private TextVar wZipFilename;
private FormData fdlZipFilename, fdbZipFilename, fdZipFilename;
private Button wOK, wCancel;
private Listener lsOK, lsCancel;
private JobEntryZipFile jobEntry;
private Shell shell;
private Props props;
private Label wlTargetDirectory;
private TextVar wTargetDirectory;
private FormData fdlTargetDirectory, fdTargetDirectory;
private Label wlMovetoDirectory;
private TextVar wMovetoDirectory;
private FormData fdlMovetoDirectory, fdMovetoDirectory;
private Label wlWildcard;
private TextVar wWildcard;
private FormData fdlWildcard, fdWildcard;
private Label wlWildcardExclude;
private TextVar wWildcardExclude;
private FormData fdlWildcardExclude, fdWildcardExclude;
private Label wlCompressionRate;
private CCombo wCompressionRate;
private FormData fdlCompressionRate, fdCompressionRate;
private Label wlIfFileExists;
private CCombo wIfFileExists;
private FormData fdlIfFileExists, fdIfFileExists;
private Label wlAfterZip;
private CCombo wAfterZip;
private FormData fdlAfterZip, fdAfterZip;
private SelectionAdapter lsDef;
private boolean changed;
public JobEntryZipFileDialog(Shell parent, JobEntryZipFile jobEntry, JobMeta jobMeta)
{
super(parent, SWT.NONE);
props=Props.getInstance();
this.jobEntry=jobEntry;
if (this.jobEntry.getName() == null)
this.jobEntry.setName(Messages.getString("JobZipFiles.Name.Default"));
}
public JobEntryInterface open()
{
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, props.getJobsDialogStyle());
props.setLook(shell);
JobDialog.setShellImage(shell, jobEntry);
ModifyListener lsMod = new ModifyListener()
{
public void modifyText(ModifyEvent e)
{
jobEntry.setChanged();
}
};
changed = jobEntry.hasChanged();
FormLayout formLayout = new FormLayout ();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(Messages.getString("JobZipFiles.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// ZipFilename line
wlName=new Label(shell, SWT.RIGHT);
wlName.setText(Messages.getString("JobZipFiles.Name.Label"));
props.setLook(wlName);
fdlName=new FormData();
fdlName.left = new FormAttachment(0, 0);
fdlName.right= new FormAttachment(middle, -margin);
fdlName.top = new FormAttachment(0, margin);
wlName.setLayoutData(fdlName);
wName=new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wName);
wName.addModifyListener(lsMod);
fdName=new FormData();
fdName.left = new FormAttachment(middle, 0);
fdName.top = new FormAttachment(0, margin);
fdName.right= new FormAttachment(100, 0);
wName.setLayoutData(fdName);
// TargetDirectory line
wlTargetDirectory = new Label(shell, SWT.RIGHT);
wlTargetDirectory.setText(Messages.getString("JobZipFiles.TargetDir.Label"));
props.setLook(wlTargetDirectory);
fdlTargetDirectory = new FormData();
fdlTargetDirectory.left = new FormAttachment(0, 0);
fdlTargetDirectory.top = new FormAttachment(wName, margin);
fdlTargetDirectory.right = new FormAttachment(middle, -margin);
wlTargetDirectory.setLayoutData(fdlTargetDirectory);
wTargetDirectory = new TextVar(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER, Messages
.getString("JobZipFiles.TargetDir.Tooltip"));
props.setLook(wTargetDirectory);
wTargetDirectory.addModifyListener(lsMod);
fdTargetDirectory = new FormData();
fdTargetDirectory.left = new FormAttachment(middle, 0);
fdTargetDirectory.top = new FormAttachment(wName, margin);
fdTargetDirectory.right = new FormAttachment(100, 0);
wTargetDirectory.setLayoutData(fdTargetDirectory);
// Wildcard line
wlWildcard = new Label(shell, SWT.RIGHT);
wlWildcard.setText(Messages.getString("JobZipFiles.Wildcard.Label"));
props.setLook(wlWildcard);
fdlWildcard = new FormData();
fdlWildcard.left = new FormAttachment(0, 0);
fdlWildcard.top = new FormAttachment(wTargetDirectory, margin);
fdlWildcard.right = new FormAttachment(middle, -margin);
wlWildcard.setLayoutData(fdlWildcard);
wWildcard = new TextVar(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER, Messages
.getString("JobZipFiles.Wildcard.Tooltip"));
props.setLook(wWildcard);
wWildcard.addModifyListener(lsMod);
fdWildcard = new FormData();
fdWildcard.left = new FormAttachment(middle, 0);
fdWildcard.top = new FormAttachment(wTargetDirectory, margin);
fdWildcard.right = new FormAttachment(100, 0);
wWildcard.setLayoutData(fdWildcard);
// Wildcard to exclude
wlWildcardExclude = new Label(shell, SWT.RIGHT);
wlWildcardExclude.setText(Messages.getString("JobZipFiles.WildcardExclude.Label"));
props.setLook(wlWildcardExclude);
fdlWildcardExclude = new FormData();
fdlWildcardExclude.left = new FormAttachment(0, 0);
fdlWildcardExclude.top = new FormAttachment(wWildcard, margin);
fdlWildcardExclude.right = new FormAttachment(middle, -margin);
wlWildcardExclude.setLayoutData(fdlWildcardExclude);
wWildcardExclude = new TextVar(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER, Messages
.getString("JobZipFiles.WildcardExclude.Tooltip"));
props.setLook(wWildcardExclude);
wWildcardExclude.addModifyListener(lsMod);
fdWildcardExclude = new FormData();
fdWildcardExclude.left = new FormAttachment(middle, 0);
fdWildcardExclude.top = new FormAttachment(wWildcard, margin);
fdWildcardExclude.right = new FormAttachment(100, 0);
wWildcardExclude.setLayoutData(fdWildcardExclude);
// ZipFilename line
wlZipFilename=new Label(shell, SWT.RIGHT);
wlZipFilename.setText(Messages.getString("JobZipFiles.ZipFilename.Label"));
props.setLook(wlZipFilename);
fdlZipFilename=new FormData();
fdlZipFilename.left = new FormAttachment(0, 0);
fdlZipFilename.top = new FormAttachment(wWildcardExclude, margin);
fdlZipFilename.right= new FormAttachment(middle, -margin);
wlZipFilename.setLayoutData(fdlZipFilename);
wbZipFilename=new Button(shell, SWT.PUSH| SWT.CENTER);
props.setLook(wbZipFilename);
wbZipFilename.setText(Messages.getString("System.Button.Browse"));
fdbZipFilename=new FormData();
fdbZipFilename.right= new FormAttachment(100, 0);
fdbZipFilename.top = new FormAttachment(wWildcardExclude, 0);
wbZipFilename.setLayoutData(fdbZipFilename);
wZipFilename=new TextVar(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wZipFilename);
wZipFilename.addModifyListener(lsMod);
fdZipFilename=new FormData();
fdZipFilename.left = new FormAttachment(middle, 0);
fdZipFilename.top = new FormAttachment(wWildcardExclude, margin);
fdZipFilename.right= new FormAttachment(wbZipFilename, -margin);
wZipFilename.setLayoutData(fdZipFilename);
// Whenever something changes, set the tooltip to the expanded version:
wZipFilename.addModifyListener(new ModifyListener()
{
public void modifyText(ModifyEvent e)
{
wZipFilename.setToolTipText(StringUtil.environmentSubstitute( wZipFilename.getText() ) );
}
}
);
wbZipFilename.addSelectionListener
(
new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
//dialog.setFilterExtensions(new String[] {"*"});
dialog.setFilterExtensions(new String[] {"*.zip;*.ZIP", "*"});
if (wZipFilename.getText()!=null)
{
dialog.setFileName(StringUtil.environmentSubstitute(wZipFilename.getText()) );
}
dialog.setFilterNames(FILETYPES);
if (dialog.open()!=null)
{
wZipFilename.setText(dialog.getFilterPath()+Const.FILE_SEPARATOR+dialog.getFileName());
}
}
}
);
//Compression Rate
wlCompressionRate = new Label(shell, SWT.RIGHT);
wlCompressionRate.setText(Messages.getString("JobZipFiles.CompressionRate.Label"));
props.setLook(wlCompressionRate);
fdlCompressionRate = new FormData();
fdlCompressionRate.left = new FormAttachment(0, 0);
fdlCompressionRate.right = new FormAttachment(middle, 0);
fdlCompressionRate.top = new FormAttachment(wZipFilename, margin);
wlCompressionRate.setLayoutData(fdlCompressionRate);
wCompressionRate = new CCombo(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
wCompressionRate.add(Messages.getString("JobZipFiles.NO_COMP_CompressionRate.Label"));
wCompressionRate.add(Messages.getString("JobZipFiles.DEF_COMP_CompressionRate.Label"));
wCompressionRate.add(Messages.getString("JobZipFiles.BEST_COMP_CompressionRate.Label"));
wCompressionRate.add(Messages.getString("JobZipFiles.BEST_SPEED_CompressionRate.Label"));
wCompressionRate.select(1); // +1: starts at -1
props.setLook(wCompressionRate);
fdCompressionRate= new FormData();
fdCompressionRate.left = new FormAttachment(middle, 0);
fdCompressionRate.top = new FormAttachment(wZipFilename, margin);
fdCompressionRate.right = new FormAttachment(100, 0);
wCompressionRate.setLayoutData(fdCompressionRate);
fdCompressionRate = new FormData();
fdCompressionRate.left = new FormAttachment(middle, 0);
fdCompressionRate.top = new FormAttachment(wZipFilename, margin);
fdCompressionRate.right = new FormAttachment(100, 0);
wCompressionRate.setLayoutData(fdCompressionRate);
//IF File Exists
wlIfFileExists = new Label(shell, SWT.RIGHT);
wlIfFileExists.setText(Messages.getString("JobZipFiles.IfZipFileExists.Label"));
props.setLook(wlIfFileExists);
fdlIfFileExists = new FormData();
fdlIfFileExists.left = new FormAttachment(0, 0);
fdlIfFileExists.right = new FormAttachment(middle, 0);
fdlIfFileExists.top = new FormAttachment(wCompressionRate, margin);
wlIfFileExists.setLayoutData(fdlIfFileExists);
wIfFileExists = new CCombo(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
wIfFileExists.add(Messages.getString("JobZipFiles.Create_NewFile_IfFileExists.Label"));
wIfFileExists.add(Messages.getString("JobZipFiles.Append_File_IfFileExists.Label"));
wIfFileExists.add(Messages.getString("JobZipFiles.Do_Nothing_IfFileExists.Label"));
wIfFileExists.add(Messages.getString("JobZipFiles.Fail_IfFileExists.Label"));
wIfFileExists.select(3); // +1: starts at -1
props.setLook(wIfFileExists);
fdIfFileExists= new FormData();
fdIfFileExists.left = new FormAttachment(middle, 0);
fdIfFileExists.top = new FormAttachment(wCompressionRate, margin);
fdIfFileExists.right = new FormAttachment(100, 0);
wIfFileExists.setLayoutData(fdIfFileExists);
fdIfFileExists = new FormData();
fdIfFileExists.left = new FormAttachment(middle, 0);
fdIfFileExists.top = new FormAttachment(wCompressionRate, margin);
fdIfFileExists.right = new FormAttachment(100, 0);
wIfFileExists.setLayoutData(fdIfFileExists);
//After Zipping
wlAfterZip = new Label(shell, SWT.RIGHT);
wlAfterZip.setText(Messages.getString("JobZipFiles.AfterZip.Label"));
props.setLook(wlAfterZip);
fdlAfterZip = new FormData();
fdlAfterZip.left = new FormAttachment(0, 0);
fdlAfterZip.right = new FormAttachment(middle, 0);
fdlAfterZip.top = new FormAttachment(wIfFileExists, margin);
wlAfterZip.setLayoutData(fdlAfterZip);
wAfterZip = new CCombo(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
wAfterZip.add(Messages.getString("JobZipFiles.Do_Nothing_AfterZip.Label"));
wAfterZip.add(Messages.getString("JobZipFiles.Delete_Files_AfterZip.Label"));
wAfterZip.add(Messages.getString("JobZipFiles.Move_Files_AfterZip.Label"));
wAfterZip.select(0); // +1: starts at -1
props.setLook(wAfterZip);
fdAfterZip= new FormData();
fdAfterZip.left = new FormAttachment(middle, 0);
fdAfterZip.top = new FormAttachment(wIfFileExists, margin);
fdAfterZip.right = new FormAttachment(100, 0);
wAfterZip.setLayoutData(fdAfterZip);
fdAfterZip = new FormData();
fdAfterZip.left = new FormAttachment(middle, 0);
fdAfterZip.top = new FormAttachment(wIfFileExists, margin);
fdAfterZip.right = new FormAttachment(100, 0);
wAfterZip.setLayoutData(fdAfterZip);
wAfterZip.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
AfterZipActivate();
}
});
// moveTo Directory
wlMovetoDirectory = new Label(shell, SWT.RIGHT);
wlMovetoDirectory.setText(Messages.getString("JobZipFiles.MovetoDirectory.Label"));
props.setLook(wlMovetoDirectory);
fdlMovetoDirectory = new FormData();
fdlMovetoDirectory.left = new FormAttachment(0, 0);
fdlMovetoDirectory.top = new FormAttachment(wAfterZip, margin);
fdlMovetoDirectory.right = new FormAttachment(middle, -margin);
wlMovetoDirectory.setLayoutData(fdlMovetoDirectory);
wMovetoDirectory = new TextVar(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER, Messages
.getString("JobZipFiles.MovetoDirectory.Tooltip"));
props.setLook(wMovetoDirectory);
wMovetoDirectory.addModifyListener(lsMod);
fdMovetoDirectory = new FormData();
fdMovetoDirectory.left = new FormAttachment(middle, 0);
fdMovetoDirectory.top = new FormAttachment(wAfterZip, margin);
fdMovetoDirectory.right = new FormAttachment(100, 0);
wMovetoDirectory.setLayoutData(fdMovetoDirectory);
wOK = new Button(shell, SWT.PUSH);
wOK.setText(Messages.getString("System.Button.OK"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(Messages.getString("System.Button.Cancel"));
BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK, wCancel }, margin, wMovetoDirectory);
// Add listeners
lsCancel = new Listener() { public void handleEvent(Event e) { cancel(); } };
lsOK = new Listener() { public void handleEvent(Event e) { ok(); } };
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener (SWT.Selection, lsOK );
lsDef=new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent e) { ok(); } };
wName.addSelectionListener( lsDef );
wZipFilename.addSelectionListener( lsDef );
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener( new ShellAdapter() { public void shellClosed(ShellEvent e) { cancel(); } } );
getData();
AfterZipActivate();
BaseStepDialog.setSize(shell);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch()) display.sleep();
}
return jobEntry;
}
public void AfterZipActivate()
{
jobEntry.setChanged();
if (wAfterZip.getSelectionIndex()==2)
wMovetoDirectory.setEnabled(true);
else
wMovetoDirectory.setEnabled(false);
}
public void dispose()
{
WindowProperty winprop = new WindowProperty(shell);
props.setScreen(winprop);
shell.dispose();
}
/**
* Copy information from the meta-data input to the dialog fields.
*/
public void getData()
{
if (jobEntry.getName() != null) wName.setText( jobEntry.getName() );
wName.selectAll();
if (jobEntry.getZipFilename()!= null) wZipFilename.setText( jobEntry.getZipFilename() );
if (jobEntry.compressionrate>=0)
{
wCompressionRate.select(jobEntry.compressionrate );
}
else
{
wCompressionRate.select(1); // DEFAULT
}
if (jobEntry.ifzipfileexists>=0)
{
wIfFileExists.select(jobEntry.ifzipfileexists );
}
else
{
wIfFileExists.select(2); // NOTHING
}
if (jobEntry.getWildcard()!= null) wWildcard.setText( jobEntry.getWildcard() );
if (jobEntry.getWildcardExclude()!= null) wWildcardExclude.setText( jobEntry.getWildcardExclude() );
if (jobEntry.getTargetDirectory()!= null) wTargetDirectory.setText( jobEntry.getTargetDirectory() );
if (jobEntry.getMoveToDirectory()!= null) wMovetoDirectory.setText( jobEntry.getMoveToDirectory() );
if (jobEntry.afterzip>=0)
{
wAfterZip.select(jobEntry.afterzip );
}
else
{
wAfterZip.select(0 ); // NOTHING
}
}
private void cancel()
{
jobEntry.setChanged(changed);
jobEntry=null;
dispose();
}
private void ok()
{
jobEntry.setName(wName.getText());
jobEntry.setZipFilename(wZipFilename.getText());
jobEntry.compressionrate = wCompressionRate.getSelectionIndex();
jobEntry.ifzipfileexists = wIfFileExists.getSelectionIndex();
jobEntry.setWildcard(wWildcard.getText());
jobEntry.setWildcardExclude(wWildcardExclude.getText());
jobEntry.setTargetDirectory(wTargetDirectory.getText());
jobEntry.setMoveToDirectory(wMovetoDirectory.getText());
jobEntry.afterzip = wAfterZip.getSelectionIndex();
dispose();
}
public String toString()
{
return this.getClass().getName();
}
public boolean evaluates()
{
return true;
}
public boolean isUnconditional()
{
return false;
}
}