Search in sources :

Example 16 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class OvirtDataCenter method ls.

@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
    String dcName = fileURL.getFilename();
    log.debug("listing Data Center {}", dcName);
    try (OvirtConnHandler connHandler = getConnHandler()) {
        DataCenter dc = Utils.getDataCenter(connHandler, dcName);
        return Utils.getStorageDomains(connHandler, dc.id()).stream().filter(sd -> sd.type() == StorageDomainType.DATA).map(this::toFile).filter(Objects::nonNull).toArray(AbstractFile[]::new);
    }
}
Also used : Objects(java.util.Objects) Logger(org.slf4j.Logger) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) FileOperation(com.mucommander.commons.file.FileOperation) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) DataCenter(org.ovirt.engine.sdk4.types.DataCenter) StorageDomainType(org.ovirt.engine.sdk4.types.StorageDomainType) FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) DataCenter(org.ovirt.engine.sdk4.types.DataCenter)

Example 17 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class CommandManager method loadAssociations.

/**
 * Loads the custom associations XML File.
 * <p>
 * The command files will be loaded as a <i>backed-up file</i> (see {@link BackupInputStream}).
 * Its format is described {@link AssociationsXmlConstants here}.
 * </p>
 * @throws IOException if an IO error occurs.
 * @see                #writeAssociations()
 * @see                #getAssociationFile()
 * @see                #setAssociationFile(String)
 */
public static void loadAssociations() throws IOException, CommandException {
    AbstractFile file = getAssociationFile();
    LOGGER.debug("Loading associations from file: " + file.getAbsolutePath());
    // Tries to load the associations file.
    // Associations are not considered to be modified by this.
    InputStream in = null;
    try {
        AssociationReader.read(in = new BackupInputStream(file), new AssociationFactory());
    } finally {
        wereAssociationsModified = false;
        // Makes sure the input stream is closed.
        if (in != null) {
            try {
                in.close();
            } catch (Exception e) {
            // Ignores this.
            }
        }
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) BackupInputStream(com.mucommander.io.backup.BackupInputStream) InputStream(java.io.InputStream) BackupInputStream(com.mucommander.io.backup.BackupInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 18 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class GnomeTrash method moveToTrash.

/**
 * Implementation of {@link com.mucommander.desktop.QueuedTrash} moveToTrash method.
 * <p>
 * Try to copy a collection of files to the GNOME's Trash.
 * </p>
 * @param queuedFiles Collection of files to the trash
 * @return <code>true</code> if movement has been successful or <code>false</code> otherwise
 */
@Override
protected boolean moveToTrash(List<AbstractFile> queuedFiles) {
    int nbFiles = queuedFiles.size();
    String fileInfoContent;
    String trashFileName;
    // overall return value (if everything went OK or at least one file wasn't moved properly
    boolean retVal = true;
    for (int i = 0; i < nbFiles; i++) {
        AbstractFile fileToDelete = queuedFiles.get(i);
        // generate content of info file and new filename
        try {
            fileInfoContent = getFileInfoContent(fileToDelete);
            trashFileName = getUniqueFilename(fileToDelete);
        } catch (IOException ex) {
            LOGGER.debug("Failed to create filename for new trash item: " + fileToDelete.getName(), ex);
            // continue with other file (do not move file, because info file cannot be properly created
            continue;
        }
        AbstractFile infoFile = null;
        OutputStreamWriter infoWriter = null;
        try {
            // create info file
            infoFile = TRASH_INFO_SUBFOLDER.getChild(trashFileName + ".trashinfo");
            infoWriter = new OutputStreamWriter(infoFile.getOutputStream());
            infoWriter.write(fileInfoContent);
        } catch (IOException ex) {
            retVal = false;
            LOGGER.debug("Failed to create trash info file: " + trashFileName, ex);
            // continue with other file (do not move file, because info file wasn't properly created)
            continue;
        } finally {
            if (infoWriter != null) {
                try {
                    infoWriter.close();
                } catch (IOException e) {
                // Not much else to do
                }
            }
        }
        try {
            // rename original file
            fileToDelete.renameTo(TRASH_FILES_SUBFOLDER.getChild(trashFileName));
        } catch (IOException ex) {
            try {
                // remove info file
                infoFile.delete();
            } catch (IOException ex1) {
            // simply ignore
            }
            retVal = false;
            LOGGER.debug("Failed to move file to trash: " + trashFileName, ex);
        }
    }
    return retVal;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Example 19 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class RenameAction method performAction.

@Override
public void performAction() {
    FileTable activeTable = mainFrame.getActiveTable();
    AbstractFile selectedFile = activeTable.getSelectedFile(false);
    // Trigger in-table editing only if a file other than parent folder '..' is selected
    if (selectedFile != null) {
        // Trigger in-table renaming
        activeTable.editCurrentFilename();
    }
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileTable(com.mucommander.ui.main.table.FileTable)

Example 20 with AbstractFile

use of com.mucommander.commons.file.AbstractFile in project mucommander by mucommander.

the class RevealInDesktopAction method toggleEnabledState.

@Override
protected void toggleEnabledState() {
    AbstractFile currentFolder = mainFrame.getActivePanel().getCurrentFolder();
    switch(currentFolder.getURL().getScheme()) {
        case LocalFile.SCHEMA:
            setEnabled(!currentFolder.isArchive() && !currentFolder.hasAncestor(AbstractArchiveEntryFile.class));
            break;
        case SearchFile.SCHEMA:
            AbstractFile selectedFile = mainFrame.getActiveTable().getSelectedFile();
            setEnabled(selectedFile != null && selectedFile.getURL().getScheme().equals(LocalFile.SCHEMA));
            break;
    }
}
Also used : AbstractArchiveEntryFile(com.mucommander.commons.file.archive.AbstractArchiveEntryFile) AbstractFile(com.mucommander.commons.file.AbstractFile)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)150 IOException (java.io.IOException)49 FileURL (com.mucommander.commons.file.FileURL)19 FileSet (com.mucommander.commons.file.util.FileSet)11 FileTable (com.mucommander.ui.main.table.FileTable)11 DialogAction (com.mucommander.ui.dialog.DialogAction)10 File (java.io.File)9 List (java.util.List)8 MainFrame (com.mucommander.ui.main.MainFrame)6 InputStream (java.io.InputStream)6 Vector (java.util.Vector)6 AbstractArchiveEntryFile (com.mucommander.commons.file.archive.AbstractArchiveEntryFile)5 ProtocolFile (com.mucommander.commons.file.protocol.ProtocolFile)5 LocalFile (com.mucommander.commons.file.protocol.local.LocalFile)5 ProgressDialog (com.mucommander.ui.dialog.file.ProgressDialog)5 FolderPanel (com.mucommander.ui.main.FolderPanel)5 FileTableModel (com.mucommander.ui.main.table.FileTableModel)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)4