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