Skip to content

Commit

Permalink
Fix File Filter and some layout issues
Browse files Browse the repository at this point in the history
Fixes part of #7383
  • Loading branch information
Siedlerchr committed Jan 25, 2021
1 parent ae43548 commit 72cd809
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FileExtensionViewModel {
private final ExternalFileTypes externalFileTypes;

FileExtensionViewModel(FileType fileType, ExternalFileTypes externalFileTypes) {
this.description = Localization.lang("%0 file", fileType.toString());
this.description = Localization.lang("%0 file", fileType.getName());
this.extensions = fileType.getExtensionsWithDot();
this.externalFileTypes = externalFileTypes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter
Map<Boolean, List<Path>> fileListPartition;

try (Stream<Path> filesStream = StreamSupport.stream(Files.newDirectoryStream(directory, fileFilter).spliterator(), false)) {
fileListPartition = filesStream.collect(Collectors.partitioningBy(path -> path.toFile().isDirectory()));
fileListPartition = filesStream.collect(Collectors.partitioningBy(Files::isDirectory));
} catch (IOException e) {
LOGGER.error(String.format("%s while searching files: %s", e.getClass().getName(), e.getMessage()));
return parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
</tooltip>
</Button>

<Label text="%File extension:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<Label text="%File type:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<ComboBox fx:id="fileTypeCombo" maxWidth="Infinity" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Button fx:id="scanButton" onAction="#scanFiles" text="%Scan directory"
<Button fx:id="scanButton" onAction="#scanFiles" text="%Search"
GridPane.columnIndex="2" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Searches the selected directory for unlinked files."/>
Expand All @@ -68,14 +68,14 @@
</ScrollPane>
</TitledPane>
<TitledPane fx:id="resultPane" text="%Import result" disable="true">
<TableView fx:id="importResultTable">
<TableView fx:id="importResultTable" styleClass="unlinkedFilesResultTable">
<columns>
<TableColumn fx:id="colStatus" prefWidth="100.0" text="%Status"/>
<TableColumn fx:id="colMessage" prefWidth="300.0" text="%Message"/>
<TableColumn fx:id="colFile" prefWidth="500.0" text="%File"/>
<TableColumn fx:id="colMessage" prefWidth="300.0" text="%Message"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</TitledPane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.DirectoryStream.Filter;
import java.nio.file.Files;
import java.nio.file.Path;

import org.jabref.logic.util.io.DatabaseFileLookup;
Expand Down Expand Up @@ -31,6 +32,11 @@ public UnlinkedPDFFileFilter(DirectoryStream.Filter<Path> fileFilter, BibDatabas

@Override
public boolean accept(Path pathname) throws IOException {
return fileFilter.accept(pathname) && !lookup.lookupDatabase(pathname.toFile());

if (Files.isDirectory(pathname)) {
return true;
} else {
return fileFilter.accept(pathname) && !lookup.lookupDatabase(pathname);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/util/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ default List<String> getExtensionsWithDot() {
}

List<String> getExtensions();

String getName();
}
78 changes: 42 additions & 36 deletions src/main/java/org/jabref/logic/util/StandardFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,64 @@
*/
public enum StandardFileType implements FileType {

BIBTEXML("bibx", "xml"),
ENDNOTE("ref", "enw"),
ISI("isi", "txt"),
MEDLINE("nbib", "xml"),
MEDLINE_PLAIN("nbib", "txt"),
PUBMED("fcgi"),
SILVER_PLATTER("dat", "txt"),

AUX("aux"),
BIBTEX_DB("bib"),
CITATION_STYLE("csl"),
CLASS("class"),
CSV("csv"),
HTML("html", "htm"),
JAR("jar"),
JAVA_KEYSTORE("jks"),
JSTYLE("jstyle"),
LAYOUT("layout"),
ODS("ods"),
PDF("pdf"),
RIS("ris"),
TERMS("terms"),
TXT("txt"),
RDF("rdf"),
RTF("rtf"),
SXC("sxc"),
TEX("tex"),
XML("xml"),
JSON("json"),
XMP("xmp"),
ZIP("zip"),
CSS("css"),
YAML("yaml"),
ANY_FILE("*");
BIBTEXML("BibTeXML", "bibx", "xml"),
ENDNOTE("Endnote", "ref", "enw"),
ISI("Isi", "isi", "txt"),
MEDLINE("Medline", "nbib", "xml"),
MEDLINE_PLAIN("Medline Plain", "nbib", "txt"),
PUBMED("Pubmed", "fcgi"),
SILVER_PLATTER("SilverPlatter", "dat", "txt"),
AUX("Aux file", "aux"),
BIBTEX_DB("Bibtex library", "bib"),
CITATION_STYLE("Citation Style", "csl"),
CLASS("Class file", "class"),
CSV("CSV", "csv"),
HTML("HTML", "html", "htm"),
JAR("JAR", "jar"),
JAVA_KEYSTORE("Java Keystore", "jks"),
JSTYLE("LibreOffice layout style", "jstyle"),
LAYOUT("Custom Exporter format", "layout"),
ODS("OpenOffice Calc", "ods"),
PDF("PDF", "pdf"),
RIS("RIS", "ris"),
TERMS("Protected terms", "terms"),
TXT("Plain Text", "txt"),
RDF("RDF", "rdf"),
RTF("RTF", "rtf"),
SXC("Open Office Calc 1.x", "sxc"),
TEX("LaTeX", "tex"),
XML("XML", "xml"),
JSON("JSON", "json"),
XMP("XMP", "xmp"),
ZIP("Zip Archive", "zip"),
CSS("CSS Styleshet", "css"),
YAML("YAML Markup", "yaml"),
ANY_FILE("All files", "*");

private final List<String> extensions;
private final String name;

StandardFileType(String... extensions) {
StandardFileType(String name, String... extensions) {
this.extensions = Arrays.asList(extensions);
this.name = name;
}

@Override
public List<String> getExtensions() {
return extensions;
}

@Override
public String getName() {
return this.name;
}

public static FileType fromExtensions(String... extensions) {
var exts = Arrays.asList(extensions);

return OptionalUtil.orElse(Arrays.stream(StandardFileType.values())
.filter(field -> field.getExtensions().stream().anyMatch(elem -> exts.contains(elem)))
.findAny(),
new UnknownFileType(extensions));
new UnknownFileType(extensions));
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/logic/util/UnknownFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(extensions);
}

@Override
public String getName() {
return "Unknown File Type" + extensions.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public DatabaseFileLookup(BibDatabaseContext databaseContext, FilePreferences fi
* <br>
* For the matching, the absolute file paths will be used.
*
* @param file A {@link File} Object.
* @param pathname A {@link File} Object.
* @return <code>true</code>, if the file Object is stored in at least one
* entry in the database, otherwise <code>false</code>.
*/
public boolean lookupDatabase(File file) {
return fileCache.contains(file.toPath());
public boolean lookupDatabase(Path pathname) {
return fileCache.contains(pathname);
}

private List<Path> parseFileField(BibEntry entry) {
Expand Down

0 comments on commit 72cd809

Please sign in to comment.