Skip to content

Commit

Permalink
Reintroducing master table index column (#5844)
Browse files Browse the repository at this point in the history
* Added master table index column

* Added master table index column

* l10n
  • Loading branch information
calixtus authored and Siedlerchr committed Jan 21, 2020
1 parent 3656bf7 commit f4847b1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
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

0 comments on commit f4847b1

Please sign in to comment.