-
Notifications
You must be signed in to change notification settings - Fork 0
/
OkAction.java
65 lines (50 loc) · 2.14 KB
/
OkAction.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
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
public class OkAction extends AbstractAction{
@Override
public void actionPerformed(ActionEvent e) {
//TODO dialog with simple copy/move progress
if (destDirectoryCheck()) {
int size = FileListAction.fileList.size();
String labelText = "files: 1 " + "of " + size;
String fieldText = "Copy started at " + new Date() + "\n";
if (MainPanel.copyType == MainPanel.COPY) {
new ProgressDialog("Copy", labelText, fieldText);
} else {
}
}
}
/**
* Check directory path.
* If directory path not valid - create dialog window with error message.
* If directory not exist - show confirm dialog to create new folder.
*
* @return true - if directory created or false if path not valid or user press Cancel button
*/
private boolean destDirectoryCheck() {
boolean result = false;
try {
Path checkPath = Paths.get(MainPanel.destPath); //Throw InvalidPathException if path not valid
if (!Files.exists(checkPath)) { //If directory not exist - show dialog
int returnState = JOptionPane.showConfirmDialog(null, "Directory not exist\n " +
"Create new directory?", "Directory not exist",JOptionPane.OK_CANCEL_OPTION);
if (returnState == JOptionPane.OK_OPTION) { //Create directory if Ok button is pressed
File newDir = new File(MainPanel.destPath);
result = newDir.mkdir();
}
} else {
result = true;
}
} catch (InvalidPathException ipe) {
JOptionPane.showMessageDialog(null, "Invalid destination path!",
"Invalid path!", JOptionPane.ERROR_MESSAGE);
}
return result;
}
}