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

Conversion of Preferences/TableColumnsTab to mvvm #5185

Merged
merged 41 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3d891ca
Initial
calixtus Aug 10, 2019
90c4444
Added contents of the list and bindings
calixtus Aug 11, 2019
eace48d
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 11, 2019
f5645ae
Initial
calixtus Aug 10, 2019
c0cfaba
Added contents of the list and bindings
calixtus Aug 11, 2019
1ea512c
Refactored specialFields
calixtus Aug 18, 2019
51a412d
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 18, 2019
79ff2f6
Added checking, storing and specialFields
calixtus Aug 18, 2019
146fe74
Fix specialField, l10n
calixtus Aug 18, 2019
d66383a
Added add and remove custom column, refactor
calixtus Aug 22, 2019
1a7a44d
Fixes unintentional sorting, added moving columns up and down
calixtus Aug 23, 2019
b4b11f2
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 23, 2019
0b6fcda
Refactoring, added update of MainTable
calixtus Aug 24, 2019
9c15843
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 24, 2019
7b6179e
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 25, 2019
0c77201
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 26, 2019
9282a82
Refactored to TableView, Added ComboBox
calixtus Aug 26, 2019
6992688
Fixed bug in ui update
calixtus Aug 30, 2019
b640388
Refactor and rewording to clean up
calixtus Aug 30, 2019
0412168
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 30, 2019
4b5b607
Changed table order reload icon
calixtus Aug 30, 2019
b6f728c
Refactor to save special fields column order, rewording
calixtus Aug 30, 2019
1f03afa
Refactor mvvm
calixtus Aug 30, 2019
4790442
Removed now superfluous restart message
calixtus Aug 30, 2019
e5759e4
l10n
calixtus Aug 30, 2019
043858a
Refactor for order
calixtus Aug 30, 2019
74c4e42
Merge branch 'preferences_mvvm_tablecolumns' of https://github.com/ca…
calixtus Aug 31, 2019
f1198f4
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Aug 31, 2019
551740a
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Sep 3, 2019
b368698
Added validation, cleanup, and minor fix
calixtus Sep 3, 2019
dd79607
Refactored FieldsUtil for reuse
calixtus Sep 3, 2019
4e78ae1
Resdolved merge errors
calixtus Sep 3, 2019
fbfa701
Refactored FieldsUtil for reuse
calixtus Sep 3, 2019
a5721cc
Fixes and cleanups
calixtus Sep 3, 2019
787896b
Refactor and cleanups
calixtus Sep 4, 2019
e766834
Merge remote-tracking branch 'upstream/master' into preferences_mvvm_…
calixtus Sep 4, 2019
a599372
Refactor to streams
calixtus Sep 4, 2019
dadd99a
l10n
calixtus Sep 4, 2019
6832901
l10n again
calixtus Sep 4, 2019
651f3c2
Cleanups
calixtus Sep 4, 2019
5c8b76d
Fix sorting bug
calixtus Sep 4, 2019
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
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public class BasePanel extends StackPane {
// Keeps track of the string dialog if it is open.
private final Map<Actions, BaseAction> actions = new HashMap<>();
private final SidePaneManager sidePaneManager;
private final BasePanelPreferences preferences;
private final ExternalFileTypes externalFileTypes;

private final EntryEditor entryEditor;
private final DialogService dialogService;
private MainTable mainTable;
private BasePanelPreferences preferences;
// To contain instantiated entry editors. This is to save time
// As most enums, this must not be null
private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING;
Expand Down Expand Up @@ -727,6 +727,8 @@ public void actionPerformed(ActionEvent e) {
}

public void setupMainPanel() {
preferences = BasePanelPreferences.from(Globals.prefs);

splitPane = new SplitPane();
splitPane.setOrientation(Orientation.VERTICAL);
adjustSplitter(); // restore last splitting state (before mainTable is created as creation affects the stored size of the entryEditors)
Expand Down
44 changes: 10 additions & 34 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -694,41 +694,17 @@ private MenuBar createMenu() {
);

if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) {
boolean menuItemAdded = false;
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) {
edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.RELEVANCE, factory));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) {
edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.QUALITY, factory));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) {
edit.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.PRINTED, factory));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager));
menuItemAdded = true;
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
edit.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager));
menuItemAdded = true;
}

if (menuItemAdded) {
edit.getItems().add(new SeparatorMenuItem());
}
edit.getItems().addAll(
SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.RANKING, factory, undoManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.RELEVANCE, factory),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.QUALITY, factory),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItemForActiveDatabase(SpecialField.PRINTED, factory),
SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.PRIORITY, factory, undoManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenuForActiveDatabase(SpecialField.READ_STATUS, factory, undoManager),
new SeparatorMenuItem()
);
}

//@formatter:off
library.getItems().addAll(
factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)),
Expand Down
48 changes: 29 additions & 19 deletions src/main/java/org/jabref/gui/maintable/ColumnPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@

import javafx.scene.control.TableColumn.SortType;

import org.jabref.model.entry.field.SpecialField;

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> normalColumns;
private final List<SpecialField> specialFieldColumns;
private final List<String> extraFileColumns;
private final boolean showEPrintColumn;
private final List<String> columnNames;
private final boolean specialFieldsEnabled;
private final boolean autoSyncSpecialFieldsToKeyWords;
private final boolean serializeSpecialFields;
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> normalColumns, List<SpecialField> specialFieldColumns, List<String> extraFileColumns, Map<String, Double> columnWidths, 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.normalColumns = normalColumns;
this.specialFieldColumns = specialFieldColumns;
this.extraFileColumns = extraFileColumns;
this.showEPrintColumn = showEPrintColumn;
this.columnNames = columnNames;
this.specialFieldsEnabled = specialFieldsEnabled;
this.autoSyncSpecialFieldsToKeyWords = autoSyncSpecialFieldsToKeyWords;
this.serializeSpecialFields = serializeSpecialFields;
this.extraFileColumnsEnabled = extraFileColumnsEnabled;
this.columnWidths = columnWidths;
this.columnSortType = columnSortType;
}
Expand All @@ -45,22 +47,30 @@ public boolean preferDoiOverUrl() {
}

public boolean showEprintColumn() {
return showEprintColumn;
return showEPrintColumn;
}

public List<String> getExtraFileColumns() {
return extraFileColumns;
public boolean getSpecialFieldsEnabled() { return specialFieldsEnabled; }

public boolean getAutoSyncSpecialFieldsToKeyWords() {
return autoSyncSpecialFieldsToKeyWords;
}

public List<SpecialField> getSpecialFieldColumns() {
return specialFieldColumns;
public boolean getSerializeSpecialFields() {
return serializeSpecialFields;
}

public boolean getExtraFileColumnsEnabled() { return extraFileColumnsEnabled; }

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

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

public double getPrefColumnWidth(String columnName) {
public double getColumnWidth(String columnName) {
return columnWidths.getOrDefault(columnName, DEFAULT_FIELD_LENGTH);
}

Expand Down
39 changes: 16 additions & 23 deletions src/main/java/org/jabref/gui/maintable/MainTableColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.gui.specialfields.SpecialFieldViewModel;
import org.jabref.gui.util.FieldsUtil;
import org.jabref.gui.util.OptionalValueTableCellFactory;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.gui.util.comparator.RankingFieldComparator;
Expand Down Expand Up @@ -81,12 +82,11 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
public List<TableColumn<BibEntryTableViewModel, ?>> createColumns() {
List<TableColumn<BibEntryTableViewModel, ?>> columns = new ArrayList<>();
columns.add(createGroupColumn());
// Add column for linked files

if (preferences.showFileColumn()) {
columns.add(createFileColumn());
}

// Add column for DOI/URL
if (preferences.showUrlColumn()) {
if (preferences.preferDoiOverUrl()) {
columns.add(createUrlOrDoiColumn(IconTheme.JabRefIcons.DOI, StandardField.DOI, StandardField.URL));
Expand All @@ -95,21 +95,19 @@ public MainTableColumnFactory(BibDatabaseContext database, ColumnPreferences pre
}
}

// Add column for eprints
if (preferences.showEprintColumn()) {
columns.add(createEprintColumn(IconTheme.JabRefIcons.WWW, StandardField.EPRINT));
}

// Add columns for other file types
columns.addAll(preferences.getExtraFileColumns().stream().map(this::createExtraFileColumn).collect(Collectors.toList()));

// Add 'normal' bibtex fields as configured in the preferences
columns.addAll(createNormalColumns());

// Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences
for (SpecialField field : preferences.getSpecialFieldColumns()) {
columns.add(createSpecialFieldColumn((field)));
}
preferences.getColumnNames().stream().map(FieldFactory::parseField).forEach(field -> {
if (field instanceof FieldsUtil.ExtraFilePseudoField) {
columns.add(createExtraFileColumn(field.getName()));
} else if (field instanceof SpecialField) {
columns.add(createSpecialFieldColumn((SpecialField) field));
} else {
columns.add(createNormalColumn(field));
}
});

return columns;
}
Expand Down Expand Up @@ -163,20 +161,15 @@ private Node createGroupColorRegion(BibEntryTableViewModel entry, List<AbstractG
return new Pane();
}

private List<TableColumn<BibEntryTableViewModel, ?>> createNormalColumns() {
List<TableColumn<BibEntryTableViewModel, ?>> columns = new ArrayList<>();

// Read table columns from preferences
for (String columnName : preferences.getNormalColumns()) {
NormalTableColumn column = new NormalTableColumn(columnName, FieldFactory.parseOrFields(columnName), database.getDatabase());
private TableColumn<BibEntryTableViewModel, ?> createNormalColumn(Field field) {
String columnName = field.getName();
NormalTableColumn column = new NormalTableColumn(columnName, FieldFactory.parseOrFields(columnName), database.getDatabase());
new ValueTableCellFactory<BibEntryTableViewModel, String>()
.withText(text -> text)
.install(column);
column.setSortable(true);
column.setPrefWidth(preferences.getPrefColumnWidth(columnName));
columns.add(column);
}
return columns;
column.setPrefWidth(preferences.getColumnWidth(columnName));
return column;
}

private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>> createSpecialFieldColumn(SpecialField specialField) {
Expand Down
29 changes: 6 additions & 23 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,12 @@ public static ContextMenu create(BibEntryTableViewModel entry, KeyBindingReposit
contextMenu.getItems().add(new SeparatorMenuItem());

if (Globals.prefs.getBoolean(JabRefPreferences.SPECIALFIELDSENABLED)) {
if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RANKING)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, panel));
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_RELEVANCE)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel));
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_QUALITY)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel));
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRINTED)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel));
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_PRIORITY)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel));
}

if (Globals.prefs.getBoolean(JabRefPreferences.SHOWCOLUMN_READ)) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel));
}
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, panel));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, panel));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, panel));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, panel));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, panel));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, panel));
}

contextMenu.getItems().add(new SeparatorMenuItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PreferencesDialogViewModel(DialogService dialogService, TaskExecutor task
new GeneralTabView(prefs),
new FileTabView(prefs),
new TablePrefsTab(prefs),
new TableColumnsTab(prefs, frame),
new TableColumnsTabView(prefs),
new PreviewTabView(prefs),
new ExternalTabView(prefs, frame),
new GroupsTabView(prefs),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.jabref.gui.preferences;

import java.util.Objects;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;

import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.UnknownField;

public class TableColumnsItemModel {

private final ObjectProperty<Field> field;
private final StringProperty name = new SimpleStringProperty("");
private final DoubleProperty length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH);
private final BooleanProperty editableProperty = new SimpleBooleanProperty(true);

public TableColumnsItemModel() {
this.field = new SimpleObjectProperty<>(new UnknownField(Localization.lang("New column")));
}

public TableColumnsItemModel(Field field) {
this.field = new SimpleObjectProperty<>(field);
this.editableProperty.setValue(this.field.get() instanceof UnknownField);
}

public TableColumnsItemModel(Field field, double length) {
this.field = new SimpleObjectProperty<>(field);
this.length.setValue(length);
this.editableProperty.setValue(this.field.get() instanceof UnknownField);
}

public void setField(Field field) {
this.field.set(field);
}

public Field getField() {
return field.get();
}

public ObservableValue<Field> fieldProperty() { return this.field; }

public void setName(String name) {
if (editableProperty.get()) {
field.setValue(new UnknownField(name));
}
}

public String getName() {
return field.get().getName();
}

public StringProperty nameProperty() { return this.name; }

public void setLength(double length) {
this.length.set(length);
}

public double getLength() {
return length.get();
}

public DoubleProperty lengthProperty() { return this.length; }

public ReadOnlyBooleanProperty editableProperty() { return editableProperty; }

@Override
public int hashCode() {
return Objects.hash(field);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof TableColumnsItemModel) {
return Objects.equals(this.field, ((TableColumnsItemModel) obj).field);
} else {
return false;
}
}
}
Loading