/
DeleteAllOperation.java
90 lines (78 loc) · 2.89 KB
/
DeleteAllOperation.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
// Import List - http://my-flow.github.io/importlist/
// Copyright (C) 2011-2015 Florian J. Breunig
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package com.moneydance.modules.features.importlist.io;
import com.moneydance.modules.features.importlist.util.Helper;
import com.moneydance.modules.features.importlist.util.Localizable;
import java.awt.Image;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
/**
* @author Florian J. Breunig
*/
final class DeleteAllOperation implements FileOperation {
/**
* Static initialization of class-dependent logger.
*/
private static final Logger LOG =
Logger.getLogger(DeleteAllOperation.class.getName());
private final Localizable localizable;
DeleteAllOperation() {
this.localizable = Helper.INSTANCE.getLocalizable();
}
@Override
public void showWarningAndExecute(final List<File> files) {
final String message =
this.localizable.getConfirmationMessageDeleteAllFiles(
files.size());
final Object confirmationLabel = new JLabel(message);
final Image image = Helper.INSTANCE.getSettings().getIconImage();
Icon icon = null;
if (image != null) {
icon = new ImageIcon(image);
}
final Object[] options = {
this.localizable.getOptionDeleteFile(),
this.localizable.getOptionCancel()
};
final int choice = JOptionPane.showOptionDialog(
null, // no parent component
confirmationLabel,
null, // no title
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE,
icon,
options,
options[1]);
if (choice == 0) {
this.execute(files);
} else {
LOG.info("Canceled deleting all files");
}
}
@Override
public void execute(final List<File> files) {
FileOperation deleteOneOperation = new DeleteOneOperation();
for (final File file : files) {
deleteOneOperation.execute(Collections.singletonList(file));
}
}
}