Skip to content

Commit

Permalink
Reorderable columns in maintable for groups, URI, file and eprint (#5544
Browse files Browse the repository at this point in the history
)

* Initial

* Added combined identifier column

* Removed superfluous properties

* Added display names and refactored

* Fixed persistent state

* changelog

* Added columns to available set

* checkstyle

* Fixed bug in persistent view

* Refactored parse, rewording, cleanups

* Removed TableColumnsItemModel, cleanups

* Added migration and some minor tweaks

* Removed superfluous method getHeaderLabel

* Cleanups, seperating specialFieldsPreferences, added width-binding

* Refactored according to remarks

* Added Tests
  • Loading branch information
calixtus authored and tobiasdiez committed Nov 10, 2019
1 parent de4a1ae commit d1484f8
Show file tree
Hide file tree
Showing 20 changed files with 691 additions and 592 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- The entry editor is now open by default when JabRef starts up. [#5460](https://github.com/JabRef/jabref/issues/5460)
- We added a new ADS fetcher to use the new ADS API [#4949](https://github.com/JabRef/jabref/issues/4949)
- We added support of the [X11 primary selection](https://unix.stackexchange.com/a/139193/18033) [#2389](https://github.com/JabRef/jabref/issues/2389)
- We made the columns for groups, files and uri in the main table reorderable and merged the clickable icon columns for uri, url, doi and eprint. [#5544](https://github.com/JabRef/jabref/pull/5544)

### Fixed

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public class GUIGlobals {

public static CustomLocalDragboard localDragboard = new CustomLocalDragboard();

public static final int WIDTH_ICON_COL = 16 + 12; // add some additional space to improve appearance

public static final int WIDTH_ICON_COL_RANKING = 5 * 16; // Width of Ranking Icon Column

public static final String UNTITLED_TITLE = Localization.lang("untitled");

private GUIGlobals() {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jabref.gui.maintable;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -50,6 +52,17 @@ public ObservableValue<List<LinkedFile>> getLinkedFiles() {
return EasyBind.map(getField(StandardField.FILE), FileFieldParser::parse);
}

public ObservableValue<Map<Field,String>> getLinkedIdentifiers() {
SimpleObjectProperty<Map<Field,String>> linkedIdentifiers = new SimpleObjectProperty<>(new HashMap<>());

entry.getField(StandardField.URL).ifPresent(value -> linkedIdentifiers.getValue().put(StandardField.URL, value));
entry.getField(StandardField.DOI).ifPresent(value -> linkedIdentifiers.getValue().put(StandardField.DOI, value));
entry.getField(StandardField.URI).ifPresent(value -> linkedIdentifiers.getValue().put(StandardField.URI, value));
entry.getField(StandardField.EPRINT).ifPresent(value -> linkedIdentifiers.getValue().put(StandardField.EPRINT, value));

return linkedIdentifiers;
}

public ObservableValue<List<AbstractGroup>> getMatchedGroups(BibDatabaseContext database) {
SimpleObjectProperty<List<AbstractGroup>> matchedGroups = new SimpleObjectProperty<>(Collections.emptyList());

Expand Down
64 changes: 8 additions & 56 deletions src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,23 @@

public class ColumnPreferences {

public static final double DEFAULT_FIELD_LENGTH = 100;
private final boolean showFileColumn;
private final boolean showUrlColumn;
private final boolean preferDoiOverUrl;
private final boolean showEPrintColumn;
private final List<String> columnNames;
private final boolean specialFieldsEnabled;
private final boolean autoSyncSpecialFieldsToKeyWords;
private final boolean serializeSpecialFields;
public static final double DEFAULT_WIDTH = 100;
public static final double ICON_COLUMN_WIDTH = 16 + 12; // add some additional space to improve appearance

private final List<MainTableColumnModel> columns;
private final boolean extraFileColumnsEnabled;
private final Map<String, Double> columnWidths;
private final Map<String, SortType> columnSortType;

public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean preferDoiOverUrl, boolean showEPrintColumn, List<String> columnNames, boolean specialFieldsEnabled, boolean autoSyncSpecialFieldsToKeyWords, boolean serializeSpecialFields, boolean extraFileColumnsEnabled, Map<String, Double> columnWidths, Map<String, SortType> columnSortType) {
this.showFileColumn = showFileColumn;
this.showUrlColumn = showUrlColumn;
this.preferDoiOverUrl = preferDoiOverUrl;
this.showEPrintColumn = showEPrintColumn;
this.columnNames = columnNames;
this.specialFieldsEnabled = specialFieldsEnabled;
this.autoSyncSpecialFieldsToKeyWords = autoSyncSpecialFieldsToKeyWords;
this.serializeSpecialFields = serializeSpecialFields;
public ColumnPreferences(List<MainTableColumnModel> columns, boolean extraFileColumnsEnabled, Map<String, SortType> columnSortType) {
this.columns = columns;
this.extraFileColumnsEnabled = extraFileColumnsEnabled;
this.columnWidths = columnWidths;
this.columnSortType = columnSortType;
}

public boolean showFileColumn() {
return showFileColumn;
}

public boolean showUrlColumn() {
return showUrlColumn;
}

public boolean preferDoiOverUrl() {
return preferDoiOverUrl;
}

public boolean showEprintColumn() {
return showEPrintColumn;
}

public boolean getSpecialFieldsEnabled() { return specialFieldsEnabled; }

public boolean getAutoSyncSpecialFieldsToKeyWords() {
return autoSyncSpecialFieldsToKeyWords;
}

public boolean getSerializeSpecialFields() {
return serializeSpecialFields;
}

public boolean getExtraFileColumnsEnabled() { return extraFileColumnsEnabled; }

public List<String> getColumnNames() {
return columnNames;
}

public Map<String, Double> getColumnWidths() {
return columnWidths;
}

public double getColumnWidth(String columnName) {
return columnWidths.getOrDefault(columnName, DEFAULT_FIELD_LENGTH);
public List<MainTableColumnModel> getColumns() {
return columns;
}

public Map<String, SortType> getSortTypesForColumns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import javafx.beans.binding.Bindings;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.Label;

import org.jabref.gui.icon.JabRefIcon;
import org.jabref.logic.layout.LayoutFormatter;
import org.jabref.logic.layout.format.LatexToUnicodeFormatter;
import org.jabref.model.database.BibDatabase;
Expand All @@ -18,44 +15,40 @@
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.OrFields;

public class NormalTableColumn extends MainTableColumn<String> {
/**
* A column that displays the text-value of the field
*/
public class FieldColumn extends MainTableColumn<String> {

private final OrFields bibtexFields;

private final boolean isIconColumn;

private final Optional<JabRefIcon> iconLabel;

private final Optional<BibDatabase> database;

private final LayoutFormatter toUnicode = new LatexToUnicodeFormatter();
private final String columnName;

public NormalTableColumn(String columnName, OrFields bibtexFields, BibDatabase database) {
super(columnName);
this.columnName = columnName;
public FieldColumn(MainTableColumnModel model, OrFields bibtexFields, BibDatabase database) {
super(model);
this.bibtexFields = bibtexFields;
this.isIconColumn = false;
this.iconLabel = Optional.empty();
this.database = Optional.of(database);

setText(getDisplayName());
setCellValueFactory(param -> getColumnValue(param.getValue()));
}

/**
* Get the table column name to be displayed in the UI
*
* @return name to be displayed. null if field is empty.
*/
public String getDisplayName() {
return bibtexFields.getDisplayName();
}

@Override
public String getDisplayName() { return bibtexFields.getDisplayName(); }

public ObservableValue<String> getColumnValue(BibEntryTableViewModel entry) {
if (bibtexFields.isEmpty()) {
return null;
}

ObjectBinding<Field>[] dependencies = bibtexFields.stream().map(entry::getField).toArray(ObjectBinding[]::new);
ObjectBinding[] dependencies = bibtexFields.stream().map(entry::getField).toArray(ObjectBinding[]::new);
return Bindings.createStringBinding(() -> computeText(entry), dependencies);
}

Expand Down Expand Up @@ -83,20 +76,12 @@ private String computeText(BibEntryTableViewModel entry) {
return result;
}

public Node getHeaderLabel() {
if (isIconColumn) {
return iconLabel.map(JabRefIcon::getGraphicNode).get();
} else {
return new Label(getDisplayName());
}
}

/**
* Check if the value returned by getColumnValue() is the same as a simple check of the entry's field(s) would give
* The reasons for being different are (combinations may also happen): - The entry has a crossref where the field
* content is obtained from - The field has a string in it (which getColumnValue() resolves) - There are some alias
* fields. For example, if the entry has a date field but no year field, {@link
* BibEntry#getResolvedFieldOrAlias(String, BibDatabase)} will return the year value from the date field when
* BibEntry#getResolvedFieldOrAlias(Field, BibDatabase)} will return the year value from the date field when
* queried for year
*
* @param entry the BibEntry
Expand Down Expand Up @@ -126,7 +111,4 @@ public boolean isResolved(BibEntry entry) {
return (!resolvedFieldContent.equals(plainFieldContent));
}

public String getColumnName() {
return columnName;
}
}
21 changes: 15 additions & 6 deletions src/main/java/org/jabref/gui/maintable/MainTableColumn.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package org.jabref.gui.maintable;

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

abstract class MainTableColumn<T> extends TableColumn<BibEntryTableViewModel, T> {
import org.jabref.gui.util.BindingsHelper;

MainTableColumn(String text) {
super(text);
public class MainTableColumn<T> extends TableColumn<BibEntryTableViewModel, T> {

setCellValueFactory(param -> getColumnValue(param.getValue()));
private MainTableColumnModel model;

public MainTableColumn(MainTableColumnModel model) {
this.model = model;

BindingsHelper.bindBidirectional(
this.widthProperty(),
model.widthProperty(),
value -> this.setPrefWidth(model.widthProperty().getValue()),
value -> model.widthProperty().setValue(this.getWidth()));
}

abstract ObservableValue<T> getColumnValue(BibEntryTableViewModel entry);
public MainTableColumnModel getModel() { return model; }

public String getDisplayName() { return model.getDisplayName(); }
}
Loading

0 comments on commit d1484f8

Please sign in to comment.