From 5a36d97085b5f4b2bce0e4ccee7a44bd5925f588 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 18 Jan 2020 17:06:06 +0100 Subject: [PATCH 1/3] Added master table index column --- .../gui/maintable/MainTableColumnFactory.java | 23 +++++++++++++++++++ .../gui/maintable/MainTableColumnModel.java | 4 +++- .../preferences/TableColumnsTabViewModel.java | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java index eccc829ebb7..d927845200a 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java @@ -10,6 +10,7 @@ import javax.swing.undo.UndoManager; +import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; @@ -22,6 +23,7 @@ import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; +import javafx.scene.text.Text; import org.jabref.Globals; import org.jabref.gui.DialogService; @@ -82,6 +84,9 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre preferences.getColumns().forEach(column -> { switch (column.getType()) { + case INDEX: + columns.add(createIndexColumn(column)); + break; case GROUPS: columns.add(createGroupColumn(column)); break; @@ -125,6 +130,24 @@ private void setExactWidth(TableColumn column, double width) { column.setMaxWidth(width); } + /** + * Creates a text column to display any standard field. + */ + private TableColumn createIndexColumn(MainTableColumnModel columnModel) { + TableColumn column = new MainTableColumn<>(columnModel); + Node header = new Text("#"); + Tooltip.install(header, new Tooltip(MainTableColumnModel.Type.INDEX.getDisplayName())); + column.setGraphic(header); + column.setStyle("-fx-alignment: CENTER-RIGHT;"); + column.setCellValueFactory(cellData -> new ReadOnlyObjectWrapper<>( + String.valueOf(cellData.getTableView().getItems().indexOf(cellData.getValue()) + 1))); + new ValueTableCellFactory() + .withText(text -> text) + .install(column); + column.setSortable(false); + return column; + } + /** * Creates a column for group color bars. */ diff --git a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java index b4ff2ba9eba..ab6a2b40ff3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableColumnModel.java @@ -30,6 +30,7 @@ public class MainTableColumnModel { private static final Logger LOGGER = LoggerFactory.getLogger(MainTableColumnModel.class); public enum Type { + INDEX("index", Localization.lang("Index")), EXTRAFILE("extrafile", Localization.lang("File type")), FILES("files", Localization.lang("Linked files")), GROUPS("groups", Localization.lang("Groups")), @@ -132,7 +133,8 @@ public String getName() { } public String getDisplayName() { - if (Type.ICON_COLUMNS.contains(typeProperty.getValue()) && qualifierProperty.getValue().isBlank()) { + if ((Type.ICON_COLUMNS.contains(typeProperty.getValue()) && qualifierProperty.getValue().isBlank()) + || typeProperty.getValue() == Type.INDEX) { return typeProperty.getValue().getDisplayName(); } else { return FieldsUtil.getNameWithType(FieldFactory.parseField(qualifierProperty.getValue())); diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java index 545bd3c3d15..1990315fe01 100644 --- a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java @@ -115,6 +115,7 @@ public void setValues() { availableColumnsProperty.clear(); availableColumnsProperty.addAll( + new MainTableColumnModel(MainTableColumnModel.Type.INDEX), new MainTableColumnModel(MainTableColumnModel.Type.LINKED_IDENTIFIER), new MainTableColumnModel(MainTableColumnModel.Type.GROUPS), new MainTableColumnModel(MainTableColumnModel.Type.FILES), From f557d4fc6f2792735966d1d67a71d59f0b5754c5 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 18 Jan 2020 17:12:18 +0100 Subject: [PATCH 2/3] Added master table index column --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62fca1b2de1..c60e7a0e5a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# ### Changed +- We reintroduced the index column. [#5844](https://github.com/JabRef/jabref/pull/5844) + ### Fixed - We fixed an issue where the Medline fetcher was only working when JabRef was running from source. [#5645](https://github.com/JabRef/jabref/issues/5645) From 4a794a1b5e4167ce9300d1925bdb1822dd698b7f Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage Date: Sat, 18 Jan 2020 17:24:14 +0100 Subject: [PATCH 3/3] l10n --- src/main/resources/l10n/JabRef_en.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 800628cb28a..2659e0a5800 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2101,3 +2101,5 @@ Mark\ all\ changes\ as\ accepted=Mark all changes as accepted Unmark\ all\ changes=Unmark all changes Normalize\ newline\ characters=Normalize newline characters Normalizes\ all\ newline\ characters\ in\ the\ field\ content.=Normalizes all newline characters in the field content. + +Index=Index