Skip to content

Simplify the user interface for the “Delete files” action #5349 #5350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ The `Delete files` action deletes a set of specified files, optionally with subf
For example to delete all files ending in .dat, the regular expression would be ".*\.dat$".
|Files/Folders|The complete list of files/folders to delete
|===

After specifying a folder and wildcard (regular expression), use the `Add` button to add your file/folder selection to the table. Use the `Delete` or `Edit` buttons to remove or edit selected lines in the table.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.vfs2.FileObject;
import org.apache.hop.core.exception.HopFileException;
import org.apache.hop.core.logging.LogChannel;
import org.apache.hop.core.util.Utils;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.ui.core.PropsUi;
import org.apache.hop.ui.core.dialog.BaseDialog;
import org.apache.hop.ui.core.dialog.MessageBox;
import org.apache.hop.ui.core.widget.ColumnInfo;
import org.apache.hop.ui.core.widget.TableView;
import org.apache.hop.ui.core.widget.TextVar;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
import org.apache.hop.ui.workflow.action.ActionDialog;
import org.apache.hop.ui.workflow.dialog.WorkflowDialog;
Expand All @@ -54,15 +57,10 @@ public class ActionDeleteFilesDialog extends ActionDialog {
private static final Class<?> PKG = ActionDeleteFiles.class;

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

private Text wName;

private Label wlFilename;
private Button wbFilename;
private Button wbDirectory;
private TextVar wFilename;

private Button wIncludeSubfolders;

private ActionDeleteFiles action;
Expand All @@ -74,13 +72,6 @@ public class ActionDeleteFilesDialog extends ActionDialog {
private Label wlFields;
private TableView wFields;

private Label wlFilemask;
private TextVar wFilemask;

private Button wbdFilename; // Delete
private Button wbeFilename; // Edit
private Button wbaFilename; // Add or change

public ActionDeleteFilesDialog(
Shell parent, ActionDeleteFiles action, WorkflowMeta workflowMeta, IVariables variables) {
super(parent, workflowMeta, variables);
Expand Down Expand Up @@ -133,7 +124,7 @@ public IAction open() {
wlName.setLayoutData(fdlName);
wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
PropsUi.setLook(wName);
wName.addModifyListener(lsMod);
wName.addListener(SWT.Modify, event -> action.setChanged());
FormData fdName = new FormData();
fdName.left = new FormAttachment(middle, 0);
fdName.top = new FormAttachment(0, margin);
Expand Down Expand Up @@ -172,13 +163,7 @@ public IAction open() {
fdIncludeSubfolders.top = new FormAttachment(wlIncludeSubfolders, 0, SWT.CENTER);
fdIncludeSubfolders.right = new FormAttachment(100, 0);
wIncludeSubfolders.setLayoutData(fdIncludeSubfolders);
wIncludeSubfolders.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
action.setChanged();
}
});
wIncludeSubfolders.addListener(SWT.Selection, event -> action.setChanged());

Label wlPrevious = new Label(wSettings, SWT.RIGHT);
wlPrevious.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Previous.Label"));
Expand All @@ -197,13 +182,11 @@ public void widgetSelected(SelectionEvent e) {
fdPrevious.top = new FormAttachment(wlPrevious, 0, SWT.CENTER);
fdPrevious.right = new FormAttachment(100, 0);
wPrevious.setLayoutData(fdPrevious);
wPrevious.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setPrevious();
action.setChanged();
}
wPrevious.addListener(
SWT.Selection,
event -> {
setPrevious();
action.setChanged();
});
FormData fdSettings = new FormData();
fdSettings.left = new FormAttachment(0, margin);
Expand All @@ -215,125 +198,22 @@ public void widgetSelected(SelectionEvent e) {
// / END OF SETTINGS GROUP
// ///////////////////////////////////////////////////////////

// Filename line
wlFilename = new Label(shell, SWT.RIGHT);
wlFilename.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Filename.Label"));
PropsUi.setLook(wlFilename);
FormData fdlFilename = new FormData();
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.top = new FormAttachment(wSettings, 2 * margin);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);

// Browse Source folders button ...
wbDirectory = new Button(shell, SWT.PUSH | SWT.CENTER);
PropsUi.setLook(wbDirectory);
wbDirectory.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.BrowseFolders.Label"));
FormData fdbDirectory = new FormData();
fdbDirectory.right = new FormAttachment(100, -margin);
fdbDirectory.top = new FormAttachment(wSettings, margin);
wbDirectory.setLayoutData(fdbDirectory);

wbDirectory.addListener(
SWT.Selection, e -> BaseDialog.presentDirectoryDialog(shell, wFilename, variables));

wbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
PropsUi.setLook(wbFilename);
wbFilename.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.BrowseFiles.Label"));
FormData fdbFilename = new FormData();
fdbFilename.right = new FormAttachment(100, 0);
fdbFilename.top = new FormAttachment(wSettings, margin);
fdbFilename.right = new FormAttachment(wbDirectory, -margin);
wbFilename.setLayoutData(fdbFilename);

wbaFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
PropsUi.setLook(wbaFilename);
wbaFilename.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.FilenameAdd.Button"));
FormData fdbaFilename = new FormData();
fdbaFilename.right = new FormAttachment(wbFilename, -margin);
fdbaFilename.top = new FormAttachment(wSettings, margin);
wbaFilename.setLayoutData(fdbaFilename);

wFilename = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
PropsUi.setLook(wFilename);
wFilename.addModifyListener(lsMod);
FormData fdFilename = new FormData();
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.top = new FormAttachment(wSettings, 2 * margin);
fdFilename.right = new FormAttachment(wbaFilename, -margin);
wFilename.setLayoutData(fdFilename);

// Whenever something changes, set the tooltip to the expanded version:
wFilename.addModifyListener(
(ModifyEvent e) -> wFilename.setToolTipText(variables.resolve(wFilename.getText())));

wbFilename.addListener(
SWT.Selection,
e ->
BaseDialog.presentFileDialog(
shell, wFilename, variables, new String[] {"*"}, FILETYPES, false));

// Filemask
wlFilemask = new Label(shell, SWT.RIGHT);
wlFilemask.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Wildcard.Label"));
PropsUi.setLook(wlFilemask);
FormData fdlFilemask = new FormData();
fdlFilemask.left = new FormAttachment(0, 0);
fdlFilemask.top = new FormAttachment(wFilename, margin);
fdlFilemask.right = new FormAttachment(middle, -margin);
wlFilemask.setLayoutData(fdlFilemask);
wFilemask =
new TextVar(
variables,
shell,
SWT.SINGLE | SWT.LEFT | SWT.BORDER,
BaseMessages.getString(PKG, "ActionDeleteFiles.Wildcard.Tooltip"));
PropsUi.setLook(wFilemask);
wFilemask.addModifyListener(lsMod);
FormData fdFilemask = new FormData();
fdFilemask.left = new FormAttachment(middle, 0);
fdFilemask.top = new FormAttachment(wFilename, margin);
fdFilemask.right = new FormAttachment(wbaFilename, -margin);
wFilemask.setLayoutData(fdFilemask);

wlFields = new Label(shell, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Label"));
PropsUi.setLook(wlFields);
FormData fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.right = new FormAttachment(middle, -margin);
fdlFields.top = new FormAttachment(wFilemask, margin);
fdlFields.top = new FormAttachment(wSettings, margin);
wlFields.setLayoutData(fdlFields);

// Buttons to the right of the screen...
wbdFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
PropsUi.setLook(wbdFilename);
wbdFilename.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.FilenameDelete.Button"));
wbdFilename.setToolTipText(
BaseMessages.getString(PKG, "ActionDeleteFiles.FilenameDelete.Tooltip"));
FormData fdbdFilename = new FormData();
fdbdFilename.right = new FormAttachment(100, 0);
fdbdFilename.top = new FormAttachment(wlFields, margin);
wbdFilename.setLayoutData(fdbdFilename);

wbeFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
PropsUi.setLook(wbeFilename);
wbeFilename.setText(BaseMessages.getString(PKG, "ActionDeleteFiles.FilenameEdit.Button"));
wbeFilename.setToolTipText(
BaseMessages.getString(PKG, "ActionDeleteFiles.FilenameEdit.Tooltip"));
FormData fdbeFilename = new FormData();
fdbeFilename.right = new FormAttachment(100, 0);
fdbeFilename.left = new FormAttachment(wbdFilename, 0, SWT.LEFT);
fdbeFilename.top = new FormAttachment(wbdFilename, margin);
wbeFilename.setLayoutData(fdbeFilename);

final int nrRows = action.getFileItems().size();

ColumnInfo[] colinf =
new ColumnInfo[] {
new ColumnInfo(
BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Argument.Label"),
ColumnInfo.COLUMN_TYPE_TEXT,
ColumnInfo.COLUMN_TYPE_TEXT_BUTTON,
false),
new ColumnInfo(
BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Wildcard.Label"),
Expand All @@ -343,6 +223,7 @@ public void widgetSelected(SelectionEvent e) {

colinf[0].setUsingVariables(true);
colinf[0].setToolTip(BaseMessages.getString(PKG, "ActionDeleteFiles.Fields.Column"));
colinf[0].setTextVarButtonSelectionListener(getFileSelectionAdapter());
colinf[1].setUsingVariables(true);
colinf[1].setToolTip(BaseMessages.getString(PKG, "ActionDeleteFiles.Wildcard.Column"));

Expand All @@ -359,58 +240,13 @@ public void widgetSelected(SelectionEvent e) {
FormData fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(wbdFilename, -margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(wOk, -2 * margin);
wFields.setLayoutData(fdFields);

wlFields.setEnabled(!action.isArgFromPrevious());
wFields.setEnabled(!action.isArgFromPrevious());

// Add the file to the list of files...
SelectionAdapter selA =
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
wFields.add(wFilename.getText(), wFilemask.getText());
wFilename.setText("");
wFilemask.setText("");
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
}
};
wbaFilename.addSelectionListener(selA);
wFilename.addSelectionListener(selA);

// Delete files from the list of files...
wbdFilename.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
int[] idx = wFields.getSelectionIndices();
wFields.remove(idx);
wFields.removeEmptyRows();
wFields.setRowNums();
}
});

// Edit the selected file & remove from the list...
wbeFilename.addSelectionListener(
new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
int idx = wFields.getSelectionIndex();
if (idx >= 0) {
String[] string = wFields.getItem(idx);
wFilename.setText(string[0]);
wFilemask.setText(string[1]);
wFields.remove(idx);
}
wFields.removeEmptyRows();
wFields.setRowNums();
}
});

getData();
setPrevious();

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

protected SelectionAdapter getFileSelectionAdapter() {
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
try {
String path = wFields.getActiveTableItem().getText(wFields.getActiveTableColumn());
FileObject fileObject = HopVfs.getFileObject(path);

path =
BaseDialog.presentFileDialog(
shell, null, variables, fileObject, new String[] {"*"}, FILETYPES, true);
if (path != null) {
wFields.getActiveTableItem().setText(wFields.getActiveTableColumn(), path);
}
} catch (HopFileException e) {
LogChannel.UI.logError("Error selecting file or directory", e);
}
}
};
}

private void setPrevious() {
wlFields.setEnabled(!wPrevious.getSelection());
wFields.setEnabled(!wPrevious.getSelection());

wFilename.setEnabled(!wPrevious.getSelection());
wlFilename.setEnabled(!wPrevious.getSelection());
wbFilename.setEnabled(!wPrevious.getSelection());

wlFilemask.setEnabled(!wPrevious.getSelection());
wFilemask.setEnabled(!wPrevious.getSelection());

wbdFilename.setEnabled(!wPrevious.getSelection());
wbeFilename.setEnabled(!wPrevious.getSelection());
wbaFilename.setEnabled(!wPrevious.getSelection());
wbDirectory.setEnabled(!wPrevious.getSelection());
}

/** Copy information from the meta-data input to the dialog fields. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#
#

ActionDeleteFiles.BrowseFiles.Label=Datei ...
ActionDeleteFiles.BrowseFolders.Label=Ordner...
ActionDeleteFiles.CouldNotDeleteFile=Konnte Datei nicht l\u00F6schen [{0}].
ActionDeleteFiles.CouldNotProcess=Konnte [{0}] nicht verarbeiten, Ausnahme : {1}
ActionDeleteFiles.DeletingFile=L\u00F6sche Date [{0}] ...
Expand All @@ -31,13 +29,6 @@ ActionDeleteFiles.Fields.Label=Datei(en)/Ordner:
ActionDeleteFiles.Fields.Wildcard.Label=Platzhalter (RegExp)
ActionDeleteFiles.FileAlreadyDeleted=Datei [{0}] schon gel\u00F6scht oder existiert nicht.
ActionDeleteFiles.FileDeleted=Datei [{0}] gel\u00F6scht!
ActionDeleteFiles.Filename.Label=Datei/Ordner
ActionDeleteFiles.FilenameAdd.Button=Hinzuf\u00FCgen
ActionDeleteFiles.FilenameDelete.Button=L\u00F6schen
ActionDeleteFiles.FilenameDelete.Tooltip=L\u00F6sche ausgew\u00E4hlte Datei aus \u00DCbersicht
ActionDeleteFiles.FilenameEdit.Button=Bearbeiten
ActionDeleteFiles.FilenameEdit.Tooltip=Dateiauswahl bearbeiten
ActionDeleteFiles.Filetype.All=Alle Dateien
ActionDeleteFiles.FoundPreviousRows={0} Zeilen aus Vorg\u00E4nger gefunden
ActionDeleteFiles.IncludeSubfolders.Label=Unterordner ber\u00FCcksichtigen
ActionDeleteFiles.IncludeSubfolders.Tooltip=Unterordner ber\u00FCcksichtigen
Expand All @@ -56,5 +47,3 @@ ActionDeleteFiles.Settings.Label=Einstellungen
ActionDeleteFiles.Title=Datei(en) l\u00F6schen
ActionDeleteFiles.TotalDeleted=Anzahl gel\u00F6schter Dateien = {0}
ActionDeleteFiles.Wildcard.Column=Platzhalter (RegExp) angeben
ActionDeleteFiles.Wildcard.Label=Platzhalter (RegExp)
ActionDeleteFiles.Wildcard.Tooltip=Platzhalter (RegExp)
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# limitations under the License.
#

ActionDeleteFiles.BrowseFiles.Label=File...
ActionDeleteFiles.BrowseFolders.Label=Folder...
ActionDeleteFiles.CouldNotDeleteFile=Could not delete file [{0}].
ActionDeleteFiles.CouldNotProcess=Could not process [{0}], exception\: {1}
ActionDeleteFiles.DeletingFile=Deleting file [{0}] ...
Expand All @@ -29,13 +27,6 @@ ActionDeleteFiles.Fields.Label=Files/Folders\:
ActionDeleteFiles.Fields.Wildcard.Label=Wildcard (RegExp)
ActionDeleteFiles.FileAlreadyDeleted=File [{0}] already deleted or did not exist.
ActionDeleteFiles.FileDeleted=File [{0}] deleted\!
ActionDeleteFiles.Filename.Label=File/Folder
ActionDeleteFiles.FilenameAdd.Button=&Add
ActionDeleteFiles.FilenameDelete.Button=&Delete
ActionDeleteFiles.FilenameDelete.Tooltip=Remove selected files from the grid
ActionDeleteFiles.FilenameEdit.Button=&Edit
ActionDeleteFiles.FilenameEdit.Tooltip=Edit selected files
ActionDeleteFiles.Filetype.All=All files
ActionDeleteFiles.FoundPreviousRows=Found {0} previous result rows
ActionDeleteFiles.IncludeSubfolders.Label=Include Subfolders
ActionDeleteFiles.IncludeSubfolders.Tooltip=Include Subfolders
Expand All @@ -54,5 +45,3 @@ ActionDeleteFiles.Settings.Label=Settings
ActionDeleteFiles.Title=Delete files
ActionDeleteFiles.TotalDeleted=Total deleted files \= {0}
ActionDeleteFiles.Wildcard.Column=Specify a wildcard (RegExp)
ActionDeleteFiles.Wildcard.Label=Wildcard (RegExp)
ActionDeleteFiles.Wildcard.Tooltip=Wildcard (RegExp)
Loading
Loading