* dialogs to ask about overwrite and to report errors.
*/
class FileActions {
static void deleteFiles(File[] files, Component parent) {
AlertDialog alert = Platform.getPlatform().getAlertDialog();
Frame frame = (Frame) SwingUtilities.getAncestorOfClass(
Frame.class, parent
);
StringBuilder info = new StringBuilder();
String message;
if (files.length > 1) {
message = LOCALE.get("DeleteQuestionPlural", Integer.toString(files.length));
}
else {
message = LOCALE.get("DeleteQuestionSingular", files[0].getName());
}
String okButton = LOCALE.get("DeleteButton");
String cancelButton = LOCALE.get("CancelButton");
int option = alert.showAlert(
frame, message, info.toString(),
AlertDialog.WARNING_ALERT,
okButton, cancelButton
);
if (option == 0) {
Platform platform = Platform.getPlatform();
for (File file : files) {
String path = file.getAbsolutePath();
boolean deleted;
try {
ImageInfo.closeAll();
deleted = platform.moveFilesToTrash(new String[] { path });
}
catch (IOException e) {
deleted = false;
}
if (! deleted) {
String error =
LOCALE.get("DeleteFailed", file.getName());
option = alert.showAlert(
frame, error, "", AlertDialog.ERROR_ALERT,
LOCALE.get( "ContinueButton" ),
LOCALE.get( "CancelButton" )
);
if (option > 0) {