Search in sources :

Example 1 with CyFileFilterProvider

use of org.cytoscape.io.CyFileFilterProvider in project cytoscape-impl by cytoscape.

the class SupportedFileTypesManager method getSupportedFileTypes.

private List<FileChooserFilter> getSupportedFileTypes(final DataCategory category, final Set<CyFileFilterProvider> factories) {
    List<FileChooserFilter> types = new ArrayList<FileChooserFilter>();
    Set<String> allExtensions = new HashSet<String>();
    for (final CyFileFilterProvider factory : factories) {
        CyFileFilter filter = factory.getFileFilter();
        // this is a hack to exclude internal session table format
        if (filter.getExtensions().contains("cytable") || filter.getDataCategory() != category)
            continue;
        String description = filter.getDescription();
        Set<String> filterExtensions = filter.getExtensions();
        String[] extensions = new String[filterExtensions.size()];
        int index = 0;
        for (String extension : filterExtensions) {
            allExtensions.add(extension);
            extensions[index] = extension;
            index++;
        }
        types.add(new FileChooserFilter(description, extensions));
    }
    if (types.isEmpty())
        return types;
    Collections.sort(types, new Comparator<FileChooserFilter>() {

        @Override
        public int compare(FileChooserFilter o1, FileChooserFilter o2) {
            return o1.getDescription().compareTo(o2.getDescription());
        }
    });
    String description = String.format("All %1$s files", category.getDisplayName().toLowerCase());
    types.add(new FileChooserFilter(description, new ArrayList<String>(allExtensions).toArray(new String[allExtensions.size()])));
    return types;
}
Also used : ArrayList(java.util.ArrayList) FileChooserFilter(org.cytoscape.util.swing.FileChooserFilter) CyFileFilterProvider(org.cytoscape.io.CyFileFilterProvider) CyFileFilter(org.cytoscape.io.CyFileFilter) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CyFileFilter (org.cytoscape.io.CyFileFilter)1 CyFileFilterProvider (org.cytoscape.io.CyFileFilterProvider)1 FileChooserFilter (org.cytoscape.util.swing.FileChooserFilter)1