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

Merge identical group color indicators #6768

Merged
merged 10 commits into from
Aug 19, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue with the creation of a group of cited entries. Now the file path to an aux file gets validated. [#6585](https://github.com/JabRef/jabref/issues/6585)
- We fixed an issue on Linux systems where the application would crash upon inotify failure. Now, the user is prompted with a warning, and given the choice to continue the session. [#6073](https://github.com/JabRef/jabref/issues/6073)
- We moved the search modifier buttons into the search bar, as they were not accessible, if autocompletion was disabled. [#6625](https://github.com/JabRef/jabref/issues/6625)
- We fixed an issue about duplicated group color indicators [#6175](https://github.com/JabRef/jabref/issues/6175)
- We fixed an issue where entries with the entry type Misc from an imported aux file would not be saved correctly to the bib file on disk [#6405](https://github.com/JabRef/jabref/issues/6405)
- We fixed an issue where percent sign ('%') was not formatted properly by the HTML formatter [#6753](https://github.com/JabRef/jabref/issues/6753)

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.gui.maintable.columns.MainTableColumnFactory;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.DefaultTaskExecutor;
Expand Down Expand Up @@ -87,7 +89,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame,
Globals.stateManager);
localDragboard = Globals.stateManager.getLocalDragboard();

this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager(), frame.getDialogService()).createColumns());
this.getColumns().addAll(new MainTableColumnFactory(database, Globals.prefs, externalFileTypes, panel.getUndoManager(), frame.getDialogService()).createColumns());

new ViewModelTableRowFactory<BibEntryTableViewModel>()
.withOnMouseClickedEvent((entry, event) -> {
Expand Down
452 changes: 0 additions & 452 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javafx.beans.InvalidationListener;

import org.jabref.gui.maintable.columns.MainTableColumn;
import org.jabref.preferences.PreferencesService;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jabref.gui.maintable;
package org.jabref.gui.maintable.columns;

import javafx.beans.value.ObservableValue;

import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.MainTableColumnModel;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.gui.util.comparator.NumericFieldComparator;
import org.jabref.model.entry.field.OrFields;

/**
Expand All @@ -17,6 +21,12 @@ public FieldColumn(MainTableColumnModel model, OrFields fields) {

setText(getDisplayName());
setCellValueFactory(param -> getFieldValue(param.getValue()));

new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withText(text -> text)
.install(this);
this.setComparator(new NumericFieldComparator());
this.setSortable(true);
}

/**
Expand Down
159 changes: 159 additions & 0 deletions src/main/java/org/jabref/gui/maintable/columns/FileColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.jabref.gui.maintable.columns;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseButton;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.LinkedFileViewModel;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTableColumnModel;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.LinkedFile;
import org.jabref.preferences.PreferencesService;

/**
* A column that draws a clickable symbol for either all the files of a defined file type
* or a joined column with all the files of any type
*/
public class FileColumn extends MainTableColumn<List<LinkedFile>> {

private final ExternalFileTypes externalFileTypes;
private final DialogService dialogService;
private final BibDatabaseContext database;
private final PreferencesService preferencesService;

/**
* Creates a joined column for all the linked files.
*/
public FileColumn(MainTableColumnModel model,
BibDatabaseContext database,
ExternalFileTypes externalFileTypes,
DialogService dialogService,
PreferencesService preferencesService) {
super(model);
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.database = Objects.requireNonNull(database);
this.dialogService = dialogService;
this.preferencesService = preferencesService;

setCommonSettings();

Node headerGraphic = IconTheme.JabRefIcons.FILE.getGraphicNode();
Tooltip.install(headerGraphic, new Tooltip(Localization.lang("Linked files")));
this.setGraphic(headerGraphic);

new ValueTableCellFactory<BibEntryTableViewModel, List<LinkedFile>>()
.withGraphic(this::createFileIcon)
.withTooltip(this::createFileTooltip)
.withMenu(this::createFileMenu)
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.PRIMARY) && (linkedFiles.size() == 1)) {
// Only one linked file -> open directly
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFiles.get(0),
entry.getEntry(),
database, Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getFilePreferences(),
externalFileTypes);
linkedFileViewModel.open();
}
})
.install(this);
}

/**
* Creates a column for all the linked files of a single file type.
*/
public FileColumn(MainTableColumnModel model,
BibDatabaseContext database,
ExternalFileTypes externalFileTypes,
DialogService dialogService,
PreferencesService preferencesService,
String fileType) {
super(model);
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.database = Objects.requireNonNull(database);
this.dialogService = dialogService;
this.preferencesService = preferencesService;

setCommonSettings();

this.setGraphic(externalFileTypes
.getExternalFileTypeByName(fileType)
.map(ExternalFileType::getIcon).orElse(IconTheme.JabRefIcons.FILE)
.getGraphicNode());

new ValueTableCellFactory<BibEntryTableViewModel, List<LinkedFile>>()
.withGraphic(linkedFiles -> createFileIcon(linkedFiles.stream().filter(linkedFile ->
linkedFile.getFileType().equalsIgnoreCase(fileType)).collect(Collectors.toList())))
.install(this);
}

private void setCommonSettings() {
this.setResizable(false);
MainTableColumnFactory.setExactWidth(this, ColumnPreferences.ICON_COLUMN_WIDTH);
this.getStyleClass().add(MainTableColumnFactory.STYLE_ICON_COLUMN);
this.setCellValueFactory(cellData -> cellData.getValue().getLinkedFiles());
}

private String createFileTooltip(List<LinkedFile> linkedFiles) {
if (linkedFiles.size() > 0) {
return Localization.lang("Open file %0", linkedFiles.get(0).getLink());
}
return null;
}

private ContextMenu createFileMenu(BibEntryTableViewModel entry, List<LinkedFile> linkedFiles) {
if (linkedFiles.size() <= 1) {
return null;
}

ContextMenu contextMenu = new ContextMenu();

for (LinkedFile linkedFile : linkedFiles) {
LinkedFileViewModel linkedFileViewModel = new LinkedFileViewModel(linkedFile,
entry.getEntry(),
database,
Globals.TASK_EXECUTOR,
dialogService,
preferencesService.getXMPPreferences(),
preferencesService.getFilePreferences(),
externalFileTypes);

MenuItem menuItem = new MenuItem(linkedFileViewModel.getTruncatedDescriptionAndLink(),
linkedFileViewModel.getTypeIcon().getGraphicNode());
menuItem.setOnAction(event -> linkedFileViewModel.open());
contextMenu.getItems().add(menuItem);
}

return contextMenu;
}

private Node createFileIcon(List<LinkedFile> linkedFiles) {
if (linkedFiles.size() > 1) {
return IconTheme.JabRefIcons.FILE_MULTIPLE.getGraphicNode();
} else if (linkedFiles.size() == 1) {
return externalFileTypes.fromLinkedFile(linkedFiles.get(0), false)
.map(ExternalFileType::getIcon)
.orElse(IconTheme.JabRefIcons.FILE)
.getGraphicNode();
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.jabref.gui.maintable.columns;

import java.io.IOException;
import java.util.Map;

import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.CellFactory;
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTableColumnModel;
import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;

public class LinkedIdentifierColumn extends MainTableColumn<Map<Field, String>> {

private final BibDatabaseContext database;
private final CellFactory cellFactory;
private final DialogService dialogService;

public LinkedIdentifierColumn(MainTableColumnModel model,
CellFactory cellFactory,
BibDatabaseContext database,
DialogService dialogService) {
super(model);
this.database = database;
this.cellFactory = cellFactory;
this.dialogService = dialogService;

Node headerGraphic = IconTheme.JabRefIcons.WWW.getGraphicNode();
Tooltip.install(headerGraphic, new Tooltip(Localization.lang("Linked identifiers")));
this.setGraphic(headerGraphic);
this.getStyleClass().add(MainTableColumnFactory.STYLE_ICON_COLUMN);
MainTableColumnFactory.setExactWidth(this, ColumnPreferences.ICON_COLUMN_WIDTH);
this.setResizable(false);
this.setCellValueFactory(cellData -> cellData.getValue().getLinkedIdentifiers());
new ValueTableCellFactory<BibEntryTableViewModel, Map<Field, String>>()
.withGraphic(this::createIdentifierGraphic)
.withTooltip(this::createIdentifierTooltip)
.withMenu(this::createIdentifierMenu)
.install(this);
}

private Node createIdentifierGraphic(Map<Field, String> values) {
if (values.isEmpty()) {
return null;
} else {
return cellFactory.getTableIcon(StandardField.URL);
}
}

private String createIdentifierTooltip(Map<Field, String> values) {
StringBuilder identifiers = new StringBuilder();
values.keySet().forEach(field -> identifiers.append(field.getDisplayName()).append(": ").append(values.get(field)).append("\n"));
return identifiers.toString();
}

private ContextMenu createIdentifierMenu(BibEntryTableViewModel entry, Map<Field, String> values) {
ContextMenu contextMenu = new ContextMenu();

values.keySet().forEach(field -> {
MenuItem menuItem = new MenuItem(field.getDisplayName() + ": " +
ControlHelper.truncateString(values.get(field), -1, "...", ControlHelper.EllipsisPosition.CENTER),
cellFactory.getTableIcon(field));
menuItem.setOnAction(event -> {
try {
JabRefDesktop.openExternalViewer(database, values.get(field), field);
} catch (IOException e) {
dialogService.showErrorDialogAndWait(Localization.lang("Unable to open link."), e);
}
event.consume();
});
contextMenu.getItems().add(menuItem);
});

return contextMenu;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jabref.gui.maintable;
package org.jabref.gui.maintable.columns;

import javafx.beans.value.ObservableValue;
import javafx.scene.control.TableColumn;

import org.jabref.gui.maintable.BibEntryTableViewModel;
import org.jabref.gui.maintable.MainTableColumnModel;
import org.jabref.gui.util.BindingsHelper;

public class MainTableColumn<T> extends TableColumn<BibEntryTableViewModel, T> {
Expand Down
Loading