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

Reorderable columns in maintable for groups, URI, file and eprint #5544

Merged
merged 17 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
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
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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_COLUMN = 16 + 12; // add some additional space to improve appearance

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

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
28 changes: 3 additions & 25 deletions src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

public class ColumnPreferences {

public static final String QUALIFIER_SEPARATOR = ":";
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;
Expand All @@ -20,11 +18,7 @@ public class ColumnPreferences {
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;
public ColumnPreferences(List<String> columnNames, boolean specialFieldsEnabled, boolean autoSyncSpecialFieldsToKeyWords, boolean serializeSpecialFields, boolean extraFileColumnsEnabled, Map<String, Double> columnWidths, Map<String, SortType> columnSortType) {
this.columnNames = columnNames;
this.specialFieldsEnabled = specialFieldsEnabled;
this.autoSyncSpecialFieldsToKeyWords = autoSyncSpecialFieldsToKeyWords;
Expand All @@ -34,22 +28,6 @@ public ColumnPreferences(boolean showFileColumn, boolean showUrlColumn, boolean
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() {
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);
calixtus marked this conversation as resolved.
Show resolved Hide resolved
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;
}
}
32 changes: 26 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,35 @@
package org.jabref.gui.maintable;

import javafx.beans.value.ObservableValue;
import java.util.Optional;

import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;

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

public class MainTableColumn<T> extends TableColumn<BibEntryTableViewModel, T> {

MainTableColumn(String text) {
super(text);
private MainTableColumnModel model;

setCellValueFactory(param -> getColumnValue(param.getValue()));
private final Optional<JabRefIcon> iconLabel;

public MainTableColumn(MainTableColumnModel model) {
this.model = model;
this.iconLabel = Optional.empty();
}

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

public Node getHeaderLabel() {
calixtus marked this conversation as resolved.
Show resolved Hide resolved
if (model.getType() == MainTableColumnModel.Type.GROUPS || model.getType() == MainTableColumnModel.Type.FILES) {
return iconLabel.map(JabRefIcon::getGraphicNode).get();
} else {
return new Label(model.getDisplayName());
}
}

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