Search in sources :

Example 11 with FileSet

use of com.mucommander.commons.file.util.FileSet in project mucommander by mucommander.

the class EmailFilesDialog method getFlattenedFiles.

/**
 * Returns a FileSet of *files* (as opposed to folders) that have been found either in the given
 * FileSet or in one of the subfolders.
 *
 * @param originalFiles files as selected by the user which may contain folders
 */
private FileSet getFlattenedFiles(FileSet originalFiles) throws IOException {
    int nbFiles = originalFiles.size();
    FileSet flattenedFiles = new FileSet(originalFiles.getBaseFolder());
    for (int i = 0; i < nbFiles; i++) recurseOnFolder(originalFiles.elementAt(i), flattenedFiles);
    return flattenedFiles;
}
Also used : FileSet(com.mucommander.commons.file.util.FileSet)

Example 12 with FileSet

use of com.mucommander.commons.file.util.FileSet in project mucommander by mucommander.

the class MkdirDialog method startJob.

/**
 * Starts an {@link com.mucommander.job.impl.MkdirJob}. This method is trigged by the 'OK' button or the return key.
 */
public void startJob() {
    String enteredPath = pathField.getText();
    AbstractFile currentFolder = mainFrame.getActivePanel().getCurrentFolder();
    // Resolves destination folder
    PathUtils.ResolvedDestination resolvedDest = PathUtils.resolveDestination(enteredPath, currentFolder, currentFolder);
    // The path entered doesn't correspond to any existing folder
    if (resolvedDest == null) {
        InformationDialog.showErrorDialog(mainFrame, Translator.get("invalid_path", enteredPath));
        return;
    }
    // Checks if the directory already exists and reports the error if that's the case
    DestinationType destinationType = resolvedDest.getDestinationType();
    if (destinationType == DestinationType.EXISTING_FOLDER) {
        InformationDialog.showErrorDialog(mainFrame, Translator.get("directory_already_exists", enteredPath));
        return;
    }
    // Don't check for existing regular files, MkdirJob will take of it and popup a FileCollisionDialog
    AbstractFile destFile = resolvedDest.getDestinationFile();
    FileSet fileSet = new FileSet(destFile.getParent());
    // Job's FileSet needs to contain at least one file
    fileSet.add(destFile);
    ProgressDialog progressDialog = new ProgressDialog(mainFrame, getTitle());
    MkdirJob job;
    if (mkfileMode)
        job = new MkdirJob(progressDialog, mainFrame, fileSet, allocateSpaceCheckBox.isSelected() ? allocateSpaceChooser.getValue() : -1);
    else
        job = new MkdirJob(progressDialog, mainFrame, fileSet);
    progressDialog.start(job);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileSet(com.mucommander.commons.file.util.FileSet) MkdirJob(com.mucommander.job.impl.MkdirJob) DestinationType(com.mucommander.commons.file.util.DestinationType) PathUtils(com.mucommander.commons.file.util.PathUtils)

Example 13 with FileSet

use of com.mucommander.commons.file.util.FileSet in project mucommander by mucommander.

the class GnomeTrash method empty.

/**
 * Empty the trash
 * <p>
 * <b>Implementation notes:</b><br>
 * Simply free the <code>TRASH_PATH</code> directory
 * </p>
 *
 * @return True if everything went well
 */
@Override
public boolean empty() {
    // Abort if there is no usable trash folder
    if (TRASH_FOLDER == null)
        return false;
    FileSet filesToDelete = new FileSet(TRASH_FOLDER);
    try {
        // delete real files
        filesToDelete.addAll(TRASH_FILES_SUBFOLDER.ls());
        // delete spec files
        filesToDelete.addAll(TRASH_INFO_SUBFOLDER.ls());
    } catch (java.io.IOException ex) {
        LOGGER.debug("Failed to list files", ex);
        return false;
    }
    if (filesToDelete.size() > 0) {
        // Starts deleting files
        MainFrame mainFrame = WindowManager.getCurrentMainFrame();
        ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("delete_dialog.deleting"));
        DeleteJob deleteJob = new DeleteJob(progressDialog, mainFrame, filesToDelete, false);
        progressDialog.start(deleteJob);
    }
    return true;
}
Also used : DeleteJob(com.mucommander.job.impl.DeleteJob) FileSet(com.mucommander.commons.file.util.FileSet) IOException(java.io.IOException) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) MainFrame(com.mucommander.ui.main.MainFrame)

Example 14 with FileSet

use of com.mucommander.commons.file.util.FileSet in project mucommander by mucommander.

the class FileDropTargetListener method drop.

public void drop(DropTargetDropEvent event) {
    // Restore default cursor, no matter what
    folderPanel.setCursor(Cursor.getDefaultCursor());
    // so this test is really necessary
    if (!dragAccepted) {
        event.rejectDrop();
        return;
    }
    // Accept drop event
    event.acceptDrop(currentDropAction);
    // Retrieve the files contained by the transferable as a FileSet (takes care of handling the different
    // DataFlavors)
    FileSet droppedFiles = TransferableFileSet.getTransferFiles(event.getTransferable());
    // Stop and report failure if no file could not be retrieved
    if (droppedFiles == null || droppedFiles.size() == 0) {
        // Report drop failure
        event.dropComplete(false);
        return;
    }
    // If more than one file is dropped, only the first one is used
    if (changeFolderOnlyMode || currentDropAction == DnDConstants.ACTION_LINK) {
        AbstractFile file = droppedFiles.elementAt(0);
        // If file is a directory, change current folder to that directory
        if (file.isDirectory())
            folderPanel.tryChangeCurrentFolder(file);
        else
            // For any other file kind (archive, regular file...), change directory to the file's parent folder
            // and select the file
            folderPanel.tryChangeCurrentFolder(file.getParent(), file, false);
        // Request focus on the FolderPanel
        folderPanel.requestFocus();
    } else // Normal mode: copy or move dropped files to the FolderPanel's current folder
    {
        MainFrame mainFrame = folderPanel.getMainFrame();
        AbstractFile destFolder = folderPanel.getCurrentFolder();
        if (currentDropAction == DnDConstants.ACTION_MOVE) {
            // Start moving files
            ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("move_dialog.moving"));
            MoveJob moveJob = new MoveJob(progressDialog, mainFrame, droppedFiles, destFolder, null, FileCollisionDialog.FileCollisionAction.ASK, false);
            progressDialog.start(moveJob);
        } else {
            // Start copying files
            ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying"));
            CopyJob job = new CopyJob(progressDialog, mainFrame, droppedFiles, destFolder, null, TransferMode.COPY, FileCollisionDialog.FileCollisionAction.ASK);
            progressDialog.start(job);
        }
    }
    // Report that the drop event has been successfully handled
    event.dropComplete(true);
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileSet(com.mucommander.commons.file.util.FileSet) CopyJob(com.mucommander.job.impl.CopyJob) MoveJob(com.mucommander.job.impl.MoveJob) ProgressDialog(com.mucommander.ui.dialog.file.ProgressDialog) MainFrame(com.mucommander.ui.main.MainFrame)

Example 15 with FileSet

use of com.mucommander.commons.file.util.FileSet in project mucommander by mucommander.

the class TransferableFileSet method getTransferFiles.

/**
 * Returns the files contained by the specified Transferable as a {@link com.mucommander.commons.file.util.FileSet},
 * or <code>null</code> if no file was present in the Transferable or if an error occurred.
 *
 * <p>3 types of dropped data flavors are supported and used in this order of priority:
 * <ul>
 * <li>FileSet: the local DataFlavor used when files are transferred from muCommander
 * <li>File list: used when files are transferred from an external application
 * <li>File paths: alternate flavor used when some text representing one or several file paths is dragged
 * from an external application
 * </ul>
 *
 * @param transferable a Transferable instance that contains the files to be retrieved
 * @return the files contained by the specified Transferable as a FileSet, or <code>null</code> if no file
 * was present or if an error occurred
 */
public static FileSet getTransferFiles(Transferable transferable) {
    FileSet files;
    try {
        // FileSet DataFlavor
        if (transferable.isDataFlavorSupported(FILE_SET_DATA_FLAVOR)) {
            files = (FileSet) transferable.getTransferData(FILE_SET_DATA_FLAVOR);
        } else // File list DataFlavor
        if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            List<File> fileList = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
            int nbFiles = fileList.size();
            files = new FileSet();
            for (int i = 0; i < nbFiles; i++) {
                AbstractFile file = FileFactory.getFile(fileList.get(i).getAbsolutePath());
                if (file != null)
                    files.add(file);
            }
        } else // Text plain DataFlavor: assume that lines designate file paths
        if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            // do so just to be sure.
            try (BufferedReader br = new BufferedReader(DataFlavor.getTextPlainUnicodeFlavor().getReaderForText(transferable))) {
                // Read input line by line and try to create AbstractFile instances
                String path;
                files = new FileSet();
                while ((path = br.readLine()) != null) {
                    // Try to create an AbstractFile instance, returned instance may be null
                    AbstractFile file = FileFactory.getFile(path);
                    // piece of text (let's say an email contents) was inadvertently pasted or dropped to muCommander.
                    if (file == null)
                        return null;
                    files.add(file);
                }
            }
        } else {
            return null;
        }
    } catch (Exception e) {
        // Catch UnsupportedFlavorException, IOException
        LOGGER.debug("Caught exception while processing transferable", e);
        return null;
    }
    return files;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileSet(com.mucommander.commons.file.util.FileSet) BufferedReader(java.io.BufferedReader) List(java.util.List) LocalFile(com.mucommander.commons.file.protocol.local.LocalFile) File(java.io.File) AbstractFile(com.mucommander.commons.file.AbstractFile) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Aggregations

FileSet (com.mucommander.commons.file.util.FileSet)16 AbstractFile (com.mucommander.commons.file.AbstractFile)8 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)5 MainFrame (com.mucommander.ui.main.MainFrame)3 IOException (java.io.IOException)3 CopyJob (com.mucommander.job.impl.CopyJob)2 DeleteJob (com.mucommander.job.impl.DeleteJob)2 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)1 DestinationType (com.mucommander.commons.file.util.DestinationType)1 PathUtils (com.mucommander.commons.file.util.PathUtils)1 MkdirJob (com.mucommander.job.impl.MkdirJob)1 MoveJob (com.mucommander.job.impl.MoveJob)1 SearchJob (com.mucommander.job.impl.SearchJob)1 SendMailJob (com.mucommander.job.impl.SendMailJob)1 TempOpenWithJob (com.mucommander.job.impl.TempOpenWithJob)1 ChangePermissionsDialog (com.mucommander.ui.dialog.file.ChangePermissionsDialog)1 DownloadDialog (com.mucommander.ui.dialog.file.DownloadDialog)1 LocalCopyDialog (com.mucommander.ui.dialog.file.LocalCopyDialog)1 FolderPanel (com.mucommander.ui.main.FolderPanel)1 FileTable (com.mucommander.ui.main.table.FileTable)1