use of com.mucommander.ui.dialog.file.FileCollisionDialog in project mucommander by mucommander.
the class CalculateChecksumJob method jobStarted.
// //////////////////////
// Overridden methods //
// //////////////////////
@Override
protected void jobStarted() {
super.jobStarted();
// Check for file collisions, i.e. if the file already exists in the destination
int collision = FileCollisionChecker.checkForCollision(null, checksumFile);
if (collision != FileCollisionChecker.NO_COLLISION) {
// File already exists in destination, ask the user what to do (cancel, overwrite,...) but
// do not offer the multiple files mode options such as 'skip' and 'apply to all'.
DialogAction choice = waitForUserResponse(new FileCollisionDialog(getProgressDialog(), getMainFrame(), collision, null, checksumFile, false, false));
// Overwrite file
if (choice == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Do nothing, simply continue and file will be overwritten
} else // 'Cancel' or close dialog interrupts the job
{
interrupt();
return;
}
}
// Loop for retry
do {
try {
// Tries to get an OutputStream on the destination file
this.checksumFileOut = checksumFile.getOutputStream();
break;
} catch (Exception e) {
DialogAction choice = showErrorDialog(Translator.get("error"), Translator.get("cannot_write_file", checksumFile.getName()), Arrays.asList(FileJobAction.CANCEL, FileJobAction.RETRY));
// Retry loops
if (choice == FileJobAction.RETRY)
continue;
// 'Cancel' or close dialog interrupts the job
interrupt();
return;
}
} while (true);
}
use of com.mucommander.ui.dialog.file.FileCollisionDialog in project mucommander by mucommander.
the class BinaryEditor method saveAsFile.
public void saveAsFile() {
JFileChooser fileChooser = new JFileChooser();
// Sets selected file in JFileChooser to current file
if (currentFile.getURL().getScheme().equals(LocalFile.SCHEMA)) {
fileChooser.setSelectedFile(new java.io.File(currentFile.getAbsolutePath()));
}
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
int ret = fileChooser.showSaveDialog(windowFrame);
if (ret == JFileChooser.APPROVE_OPTION) {
AbstractFile destFile;
try {
destFile = FileFactory.getFile(fileChooser.getSelectedFile().getAbsolutePath(), true);
} catch (IOException e) {
InformationDialog.showErrorDialog(windowFrame, Translator.get("write_error"), Translator.get("file_editor.cannot_write"));
return;
}
// Check for file collisions, i.e. if the file already exists in the destination
int collision = FileCollisionChecker.checkForCollision(null, destFile);
if (collision != FileCollisionChecker.NO_COLLISION) {
// File already exists in destination, ask the user what to do (cancel, overwrite,...) but
// do not offer the multiple file mode options such as 'skip' and 'apply to all'.
DialogAction action = new FileCollisionDialog(windowFrame, windowFrame, /* mainFrame */
collision, null, destFile, false, false).getActionValue();
if (action != FileCollisionDialog.FileCollisionAction.OVERWRITE) {
return;
}
}
trySave(destFile);
}
}
use of com.mucommander.ui.dialog.file.FileCollisionDialog in project mucommander by mucommander.
the class BasicFileEditor method trySaveAs.
private void trySaveAs() {
JFileChooser fileChooser = new JFileChooser();
AbstractFile currentFile = getCurrentFile();
// Sets selected file in JFileChooser to current file
if (currentFile.getURL().getScheme().equals(LocalFile.SCHEMA)) {
fileChooser.setSelectedFile(new java.io.File(currentFile.getAbsolutePath()));
}
fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
int ret = fileChooser.showSaveDialog(getFrame());
if (ret == JFileChooser.APPROVE_OPTION) {
AbstractFile destFile;
try {
destFile = FileFactory.getFile(fileChooser.getSelectedFile().getAbsolutePath(), true);
} catch (IOException e) {
InformationDialog.showErrorDialog(getFrame(), Translator.get("write_error"), Translator.get("file_editor.cannot_write"));
return;
}
// Check for file collisions, i.e. if the file already exists in the destination
int collision = FileCollisionChecker.checkForCollision(null, destFile);
if (collision != FileCollisionChecker.NO_COLLISION) {
// File already exists in destination, ask the user what to do (cancel, overwrite,...) but
// do not offer the multiple files mode options such as 'skip' and 'apply to all'.
DialogAction action = new FileCollisionDialog(getFrame(), getFrame(), /*mainFrame*/
collision, null, destFile, false, false).getActionValue();
// User chose to overwrite the file
if (action == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Do nothing, simply continue and file will be overwritten
} else // User chose to cancel or closed the dialog
{
return;
}
}
if (trySave(destFile)) {
setCurrentFile(destFile);
}
}
}
Aggregations