Search in sources :

Example 1 with ChainedFileFilter

use of com.mucommander.commons.file.filter.ChainedFileFilter in project mucommander by mucommander.

the class CommandManager method buildAssociations.

/**
 * Passes all known file associations to the specified builder.
 * <p>
 * This method guarantees that the builder's {@link AssociationBuilder#startBuilding() startBuilding()} and
 * {@link AssociationBuilder#endBuilding() endBuilding()} methods will both be called even if an error occurs.
 * If that happens however, it is entirely possible that not all associations will be passed to
 * the builder.
 * </p>
 * @param  builder          object that will receive association list building messages.
 * @throws CommandException if anything goes wrong.
 */
public static void buildAssociations(AssociationBuilder builder) throws CommandException {
    // Used to iterate through commands and associations.
    Iterator<CommandAssociation> iterator;
    // Used to iterate through each association's filters.
    Iterator<FileFilter> filters;
    // Buffer for the current file filter.
    FileFilter filter;
    // Current command association.
    CommandAssociation current;
    builder.startBuilding();
    // Goes through all the registered associations.
    iterator = associations();
    try {
        while (iterator.hasNext()) {
            current = iterator.next();
            builder.startAssociation(current.getCommand().getAlias());
            filter = current.getFilter();
            if (filter instanceof ChainedFileFilter) {
                filters = ((ChainedFileFilter) filter).getFileFilterIterator();
                while (filters.hasNext()) buildFilter(filters.next(), builder);
            } else
                buildFilter(filter, builder);
            builder.endAssociation();
        }
    } finally {
        builder.endBuilding();
    }
}
Also used : ChainedFileFilter(com.mucommander.commons.file.filter.ChainedFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) ChainedFileFilter(com.mucommander.commons.file.filter.ChainedFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter)

Aggregations

AttributeFileFilter (com.mucommander.commons.file.filter.AttributeFileFilter)1 ChainedFileFilter (com.mucommander.commons.file.filter.ChainedFileFilter)1 FileFilter (com.mucommander.commons.file.filter.FileFilter)1