Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tries to address the refresh problem of the table in the dialog "Manage external file types" (issue 5902) #5907

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ public void searchAndOpen() {

final Set<ExternalFileType> types = ExternalFileTypes.getInstance().getExternalFileTypeSelection();
final List<Path> dirs = basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences());
final List<String> extensions = types.stream().map(ExternalFileType::getExtension).collect(Collectors.toList());
final List<String> extensions = types.stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList());

// Run the search operation:
FileFinder fileFinder = FileFinders.constructFromConfiguration(Globals.prefs.getAutoLinkPreferences());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ public static boolean openExternalFileAnyFormat(Path file, final BibDatabaseCont
private static void openExternalFilePlatformIndependent(Optional<ExternalFileType> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> 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";
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/OSX.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class OSX implements NativeDesktop {
@Override
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/Windows.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class Windows implements NativeDesktop {
public void openFile(String filePath, String fileType) throws IOException {
Optional<ExternalFileType> 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 + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public List<BibEntry> linkAssociatedFiles(List<BibEntry> entries, NamedCompound
public List<LinkedFile> findAssociatedNotLinkedFiles(BibEntry entry) throws IOException {
List<LinkedFile> linkedFiles = new ArrayList<>();

List<String> extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtension).collect(Collectors.toList());
List<String> extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList());

// Run the search operation
FileFinder fileFinder = FileFinders.constructFromConfiguration(autoLinkPreferences);
Expand All @@ -105,7 +105,7 @@ public List<LinkedFile> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void addFilesToEntry(BibEntry entry, List<Path> 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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -129,7 +142,7 @@ public void setOpenWith(String openWith) {
* @return The icon name.
*/
public String getIconName() {
return iconName;
return iconName.getValue();
}

/**
Expand All @@ -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
Expand All @@ -153,7 +166,7 @@ public void setIcon(JabRefIcon icon) {

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

public ExternalFileType copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,8 +18,9 @@ public class CustomizeExternalFileTypesViewModel {

public CustomizeExternalFileTypesViewModel() {
Set<ExternalFileType> 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));
}

/**
Expand All @@ -30,11 +33,11 @@ public void storeSettings() {
public void resetToDefaults() {
List<ExternalFileType> 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't a string be passed and converted in CustomExternalFileTypes internally?

fileTypes.add(type);
showEditDialog(type, Localization.lang("Add new file type"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the StringProperty used? I always saw getValue(). Did I miss something?


String getMimeType();
String getExtensionAsString();

StringProperty getMimeType();

/**
* Get the bibtex field name used for this file type.
Expand All @@ -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();
}
Loading