use of com.mucommander.ui.dialog.file.FileCollisionRenameDialog in project mucommander by mucommander.
the class AbstractCopyJob method checkForCollision.
/**
* Checks if there is a file collision (file exists in the destination).
* If there is no collision this method returns destFile.
* If there is a collision this method returns: <ul>
* <li>null if a user cancelled the transfer
* <li>null if a user skipped the file
* <li>destFile if a user resumed the transfer (and sets append flag)
* <li>destFile if a user has chosen to overwrite the file
* <li>new file if a user renamed the file
* </ul>
* @param file a source file
* @param destFolder a destination folder
* @param destFile a destination file
* @param allowCaseVariation if true,
* @return destFile the new destination file
*/
protected AbstractFile checkForCollision(AbstractFile file, AbstractFile destFolder, AbstractFile destFile, boolean allowCaseVariation) {
append = false;
while (true) {
// Check for file collisions (file exists in the destination, destination subfolder of source, ...)
// if a default action hasn't been specified
int collision = FileCollisionChecker.checkForCollision(file, destFile);
// destination being the same.
if (allowCaseVariation && collision == FileCollisionChecker.SAME_SOURCE_AND_DESTINATION) {
String sourceFileName = file.getName();
String destFileName = destFile.getName();
if (sourceFileName.equalsIgnoreCase(destFileName) && !sourceFileName.equals(destFileName)) {
break;
}
}
// Handle collision, asking the user what to do or using a default action to resolve the collision
if (collision != FileCollisionChecker.NO_COLLISION) {
FileCollisionDialog.FileCollisionAction choice;
// Use default action if one has been set, if not show up a dialog
if (defaultFileExistsAction == FileCollisionDialog.FileCollisionAction.ASK) {
FileCollisionDialog dialog = new FileCollisionDialog(getProgressDialog(), getMainFrame(), collision, file, destFile, true, true);
choice = (FileCollisionDialog.FileCollisionAction) waitForUserResponse(dialog);
// If 'apply to all' was selected, this choice will be used for any other files (user will not be asked again)
if (dialog.applyToAllSelected()) {
defaultFileExistsAction = choice;
}
} else {
choice = defaultFileExistsAction;
}
// Cancel, skip or close dialog
if (choice == QuestionDialog.DIALOG_DISPOSED_ACTION || choice == FileCollisionDialog.FileCollisionAction.CANCEL) {
interrupt();
return null;
} else // Skip file
if (choice == FileCollisionDialog.FileCollisionAction.SKIP) {
return null;
} else // Append to file (resume file copy)
if (choice == FileCollisionDialog.FileCollisionAction.RESUME) {
append = true;
break;
} else // Overwrite file
if (choice == FileCollisionDialog.FileCollisionAction.OVERWRITE) {
// Do nothing, simply continue
break;
} else // Overwrite file if destination is older
if (choice == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_OLDER) {
// Overwrite if file is newer (strictly)
if (file.getDate() <= destFile.getDate()) {
return null;
}
break;
} else if (choice == FileCollisionDialog.FileCollisionAction.OVERWRITE_IF_SIZE_DIFFERS) {
if (file.getSize() == destFile.getSize()) {
return null;
}
break;
} else if (choice == FileCollisionDialog.FileCollisionAction.RENAME) {
setPaused(true);
FileCollisionRenameDialog dlg = new FileCollisionRenameDialog(getMainFrame(), destFile);
String destFileName = (String) waitForUserResponseObject(dlg);
setPaused(false);
if (destFileName != null) {
destFile = createDestinationFile(file, destFolder, destFileName);
} else {
// turn on FileCollisionDialog, so we don't loop indefinitely
defaultFileExistsAction = FileCollisionDialog.FileCollisionAction.ASK;
}
// continue with collision checking
continue;
}
}
// no collision
break;
}
return destFile;
}
Aggregations