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

Reintroducing master table index column #5844

Merged
merged 3 commits into from
Jan 21, 2020
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<BibEntryTableViewModel, String> createIndexColumn(MainTableColumnModel columnModel) {
TableColumn<BibEntryTableViewModel, String> 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<BibEntryTableViewModel, String>()
.withText(text -> text)
.install(column);
column.setSortable(false);
return column;
}

/**
* Creates a column for group color bars.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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