diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index efec6542ab0..c1721826976 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1097,7 +1097,7 @@ public void searchAndOpen() { final Set types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); final List dirs = basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()); - final List extensions = types.stream().map(ExternalFileType::getExtension).collect(Collectors.toList()); + final List extensions = types.stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList()); // Run the search operation: FileFinder fileFinder = FileFinders.constructFromConfiguration(Globals.prefs.getAutoLinkPreferences()); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 78a679cc39e..d0d0c3c1717 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -146,10 +146,10 @@ public static boolean openExternalFileAnyFormat(Path file, final BibDatabaseCont private static void openExternalFilePlatformIndependent(Optional fileType, String filePath) throws IOException { if (fileType.isPresent()) { - String application = fileType.get().getOpenWithApplication(); + String application = fileType.get().getOpenWithApplication().getValue(); if (application.isEmpty()) { - NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension()); + NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension().getValue()); } else { NATIVE_DESKTOP.openFileWithApplication(filePath, application); } diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index a39c6e335d2..37aed2e1089 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -29,8 +29,8 @@ public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); String viewer; - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - viewer = type.get().getOpenWithApplication(); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + viewer = type.get().getOpenWithApplication().getValue(); } else { viewer = "xdg-open"; } diff --git a/src/main/java/org/jabref/gui/desktop/os/OSX.java b/src/main/java/org/jabref/gui/desktop/os/OSX.java index c4a6c495431..a326f9a9afb 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -16,8 +16,8 @@ public class OSX implements NativeDesktop { @Override public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - openFileWithApplication(filePath, type.get().getOpenWithApplication()); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + openFileWithApplication(filePath, type.get().getOpenWithApplication().getValue()); } else { String[] cmd = {"/usr/bin/open", filePath}; Runtime.getRuntime().exec(cmd); diff --git a/src/main/java/org/jabref/gui/desktop/os/Windows.java b/src/main/java/org/jabref/gui/desktop/os/Windows.java index 5de0f056f65..b90dce5a2ff 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -22,8 +22,8 @@ public class Windows implements NativeDesktop { public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - openFileWithApplication(filePath, type.get().getOpenWithApplication()); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + openFileWithApplication(filePath, type.get().getOpenWithApplication().getValue()); } else { // quote String so explorer handles URL query strings correctly String quotePath = "\"" + filePath + "\""; diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java index f771d0bed44..e7fb40a37c8 100644 --- a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java +++ b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java @@ -81,7 +81,7 @@ public List linkAssociatedFiles(List entries, NamedCompound public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOException { List linkedFiles = new ArrayList<>(); - List extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtension).collect(Collectors.toList()); + List extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList()); // Run the search operation FileFinder fileFinder = FileFinders.constructFromConfiguration(autoLinkPreferences); @@ -105,7 +105,7 @@ public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOEx .map(externalFileTypes::getExternalFileTypeByExt) .orElse(Optional.of(new UnknownExternalFileType(""))); - String strType = type.isPresent() ? type.get().getName() : ""; + String strType = type.isPresent() ? type.get().getName().getValue() : ""; Path relativeFilePath = FileUtil.relativize(foundFile, directories); LinkedFile linkedFile = new LinkedFile("", relativeFilePath, strType); linkedFiles.add(linkedFile); diff --git a/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java b/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java index 657ece362e5..bde1883769c 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java +++ b/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java @@ -57,7 +57,7 @@ public void addFilesToEntry(BibEntry entry, List files) { ExternalFileType type = externalFileTypes.getExternalFileTypeByExt(ext) .orElse(new UnknownExternalFileType(ext)); Path relativePath = FileUtil.relativize(file, bibDatabaseContext.getFileDirectoriesAsPaths(filePreferences)); - LinkedFile linkedfile = new LinkedFile("", relativePath.toString(), type.getName()); + LinkedFile linkedfile = new LinkedFile("", relativePath.toString(), type.getName().getValue()); entry.addFile(linkedfile); }); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java index 5a4887c6fd3..a1be9f1db13 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java @@ -2,6 +2,9 @@ import java.util.Objects; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; @@ -12,26 +15,26 @@ */ public class CustomExternalFileType implements ExternalFileType { - private String name; - private String extension; - private String openWith; - private String iconName; - private String mimeType; + private StringProperty name; + private StringProperty extension; + private StringProperty openWith; + private StringProperty iconName; + private StringProperty mimeType; private JabRefIcon icon; - public CustomExternalFileType(String name, String extension, String mimeType, - String openWith, String iconName, JabRefIcon icon) { + public CustomExternalFileType(StringProperty name, StringProperty extension, StringProperty mimeType, + StringProperty openWith, StringProperty iconName, JabRefIcon icon) { this.name = name; this.extension = extension; this.mimeType = mimeType; this.openWith = openWith; - setIconName(iconName); + setIconName(iconName.getValue()); setIcon(icon); } public CustomExternalFileType(ExternalFileType type) { - this(type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), "", type.getIcon()); + this(type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), new SimpleStringProperty(""), type.getIcon()); } /** @@ -75,52 +78,62 @@ public static ExternalFileType buildFromArgs(String[] val) { } } - return new CustomExternalFileType(name, extension, mimeType, openWith, iconName, icon); + return new CustomExternalFileType(new SimpleStringProperty(name), new SimpleStringProperty(extension), new SimpleStringProperty(mimeType), new SimpleStringProperty(openWith), new SimpleStringProperty(iconName), icon); } @Override - public String getName() { + public StringProperty getName() { return name; } + @Override + public String getNameAsString() { + return name.getValue(); + } + public void setName(String name) { - this.name = name; + this.name = new SimpleStringProperty(name); } @Override - public String getExtension() { + public StringProperty getExtension() { if (extension == null) { - return ""; + return new SimpleStringProperty(""); } return extension; } + @Override + public String getExtensionAsString() { + return extension.getValue(); + } + public void setExtension(String extension) { - this.extension = extension; + this.extension = new SimpleStringProperty(extension); } @Override - public String getMimeType() { + public StringProperty getMimeType() { if (mimeType == null) { - return ""; + return new SimpleStringProperty(""); } return mimeType; } public void setMimeType(String mimeType) { - this.mimeType = mimeType; + this.mimeType = new SimpleStringProperty(mimeType); } @Override - public String getOpenWithApplication() { + public StringProperty getOpenWithApplication() { if (openWith == null) { - return ""; + return new SimpleStringProperty(""); } return openWith; } public void setOpenWith(String openWith) { - this.openWith = openWith; + this.openWith = new SimpleStringProperty(openWith); } /** @@ -129,7 +142,7 @@ public void setOpenWith(String openWith) { * @return The icon name. */ public String getIconName() { - return iconName; + return iconName.getValue(); } /** @@ -138,7 +151,7 @@ public String getIconName() { * @param name The icon name to use. */ public void setIconName(String name) { - this.iconName = name; + this.iconName = new SimpleStringProperty(name); } @Override @@ -153,7 +166,7 @@ public void setIcon(JabRefIcon icon) { @Override public String toString() { - return getName(); + return getName().toString(); } public ExternalFileType copy() { diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java index e7a2d1492ef..a002a75f898 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java @@ -52,10 +52,10 @@ public void initialize() { fileTypesTable.setItems(viewModel.getFileTypes()); fileTypesTableIconColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getIcon())); - fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName())); - fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension())); - fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType())); - fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication())); + fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName().getValue())); + fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension().getValue())); + fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType().getValue())); + fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication().getValue())); fileTypesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); fileTypesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java index e7ee73267b2..d2758a9899f 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java @@ -4,6 +4,8 @@ import java.util.List; import java.util.Set; +import javafx.beans.Observable; +import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -16,8 +18,9 @@ public class CustomizeExternalFileTypesViewModel { public CustomizeExternalFileTypesViewModel() { Set types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); - fileTypes = FXCollections.observableArrayList(types); - fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); + fileTypes = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.getName(), extractor.getExtension(), extractor.getMimeType(), extractor.getOpenWithApplication()}); + fileTypes.addAll(types); + fileTypes.sort(Comparator.comparing(ExternalFileType::getNameAsString)); } /** @@ -30,11 +33,11 @@ public void storeSettings() { public void resetToDefaults() { List list = ExternalFileTypes.getDefaultExternalFileTypes(); fileTypes.setAll(list); - fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); + fileTypes.sort(Comparator.comparing(ExternalFileType::getNameAsString)); } public void addNewType() { - CustomExternalFileType type = new CustomExternalFileType("", "", "", "", "new", IconTheme.JabRefIcons.FILE); + CustomExternalFileType type = new CustomExternalFileType(new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty("new"), IconTheme.JabRefIcons.FILE); fileTypes.add(type); showEditDialog(type, Localization.lang("Add new file type")); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java index dc573aa2c36..2b34a73d0a9 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java @@ -19,13 +19,13 @@ public class EditExternalFileTypeViewModel { public EditExternalFileTypeViewModel(CustomExternalFileType fileType) { this.fileType = fileType; - extensionProperty.setValue(fileType.getExtension()); - nameProperty.setValue(fileType.getName()); - mimeTypeProperty.setValue(fileType.getMimeType()); - selectedApplicationProperty.setValue(fileType.getOpenWithApplication()); + extensionProperty.setValue(fileType.getExtension().getValue()); + nameProperty.setValue(fileType.getName().getValue()); + mimeTypeProperty.setValue(fileType.getMimeType().getValue()); + selectedApplicationProperty.setValue(fileType.getOpenWithApplication().getValue()); icon = fileType.getIcon().getGraphicNode(); - if (fileType.getOpenWithApplication().isEmpty()) { + if (fileType.getOpenWithApplication().getValue().isEmpty()) { defaultApplicationSelectedProperty.setValue(true); } else { diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java index 1e7c7a0315f..be328dfea39 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java @@ -1,15 +1,21 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.JabRefIcon; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; public interface ExternalFileType { - String getName(); + StringProperty getName(); + + String getNameAsString(); - String getExtension(); + StringProperty getExtension(); - String getMimeType(); + String getExtensionAsString(); + + StringProperty getMimeType(); /** * Get the bibtex field name used for this file type. @@ -18,10 +24,12 @@ public interface ExternalFileType { * @return The field name. */ default Field getField() { - return FieldFactory.parseField(getExtension()); + return FieldFactory.parseField(getExtension().getValue()); } - String getOpenWithApplication(); + StringProperty getOpenWithApplication(); JabRefIcon getIcon(); + + String toString(); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index 7e7d2836f1b..0aa11d646a2 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -26,7 +26,7 @@ public class ExternalFileTypes { // The only instance of this class: private static ExternalFileTypes singleton; // Map containing all registered external file types: - private final Set externalFileTypes = new TreeSet<>(Comparator.comparing(ExternalFileType::getName)); + private final Set externalFileTypes = new TreeSet<>(Comparator.comparing(ExternalFileType::getNameAsString)); private final ExternalFileType HTML_FALLBACK_TYPE = StandardExternalFileType.URL; @@ -72,7 +72,7 @@ public Optional getExternalFileTypeByName(String name) { */ public Optional getExternalFileTypeByExt(String extension) { String extensionCleaned = extension.replace(".", "").replace("*", ""); - return externalFileTypes.stream().filter(type -> type.getExtension().equalsIgnoreCase(extensionCleaned)).findFirst(); + return externalFileTypes.stream().filter(type -> type.getExtension().getValue().equalsIgnoreCase(extensionCleaned)).findFirst(); } /** @@ -82,7 +82,7 @@ public Optional getExternalFileTypeByExt(String extension) { * @return true if an ExternalFileType with the extension exists, false otherwise */ public boolean isExternalFileTypeByExt(String extension) { - return externalFileTypes.stream().anyMatch(type -> type.getExtension().equalsIgnoreCase(extension)); + return externalFileTypes.stream().anyMatch(type -> type.getExtension().getValue().equalsIgnoreCase(extension)); } /** @@ -95,9 +95,9 @@ public Optional getExternalFileTypeForName(String filename) { int longestFound = -1; ExternalFileType foundType = null; for (ExternalFileType type : externalFileTypes) { - if (!type.getExtension().isEmpty() && filename.toLowerCase(Locale.ROOT).endsWith(type.getExtension().toLowerCase(Locale.ROOT)) - && (type.getExtension().length() > longestFound)) { - longestFound = type.getExtension().length(); + if (!type.getExtension().getValue().isEmpty() && filename.toLowerCase(Locale.ROOT).endsWith(type.getExtension().getValue().toLowerCase(Locale.ROOT)) + && (type.getExtension().getValue().length() > longestFound)) { + longestFound = type.getExtension().getValue().length(); foundType = type; } } @@ -113,7 +113,7 @@ public Optional getExternalFileTypeForName(String filename) { */ public Optional getExternalFileTypeByMimeType(String mimeType) { for (ExternalFileType type : externalFileTypes) { - if (type.getMimeType().equalsIgnoreCase(mimeType)) { + if (type.getMimeType().getValue().equalsIgnoreCase(mimeType)) { return Optional.of(type); } } @@ -176,7 +176,7 @@ public void setExternalFileTypes(List types) { i++; } for (ExternalFileType type : defTypes) { - array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG}; + array[i] = new String[] {type.getName().getValue(), FILE_TYPE_REMOVED_FLAG}; i++; } Globals.prefs.put(JabRefPreferences.EXTERNAL_FILE_TYPES, FileFieldWriter.encodeStringArray(array)); @@ -190,7 +190,7 @@ public void setExternalFileTypes(List types) { * @return A String[] containing all information about this file type. */ private String[] getStringArrayRepresentation(ExternalFileType type) { - return new String[]{type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), type.getIcon().name()}; + return new String[]{type.getName().getValue(), type.getExtension().getValue(), type.getMimeType().getValue(), type.getOpenWithApplication().getValue(), type.getIcon().name()}; } /** diff --git a/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java index 92718e09a7a..e5693517f72 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java @@ -1,5 +1,8 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; import org.jabref.logic.l10n.Localization; @@ -30,42 +33,52 @@ public enum StandardExternalFileType implements ExternalFileType { MHT("MHT", "mht", "multipart/related", "firefox", "www", IconTheme.JabRefIcons.WWW), ePUB("ePUB", "epub", "application/epub+zip", "firefox", "www", IconTheme.JabRefIcons.WWW); - private final String name; - private final String extension; - private final String mimeType; - private final String openWith; - private final String iconName; + private final StringProperty name; + private final StringProperty extension; + private final StringProperty mimeType; + private final StringProperty openWith; + private final StringProperty iconName; private final JabRefIcon icon; StandardExternalFileType(String name, String extension, String mimeType, String openWith, String iconName, JabRefIcon icon) { - this.name = name; - this.extension = extension; - this.mimeType = mimeType; - this.openWith = openWith; - this.iconName = iconName; + this.name = new SimpleStringProperty(name); + this.extension = new SimpleStringProperty(extension); + this.mimeType = new SimpleStringProperty(mimeType); + this.openWith = new SimpleStringProperty(openWith); + this.iconName = new SimpleStringProperty(iconName); this.icon = icon; } @Override - public String getName() { + public StringProperty getName() { return name; } @Override - public String getExtension() { + public String getNameAsString() { + return name.getValue(); + } + + @Override + public StringProperty getExtension() { return extension; } @Override - public String getMimeType() { + public String getExtensionAsString() { + return extension.getValue(); + } + + @Override + public StringProperty getMimeType() { return mimeType; } @Override - public String getOpenWithApplication() { + public StringProperty getOpenWithApplication() { // On all OSes there is a generic application available to handle file opening, so use this one - return ""; + return new SimpleStringProperty(""); } @Override diff --git a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java index 41be901f9e8..3e756463cdc 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java @@ -1,5 +1,8 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; @@ -11,36 +14,46 @@ */ public class UnknownExternalFileType implements ExternalFileType { - private final String name; - private final String extension; + private final StringProperty name; + private final StringProperty extension; public UnknownExternalFileType(String name) { this(name, ""); } public UnknownExternalFileType(String name, String extension) { - this.name = name; - this.extension = extension; + this.name = new SimpleStringProperty(name); + this.extension = new SimpleStringProperty(extension); } @Override - public String getName() { + public StringProperty getName() { return name; } @Override - public String getExtension() { + public String getNameAsString() { + return name.getValue(); + } + + @Override + public StringProperty getExtension() { return extension; } @Override - public String getMimeType() { - return ""; + public String getExtensionAsString() { + return extension.getValue(); + } + + @Override + public StringProperty getMimeType() { + return new SimpleStringProperty(""); } @Override - public String getOpenWithApplication() { - return ""; + public StringProperty getOpenWithApplication() { + return new SimpleStringProperty(""); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 103a352fd03..f6a0aa47e5a 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -421,7 +421,7 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa BackgroundTask downloadTask = BackgroundTask .wrap(() -> { Optional suggestedType = inferFileType(urlDownload); - String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName(); + String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName().getValue(); linkedFile.setFileType(suggestedTypeName); String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 471af98aa2f..a1060de07ba 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -94,7 +94,7 @@ public static LinkedFile fromFile(Path file, List fileDirectories, Externa .getExternalFileTypeByExt(fileExtension) .orElse(new UnknownExternalFileType(fileExtension)); Path relativePath = FileUtil.relativize(file, fileDirectories); - return new LinkedFile("", relativePath.toString(), suggestedFileType.getName()); + return new LinkedFile("", relativePath.toString(), suggestedFileType.getName().getValue()); } public LinkedFileViewModel fromFile(Path file) { diff --git a/src/main/java/org/jabref/gui/filelist/FileListEntry.java b/src/main/java/org/jabref/gui/filelist/FileListEntry.java index 23ebefc2a92..9453c997fcf 100644 --- a/src/main/java/org/jabref/gui/filelist/FileListEntry.java +++ b/src/main/java/org/jabref/gui/filelist/FileListEntry.java @@ -38,7 +38,7 @@ public String[] getStringArrayRepresentation() { } private String getTypeName() { - return this.getType().isPresent() ? this.getType().get().getName() : ""; + return this.getType().isPresent() ? this.getType().get().getName().getValue() : ""; } @Override @@ -47,7 +47,7 @@ public String toString() { } public LinkedFile toParsedFileField() { - return new LinkedFile(getDescription(), getLink(), getType().isPresent() ? getType().get().getName() : ""); + return new LinkedFile(getDescription(), getLink(), getType().isPresent() ? getType().get().getName().getValue() : ""); } public String getDescription() { diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java index 1990315fe01..ec80f59060a 100644 --- a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java @@ -160,7 +160,7 @@ private void removeSpecialFieldColumns() { private void insertExtraFileColumns() { ExternalFileTypes.getInstance().getExternalFileTypeSelection().stream() .map(ExternalFileType::getName) - .map(name -> new MainTableColumnModel(MainTableColumnModel.Type.EXTRAFILE, name)) + .map(name -> new MainTableColumnModel(MainTableColumnModel.Type.EXTRAFILE, name.getValue())) .forEach(item -> availableColumnsProperty.getValue().add(item)); }