19
19
20
20
import java .util .ArrayList ;
21
21
import java .util .List ;
22
+ import org .apache .commons .vfs2 .FileObject ;
23
+ import org .apache .hop .core .exception .HopFileException ;
24
+ import org .apache .hop .core .logging .LogChannel ;
22
25
import org .apache .hop .core .util .Utils ;
23
26
import org .apache .hop .core .variables .IVariables ;
27
+ import org .apache .hop .core .vfs .HopVfs ;
24
28
import org .apache .hop .i18n .BaseMessages ;
25
29
import org .apache .hop .ui .core .PropsUi ;
26
30
import org .apache .hop .ui .core .dialog .BaseDialog ;
27
31
import org .apache .hop .ui .core .dialog .MessageBox ;
28
32
import org .apache .hop .ui .core .widget .ColumnInfo ;
29
33
import org .apache .hop .ui .core .widget .TableView ;
30
- import org .apache .hop .ui .core .widget .TextVar ;
31
34
import org .apache .hop .ui .pipeline .transform .BaseTransformDialog ;
32
35
import org .apache .hop .ui .workflow .action .ActionDialog ;
33
36
import org .apache .hop .ui .workflow .dialog .WorkflowDialog ;
@@ -54,15 +57,10 @@ public class ActionDeleteFilesDialog extends ActionDialog {
54
57
private static final Class <?> PKG = ActionDeleteFiles .class ;
55
58
56
59
private static final String [] FILETYPES =
57
- new String [] {BaseMessages .getString (PKG , "ActionDeleteFiles.Filetype.All " )};
60
+ new String [] {BaseMessages .getString (PKG , "System.FileType.AllFiles " )};
58
61
59
62
private Text wName ;
60
63
61
- private Label wlFilename ;
62
- private Button wbFilename ;
63
- private Button wbDirectory ;
64
- private TextVar wFilename ;
65
-
66
64
private Button wIncludeSubfolders ;
67
65
68
66
private ActionDeleteFiles action ;
@@ -74,13 +72,6 @@ public class ActionDeleteFilesDialog extends ActionDialog {
74
72
private Label wlFields ;
75
73
private TableView wFields ;
76
74
77
- private Label wlFilemask ;
78
- private TextVar wFilemask ;
79
-
80
- private Button wbdFilename ; // Delete
81
- private Button wbeFilename ; // Edit
82
- private Button wbaFilename ; // Add or change
83
-
84
75
public ActionDeleteFilesDialog (
85
76
Shell parent , ActionDeleteFiles action , WorkflowMeta workflowMeta , IVariables variables ) {
86
77
super (parent , workflowMeta , variables );
@@ -133,7 +124,7 @@ public IAction open() {
133
124
wlName .setLayoutData (fdlName );
134
125
wName = new Text (shell , SWT .SINGLE | SWT .LEFT | SWT .BORDER );
135
126
PropsUi .setLook (wName );
136
- wName .addModifyListener ( lsMod );
127
+ wName .addListener ( SWT . Modify , event -> action . setChanged () );
137
128
FormData fdName = new FormData ();
138
129
fdName .left = new FormAttachment (middle , 0 );
139
130
fdName .top = new FormAttachment (0 , margin );
@@ -172,13 +163,7 @@ public IAction open() {
172
163
fdIncludeSubfolders .top = new FormAttachment (wlIncludeSubfolders , 0 , SWT .CENTER );
173
164
fdIncludeSubfolders .right = new FormAttachment (100 , 0 );
174
165
wIncludeSubfolders .setLayoutData (fdIncludeSubfolders );
175
- wIncludeSubfolders .addSelectionListener (
176
- new SelectionAdapter () {
177
- @ Override
178
- public void widgetSelected (SelectionEvent e ) {
179
- action .setChanged ();
180
- }
181
- });
166
+ wIncludeSubfolders .addListener (SWT .Selection , event -> action .setChanged ());
182
167
183
168
Label wlPrevious = new Label (wSettings , SWT .RIGHT );
184
169
wlPrevious .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.Previous.Label" ));
@@ -197,13 +182,11 @@ public void widgetSelected(SelectionEvent e) {
197
182
fdPrevious .top = new FormAttachment (wlPrevious , 0 , SWT .CENTER );
198
183
fdPrevious .right = new FormAttachment (100 , 0 );
199
184
wPrevious .setLayoutData (fdPrevious );
200
- wPrevious .addSelectionListener (
201
- new SelectionAdapter () {
202
- @ Override
203
- public void widgetSelected (SelectionEvent e ) {
204
- setPrevious ();
205
- action .setChanged ();
206
- }
185
+ wPrevious .addListener (
186
+ SWT .Selection ,
187
+ event -> {
188
+ setPrevious ();
189
+ action .setChanged ();
207
190
});
208
191
FormData fdSettings = new FormData ();
209
192
fdSettings .left = new FormAttachment (0 , margin );
@@ -215,125 +198,22 @@ public void widgetSelected(SelectionEvent e) {
215
198
// / END OF SETTINGS GROUP
216
199
// ///////////////////////////////////////////////////////////
217
200
218
- // Filename line
219
- wlFilename = new Label (shell , SWT .RIGHT );
220
- wlFilename .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.Filename.Label" ));
221
- PropsUi .setLook (wlFilename );
222
- FormData fdlFilename = new FormData ();
223
- fdlFilename .left = new FormAttachment (0 , 0 );
224
- fdlFilename .top = new FormAttachment (wSettings , 2 * margin );
225
- fdlFilename .right = new FormAttachment (middle , -margin );
226
- wlFilename .setLayoutData (fdlFilename );
227
-
228
- // Browse Source folders button ...
229
- wbDirectory = new Button (shell , SWT .PUSH | SWT .CENTER );
230
- PropsUi .setLook (wbDirectory );
231
- wbDirectory .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.BrowseFolders.Label" ));
232
- FormData fdbDirectory = new FormData ();
233
- fdbDirectory .right = new FormAttachment (100 , -margin );
234
- fdbDirectory .top = new FormAttachment (wSettings , margin );
235
- wbDirectory .setLayoutData (fdbDirectory );
236
-
237
- wbDirectory .addListener (
238
- SWT .Selection , e -> BaseDialog .presentDirectoryDialog (shell , wFilename , variables ));
239
-
240
- wbFilename = new Button (shell , SWT .PUSH | SWT .CENTER );
241
- PropsUi .setLook (wbFilename );
242
- wbFilename .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.BrowseFiles.Label" ));
243
- FormData fdbFilename = new FormData ();
244
- fdbFilename .right = new FormAttachment (100 , 0 );
245
- fdbFilename .top = new FormAttachment (wSettings , margin );
246
- fdbFilename .right = new FormAttachment (wbDirectory , -margin );
247
- wbFilename .setLayoutData (fdbFilename );
248
-
249
- wbaFilename = new Button (shell , SWT .PUSH | SWT .CENTER );
250
- PropsUi .setLook (wbaFilename );
251
- wbaFilename .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.FilenameAdd.Button" ));
252
- FormData fdbaFilename = new FormData ();
253
- fdbaFilename .right = new FormAttachment (wbFilename , -margin );
254
- fdbaFilename .top = new FormAttachment (wSettings , margin );
255
- wbaFilename .setLayoutData (fdbaFilename );
256
-
257
- wFilename = new TextVar (variables , shell , SWT .SINGLE | SWT .LEFT | SWT .BORDER );
258
- PropsUi .setLook (wFilename );
259
- wFilename .addModifyListener (lsMod );
260
- FormData fdFilename = new FormData ();
261
- fdFilename .left = new FormAttachment (middle , 0 );
262
- fdFilename .top = new FormAttachment (wSettings , 2 * margin );
263
- fdFilename .right = new FormAttachment (wbaFilename , -margin );
264
- wFilename .setLayoutData (fdFilename );
265
-
266
- // Whenever something changes, set the tooltip to the expanded version:
267
- wFilename .addModifyListener (
268
- (ModifyEvent e ) -> wFilename .setToolTipText (variables .resolve (wFilename .getText ())));
269
-
270
- wbFilename .addListener (
271
- SWT .Selection ,
272
- e ->
273
- BaseDialog .presentFileDialog (
274
- shell , wFilename , variables , new String [] {"*" }, FILETYPES , false ));
275
-
276
- // Filemask
277
- wlFilemask = new Label (shell , SWT .RIGHT );
278
- wlFilemask .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.Wildcard.Label" ));
279
- PropsUi .setLook (wlFilemask );
280
- FormData fdlFilemask = new FormData ();
281
- fdlFilemask .left = new FormAttachment (0 , 0 );
282
- fdlFilemask .top = new FormAttachment (wFilename , margin );
283
- fdlFilemask .right = new FormAttachment (middle , -margin );
284
- wlFilemask .setLayoutData (fdlFilemask );
285
- wFilemask =
286
- new TextVar (
287
- variables ,
288
- shell ,
289
- SWT .SINGLE | SWT .LEFT | SWT .BORDER ,
290
- BaseMessages .getString (PKG , "ActionDeleteFiles.Wildcard.Tooltip" ));
291
- PropsUi .setLook (wFilemask );
292
- wFilemask .addModifyListener (lsMod );
293
- FormData fdFilemask = new FormData ();
294
- fdFilemask .left = new FormAttachment (middle , 0 );
295
- fdFilemask .top = new FormAttachment (wFilename , margin );
296
- fdFilemask .right = new FormAttachment (wbaFilename , -margin );
297
- wFilemask .setLayoutData (fdFilemask );
298
-
299
201
wlFields = new Label (shell , SWT .NONE );
300
202
wlFields .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.Fields.Label" ));
301
203
PropsUi .setLook (wlFields );
302
204
FormData fdlFields = new FormData ();
303
205
fdlFields .left = new FormAttachment (0 , 0 );
304
206
fdlFields .right = new FormAttachment (middle , -margin );
305
- fdlFields .top = new FormAttachment (wFilemask , margin );
207
+ fdlFields .top = new FormAttachment (wSettings , margin );
306
208
wlFields .setLayoutData (fdlFields );
307
209
308
- // Buttons to the right of the screen...
309
- wbdFilename = new Button (shell , SWT .PUSH | SWT .CENTER );
310
- PropsUi .setLook (wbdFilename );
311
- wbdFilename .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.FilenameDelete.Button" ));
312
- wbdFilename .setToolTipText (
313
- BaseMessages .getString (PKG , "ActionDeleteFiles.FilenameDelete.Tooltip" ));
314
- FormData fdbdFilename = new FormData ();
315
- fdbdFilename .right = new FormAttachment (100 , 0 );
316
- fdbdFilename .top = new FormAttachment (wlFields , margin );
317
- wbdFilename .setLayoutData (fdbdFilename );
318
-
319
- wbeFilename = new Button (shell , SWT .PUSH | SWT .CENTER );
320
- PropsUi .setLook (wbeFilename );
321
- wbeFilename .setText (BaseMessages .getString (PKG , "ActionDeleteFiles.FilenameEdit.Button" ));
322
- wbeFilename .setToolTipText (
323
- BaseMessages .getString (PKG , "ActionDeleteFiles.FilenameEdit.Tooltip" ));
324
- FormData fdbeFilename = new FormData ();
325
- fdbeFilename .right = new FormAttachment (100 , 0 );
326
- fdbeFilename .left = new FormAttachment (wbdFilename , 0 , SWT .LEFT );
327
- fdbeFilename .top = new FormAttachment (wbdFilename , margin );
328
- wbeFilename .setLayoutData (fdbeFilename );
329
-
330
210
final int nrRows = action .getFileItems ().size ();
331
211
332
212
ColumnInfo [] colinf =
333
213
new ColumnInfo [] {
334
214
new ColumnInfo (
335
215
BaseMessages .getString (PKG , "ActionDeleteFiles.Fields.Argument.Label" ),
336
- ColumnInfo .COLUMN_TYPE_TEXT ,
216
+ ColumnInfo .COLUMN_TYPE_TEXT_BUTTON ,
337
217
false ),
338
218
new ColumnInfo (
339
219
BaseMessages .getString (PKG , "ActionDeleteFiles.Fields.Wildcard.Label" ),
@@ -343,6 +223,7 @@ public void widgetSelected(SelectionEvent e) {
343
223
344
224
colinf [0 ].setUsingVariables (true );
345
225
colinf [0 ].setToolTip (BaseMessages .getString (PKG , "ActionDeleteFiles.Fields.Column" ));
226
+ colinf [0 ].setTextVarButtonSelectionListener (getFileSelectionAdapter ());
346
227
colinf [1 ].setUsingVariables (true );
347
228
colinf [1 ].setToolTip (BaseMessages .getString (PKG , "ActionDeleteFiles.Wildcard.Column" ));
348
229
@@ -359,58 +240,13 @@ public void widgetSelected(SelectionEvent e) {
359
240
FormData fdFields = new FormData ();
360
241
fdFields .left = new FormAttachment (0 , 0 );
361
242
fdFields .top = new FormAttachment (wlFields , margin );
362
- fdFields .right = new FormAttachment (wbdFilename , - margin );
243
+ fdFields .right = new FormAttachment (100 , 0 );
363
244
fdFields .bottom = new FormAttachment (wOk , -2 * margin );
364
245
wFields .setLayoutData (fdFields );
365
246
366
247
wlFields .setEnabled (!action .isArgFromPrevious ());
367
248
wFields .setEnabled (!action .isArgFromPrevious ());
368
249
369
- // Add the file to the list of files...
370
- SelectionAdapter selA =
371
- new SelectionAdapter () {
372
- @ Override
373
- public void widgetSelected (SelectionEvent arg0 ) {
374
- wFields .add (wFilename .getText (), wFilemask .getText ());
375
- wFilename .setText ("" );
376
- wFilemask .setText ("" );
377
- wFields .removeEmptyRows ();
378
- wFields .setRowNums ();
379
- wFields .optWidth (true );
380
- }
381
- };
382
- wbaFilename .addSelectionListener (selA );
383
- wFilename .addSelectionListener (selA );
384
-
385
- // Delete files from the list of files...
386
- wbdFilename .addSelectionListener (
387
- new SelectionAdapter () {
388
- @ Override
389
- public void widgetSelected (SelectionEvent arg0 ) {
390
- int [] idx = wFields .getSelectionIndices ();
391
- wFields .remove (idx );
392
- wFields .removeEmptyRows ();
393
- wFields .setRowNums ();
394
- }
395
- });
396
-
397
- // Edit the selected file & remove from the list...
398
- wbeFilename .addSelectionListener (
399
- new SelectionAdapter () {
400
- @ Override
401
- public void widgetSelected (SelectionEvent arg0 ) {
402
- int idx = wFields .getSelectionIndex ();
403
- if (idx >= 0 ) {
404
- String [] string = wFields .getItem (idx );
405
- wFilename .setText (string [0 ]);
406
- wFilemask .setText (string [1 ]);
407
- wFields .remove (idx );
408
- }
409
- wFields .removeEmptyRows ();
410
- wFields .setRowNums ();
411
- }
412
- });
413
-
414
250
getData ();
415
251
setPrevious ();
416
252
@@ -419,21 +255,30 @@ public void widgetSelected(SelectionEvent arg0) {
419
255
return action ;
420
256
}
421
257
258
+ protected SelectionAdapter getFileSelectionAdapter () {
259
+ return new SelectionAdapter () {
260
+ @ Override
261
+ public void widgetSelected (SelectionEvent event ) {
262
+ try {
263
+ String path = wFields .getActiveTableItem ().getText (wFields .getActiveTableColumn ());
264
+ FileObject fileObject = HopVfs .getFileObject (path );
265
+
266
+ path =
267
+ BaseDialog .presentFileDialog (
268
+ shell , null , variables , fileObject , new String [] {"*" }, FILETYPES , true );
269
+ if (path != null ) {
270
+ wFields .getActiveTableItem ().setText (wFields .getActiveTableColumn (), path );
271
+ }
272
+ } catch (HopFileException e ) {
273
+ LogChannel .UI .logError ("Error selecting file or directory" , e );
274
+ }
275
+ }
276
+ };
277
+ }
278
+
422
279
private void setPrevious () {
423
280
wlFields .setEnabled (!wPrevious .getSelection ());
424
281
wFields .setEnabled (!wPrevious .getSelection ());
425
-
426
- wFilename .setEnabled (!wPrevious .getSelection ());
427
- wlFilename .setEnabled (!wPrevious .getSelection ());
428
- wbFilename .setEnabled (!wPrevious .getSelection ());
429
-
430
- wlFilemask .setEnabled (!wPrevious .getSelection ());
431
- wFilemask .setEnabled (!wPrevious .getSelection ());
432
-
433
- wbdFilename .setEnabled (!wPrevious .getSelection ());
434
- wbeFilename .setEnabled (!wPrevious .getSelection ());
435
- wbaFilename .setEnabled (!wPrevious .getSelection ());
436
- wbDirectory .setEnabled (!wPrevious .getSelection ());
437
282
}
438
283
439
284
/** Copy information from the meta-data input to the dialog fields. */
0 commit comments