Search in sources :

Example 6 with FileCollisionDialog

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);
}
Also used : FileCollisionDialog(com.mucommander.ui.dialog.file.FileCollisionDialog) DialogAction(com.mucommander.ui.dialog.DialogAction) IOException(java.io.IOException)

Example 7 with FileCollisionDialog

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);
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileCollisionDialog(com.mucommander.ui.dialog.file.FileCollisionDialog) JFileChooser(javax.swing.JFileChooser) DialogAction(com.mucommander.ui.dialog.DialogAction) IOException(java.io.IOException)

Example 8 with FileCollisionDialog

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);
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileCollisionDialog(com.mucommander.ui.dialog.file.FileCollisionDialog) JFileChooser(javax.swing.JFileChooser) DialogAction(com.mucommander.ui.dialog.DialogAction) IOException(java.io.IOException)

Aggregations

FileCollisionDialog (com.mucommander.ui.dialog.file.FileCollisionDialog)8 DialogAction (com.mucommander.ui.dialog.DialogAction)7 IOException (java.io.IOException)6 AbstractFile (com.mucommander.commons.file.AbstractFile)4 JFileChooser (javax.swing.JFileChooser)3 RandomAccessOutputStream (com.mucommander.commons.io.RandomAccessOutputStream)1 FileCollisionRenameDialog (com.mucommander.ui.dialog.file.FileCollisionRenameDialog)1 OutputStream (java.io.OutputStream)1