Skip to content

Commit 9da8fe7

Browse files
committed
Simplify the user interface for the “Delete files” action #5349
1 parent ef05f87 commit 9da8fe7

File tree

12 files changed

+39
-312
lines changed

12 files changed

+39
-312
lines changed

plugins/actions/deletefiles/src/main/java/org/apache/hop/workflow/actions/deletefiles/ActionDeleteFilesDialog.java

Lines changed: 37 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919

2020
import java.util.ArrayList;
2121
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;
2225
import org.apache.hop.core.util.Utils;
2326
import org.apache.hop.core.variables.IVariables;
27+
import org.apache.hop.core.vfs.HopVfs;
2428
import org.apache.hop.i18n.BaseMessages;
2529
import org.apache.hop.ui.core.PropsUi;
2630
import org.apache.hop.ui.core.dialog.BaseDialog;
2731
import org.apache.hop.ui.core.dialog.MessageBox;
2832
import org.apache.hop.ui.core.widget.ColumnInfo;
2933
import org.apache.hop.ui.core.widget.TableView;
30-
import org.apache.hop.ui.core.widget.TextVar;
3134
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
3235
import org.apache.hop.ui.workflow.action.ActionDialog;
3336
import org.apache.hop.ui.workflow.dialog.WorkflowDialog;
@@ -54,15 +57,10 @@ public class ActionDeleteFilesDialog extends ActionDialog {
5457
private static final Class<?> PKG = ActionDeleteFiles.class;
5558

5659
private static final String[] FILETYPES =
57-
new String[] {BaseMessages.getString(PKG, "ActionDeleteFiles.Filetype.All")};
60+
new String[] {BaseMessages.getString(PKG, "System.FileType.AllFiles")};
5861

5962
private Text wName;
6063

61-
private Label wlFilename;
62-
private Button wbFilename;
63-
private Button wbDirectory;
64-
private TextVar wFilename;
65-
6664
private Button wIncludeSubfolders;
6765

6866
private ActionDeleteFiles action;
@@ -74,13 +72,6 @@ public class ActionDeleteFilesDialog extends ActionDialog {
7472
private Label wlFields;
7573
private TableView wFields;
7674

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-
8475
public ActionDeleteFilesDialog(
8576
Shell parent, ActionDeleteFiles action, WorkflowMeta workflowMeta, IVariables variables) {
8677
super(parent, workflowMeta, variables);
@@ -133,7 +124,7 @@ public IAction open() {
133124
wlName.setLayoutData(fdlName);
134125
wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
135126
PropsUi.setLook(wName);
136-
wName.addModifyListener(lsMod);
127+
wName.addListener(SWT.Modify, event -> action.setChanged());
137128
FormData fdName = new FormData();
138129
fdName.left = new FormAttachment(middle, 0);
139130
fdName.top = new FormAttachment(0, margin);
@@ -172,13 +163,7 @@ public IAction open() {
172163
fdIncludeSubfolders.top = new FormAttachment(wlIncludeSubfolders, 0, SWT.CENTER);
173164
fdIncludeSubfolders.right = new FormAttachment(100, 0);
174165
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());
182167

183168
Label wlPrevious = new Label(wSettings, SWT.RIGHT);
184169
wlPrevious.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Previous.Label"));
@@ -197,13 +182,11 @@ public void widgetSelected(SelectionEvent e) {
197182
fdPrevious.top = new FormAttachment(wlPrevious, 0, SWT.CENTER);
198183
fdPrevious.right = new FormAttachment(100, 0);
199184
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();
207190
});
208191
FormData fdSettings = new FormData();
209192
fdSettings.left = new FormAttachment(0, margin);
@@ -215,125 +198,22 @@ public void widgetSelected(SelectionEvent e) {
215198
// / END OF SETTINGS GROUP
216199
// ///////////////////////////////////////////////////////////
217200

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-
299201
wlFields = new Label(shell, SWT.NONE);
300202
wlFields.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Label"));
301203
PropsUi.setLook(wlFields);
302204
FormData fdlFields = new FormData();
303205
fdlFields.left = new FormAttachment(0, 0);
304206
fdlFields.right = new FormAttachment(middle, -margin);
305-
fdlFields.top = new FormAttachment(wFilemask, margin);
207+
fdlFields.top = new FormAttachment(wSettings, margin);
306208
wlFields.setLayoutData(fdlFields);
307209

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-
330210
final int nrRows = action.getFileItems().size();
331211

332212
ColumnInfo[] colinf =
333213
new ColumnInfo[] {
334214
new ColumnInfo(
335215
BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Argument.Label"),
336-
ColumnInfo.COLUMN_TYPE_TEXT,
216+
ColumnInfo.COLUMN_TYPE_TEXT_BUTTON,
337217
false),
338218
new ColumnInfo(
339219
BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Wildcard.Label"),
@@ -343,6 +223,7 @@ public void widgetSelected(SelectionEvent e) {
343223

344224
colinf[0].setUsingVariables(true);
345225
colinf[0].setToolTip(BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Column"));
226+
colinf[0].setTextVarButtonSelectionListener(getFileSelectionAdapter());
346227
colinf[1].setUsingVariables(true);
347228
colinf[1].setToolTip(BaseMessages.getString(PKG, "ActionDeleteFiles.Wildcard.Column"));
348229

@@ -359,58 +240,13 @@ public void widgetSelected(SelectionEvent e) {
359240
FormData fdFields = new FormData();
360241
fdFields.left = new FormAttachment(0, 0);
361242
fdFields.top = new FormAttachment(wlFields, margin);
362-
fdFields.right = new FormAttachment(wbdFilename, -margin);
243+
fdFields.right = new FormAttachment(100, 0);
363244
fdFields.bottom = new FormAttachment(wOk, -2 * margin);
364245
wFields.setLayoutData(fdFields);
365246

366247
wlFields.setEnabled(!action.isArgFromPrevious());
367248
wFields.setEnabled(!action.isArgFromPrevious());
368249

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-
414250
getData();
415251
setPrevious();
416252

@@ -419,21 +255,30 @@ public void widgetSelected(SelectionEvent arg0) {
419255
return action;
420256
}
421257

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+
422279
private void setPrevious() {
423280
wlFields.setEnabled(!wPrevious.getSelection());
424281
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());
437282
}
438283

439284
/** Copy information from the meta-data input to the dialog fields. */

plugins/actions/deletefiles/src/main/resources/org/apache/hop/workflow/actions/deletefiles/messages/messages_de_DE.properties

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#
1818
#
1919

20-
ActionDeleteFiles.BrowseFiles.Label=Datei ...
21-
ActionDeleteFiles.BrowseFolders.Label=Ordner...
2220
ActionDeleteFiles.CouldNotDeleteFile=Konnte Datei nicht l\u00F6schen [{0}].
2321
ActionDeleteFiles.CouldNotProcess=Konnte [{0}] nicht verarbeiten, Ausnahme : {1}
2422
ActionDeleteFiles.DeletingFile=L\u00F6sche Date [{0}] ...
@@ -31,13 +29,6 @@ ActionDeleteFiles.Fields.Label=Datei(en)/Ordner:
3129
ActionDeleteFiles.Fields.Wildcard.Label=Platzhalter (RegExp)
3230
ActionDeleteFiles.FileAlreadyDeleted=Datei [{0}] schon gel\u00F6scht oder existiert nicht.
3331
ActionDeleteFiles.FileDeleted=Datei [{0}] gel\u00F6scht!
34-
ActionDeleteFiles.Filename.Label=Datei/Ordner
35-
ActionDeleteFiles.FilenameAdd.Button=Hinzuf\u00FCgen
36-
ActionDeleteFiles.FilenameDelete.Button=L\u00F6schen
37-
ActionDeleteFiles.FilenameDelete.Tooltip=L\u00F6sche ausgew\u00E4hlte Datei aus \u00DCbersicht
38-
ActionDeleteFiles.FilenameEdit.Button=Bearbeiten
39-
ActionDeleteFiles.FilenameEdit.Tooltip=Dateiauswahl bearbeiten
40-
ActionDeleteFiles.Filetype.All=Alle Dateien
4132
ActionDeleteFiles.FoundPreviousRows={0} Zeilen aus Vorg\u00E4nger gefunden
4233
ActionDeleteFiles.IncludeSubfolders.Label=Unterordner ber\u00FCcksichtigen
4334
ActionDeleteFiles.IncludeSubfolders.Tooltip=Unterordner ber\u00FCcksichtigen
@@ -56,5 +47,3 @@ ActionDeleteFiles.Settings.Label=Einstellungen
5647
ActionDeleteFiles.Title=Datei(en) l\u00F6schen
5748
ActionDeleteFiles.TotalDeleted=Anzahl gel\u00F6schter Dateien = {0}
5849
ActionDeleteFiles.Wildcard.Column=Platzhalter (RegExp) angeben
59-
ActionDeleteFiles.Wildcard.Label=Platzhalter (RegExp)
60-
ActionDeleteFiles.Wildcard.Tooltip=Platzhalter (RegExp)

plugins/actions/deletefiles/src/main/resources/org/apache/hop/workflow/actions/deletefiles/messages/messages_en_US.properties

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# limitations under the License.
1616
#
1717

18-
ActionDeleteFiles.BrowseFiles.Label=File...
19-
ActionDeleteFiles.BrowseFolders.Label=Folder...
2018
ActionDeleteFiles.CouldNotDeleteFile=Could not delete file [{0}].
2119
ActionDeleteFiles.CouldNotProcess=Could not process [{0}], exception\: {1}
2220
ActionDeleteFiles.DeletingFile=Deleting file [{0}] ...
@@ -29,13 +27,6 @@ ActionDeleteFiles.Fields.Label=Files/Folders\:
2927
ActionDeleteFiles.Fields.Wildcard.Label=Wildcard (RegExp)
3028
ActionDeleteFiles.FileAlreadyDeleted=File [{0}] already deleted or did not exist.
3129
ActionDeleteFiles.FileDeleted=File [{0}] deleted\!
32-
ActionDeleteFiles.Filename.Label=File/Folder
33-
ActionDeleteFiles.FilenameAdd.Button=&Add
34-
ActionDeleteFiles.FilenameDelete.Button=&Delete
35-
ActionDeleteFiles.FilenameDelete.Tooltip=Remove selected files from the grid
36-
ActionDeleteFiles.FilenameEdit.Button=&Edit
37-
ActionDeleteFiles.FilenameEdit.Tooltip=Edit selected files
38-
ActionDeleteFiles.Filetype.All=All files
3930
ActionDeleteFiles.FoundPreviousRows=Found {0} previous result rows
4031
ActionDeleteFiles.IncludeSubfolders.Label=Include Subfolders
4132
ActionDeleteFiles.IncludeSubfolders.Tooltip=Include Subfolders
@@ -54,5 +45,3 @@ ActionDeleteFiles.Settings.Label=Settings
5445
ActionDeleteFiles.Title=Delete files
5546
ActionDeleteFiles.TotalDeleted=Total deleted files \= {0}
5647
ActionDeleteFiles.Wildcard.Column=Specify a wildcard (RegExp)
57-
ActionDeleteFiles.Wildcard.Label=Wildcard (RegExp)
58-
ActionDeleteFiles.Wildcard.Tooltip=Wildcard (RegExp)

0 commit comments

Comments
 (0)