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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations