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

Special field code maintenance #7078

Merged
merged 1 commit into from
Nov 6, 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
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,18 +740,18 @@ private MenuBar createMenu() {
new SeparatorMenuItem(),
// ToDo: SpecialField needs the active BasePanel to mark it as changed.
// Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead!
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, stateManager)
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager),
SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager)
);
}

// @formatter:off
library.getItems().addAll(
factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, Globals.prefs, stateManager)),
factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)),
factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)),
factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)),

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/jabref/gui/maintable/CellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.preferences.PreferencesService;

public class CellFactory {

private final Map<Field, JabRefIcon> TABLE_ICONS = new HashMap<>();

public CellFactory(ExternalFileTypes externalFileTypes, UndoManager undoManager) {
public CellFactory(ExternalFileTypes externalFileTypes, PreferencesService preferencesService, UndoManager undoManager) {
JabRefIcon icon;
icon = IconTheme.JabRefIcons.PDF_FILE;
// icon.setToo(Localization.lang("Open") + " PDF");
Expand Down Expand Up @@ -61,36 +62,36 @@ public CellFactory(ExternalFileTypes externalFileTypes, UndoManager undoManager)
TABLE_ICONS.put(fileType.getField(), icon);
}

SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager);
SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE, preferencesService, undoManager);
icon = relevanceViewModel.getIcon();
// icon.setToolTipText(relevanceViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.RELEVANCE, icon);

SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY, undoManager);
SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY, preferencesService, undoManager);
icon = qualityViewModel.getIcon();
// icon.setToolTipText(qualityViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.QUALITY, icon);

// Ranking item in the menu uses one star
SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING, undoManager);
SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING, preferencesService, undoManager);
icon = rankViewModel.getIcon();
// icon.setToolTipText(rankViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.RANKING, icon);

// Priority icon used for the menu
SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager);
SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY, preferencesService, undoManager);
icon = priorityViewModel.getIcon();
// icon.setToolTipText(priorityViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.PRIORITY, icon);

// Read icon used for menu
SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager);
SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS, preferencesService, undoManager);
icon = readViewModel.getIcon();
// icon.setToolTipText(readViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.READ_STATUS, icon);

// Print icon used for menu
SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED, undoManager);
SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED, preferencesService, undoManager);
icon = printedViewModel.getIcon();
// icon.setToolTipText(printedViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.PRINTED, icon);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public MainTable(MainTableDataModel model,
dialogService,
stateManager,
preferencesService,
undoManager,
Globals.clipboardManager))
.setOnDragDetected(this::handleOnDragDetected)
.setOnDragDropped(this::handleOnDragDropped)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public MainTableColumnFactory(BibDatabaseContext database,
this.columnPreferences = preferencesService.getColumnPreferences();
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.dialogService = dialogService;
this.cellFactory = new CellFactory(externalFileTypes, undoManager);
this.cellFactory = new CellFactory(externalFileTypes, preferencesService, undoManager);
this.undoManager = undoManager;
}

Expand Down Expand Up @@ -214,7 +214,7 @@ private TableColumn<BibEntryTableViewModel, Map<Field, String>> createIdentifier
* Creates a column that displays a {@link SpecialField}
*/
private TableColumn<BibEntryTableViewModel, Optional<SpecialFieldValueViewModel>> createSpecialFieldColumn(MainTableColumnModel columnModel) {
return new SpecialFieldColumn(columnModel, undoManager);
return new SpecialFieldColumn(columnModel, preferencesService, undoManager);
}

/**
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/jabref/gui/maintable/RightClickMenu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.maintable;

import javax.swing.undo.UndoManager;

import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.SeparatorMenuItem;
Expand Down Expand Up @@ -37,6 +39,7 @@ public static ContextMenu create(BibEntryTableViewModel entry,
DialogService dialogService,
StateManager stateManager,
PreferencesService preferencesService,
UndoManager undoManager,
ClipBoardManager clipBoardManager) {
ContextMenu contextMenu = new ContextMenu();
ActionFactory factory = new ActionFactory(keyBindingRepository);
Expand All @@ -54,12 +57,12 @@ public static ContextMenu create(BibEntryTableViewModel entry,
contextMenu.getItems().add(new SeparatorMenuItem());

if (preferencesService.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) {
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager));
}

contextMenu.getItems().add(new SeparatorMenuItem());
Expand Down Expand Up @@ -94,7 +97,7 @@ private static Menu createCopySubMenu(LibraryTab libraryTab,
copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_KEY_AND_LINK, new CopyMoreAction(StandardActions.COPY_KEY_AND_LINK, dialogService, stateManager, clipBoardManager, preferencesService)));

// the submenu will behave dependent on what style is currently selected (citation/preview)
PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences();
PreviewPreferences previewPreferences = preferencesService.getPreviewPreferences();
PreviewLayout style = previewPreferences.getCurrentPreviewStyle();
if (style instanceof CitationStylePreviewLayout) {
copySpecialMenu.getItems().add(factory.createMenuItem(StandardActions.COPY_CITATION_HTML, new CopyCitationAction(CitationStyleOutputFormat.HTML, dialogService, stateManager, clipBoardManager, previewPreferences)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.model.entry.field.SpecialFieldValue;
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;
import org.controlsfx.control.Rating;
Expand All @@ -35,14 +36,16 @@
*/
public class SpecialFieldColumn extends MainTableColumn<Optional<SpecialFieldValueViewModel>> {

private final PreferencesService preferencesService;
private final UndoManager undoManager;

public SpecialFieldColumn(MainTableColumnModel model, UndoManager undoManager) {
public SpecialFieldColumn(MainTableColumnModel model, PreferencesService preferencesService, UndoManager undoManager) {
super(model);
this.preferencesService = preferencesService;
this.undoManager = undoManager;

SpecialField specialField = (SpecialField) FieldFactory.parseField(model.getQualifier());
SpecialFieldViewModel specialFieldViewModel = new SpecialFieldViewModel(specialField, undoManager);
SpecialFieldViewModel specialFieldViewModel = new SpecialFieldViewModel(specialField, preferencesService, undoManager);

Node headerGraphic = specialFieldViewModel.getIcon().getGraphicNode();
Tooltip.install(headerGraphic, new Tooltip(specialFieldViewModel.getLocalization()));
Expand Down Expand Up @@ -98,7 +101,7 @@ private Rating createSpecialRating(BibEntryTableViewModel entry, SpecialFieldVal
Rating ranking = new Rating();
ranking.setRating(value.getValue().toRating());
EasyBind.subscribe(ranking.ratingProperty(), rating ->
new SpecialFieldViewModel(SpecialField.RANKING, undoManager)
new SpecialFieldViewModel(SpecialField.RANKING, preferencesService, undoManager)
.setSpecialFieldValue(entry.getEntry(), SpecialFieldValue.getRating(rating.intValue())));

return ranking;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/jabref/gui/specialfields/SpecialFieldAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.util.List;
import java.util.Objects;

import javax.swing.undo.UndoManager;

import org.jabref.gui.DialogService;
import org.jabref.gui.Globals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionHelper;
Expand All @@ -16,6 +17,7 @@
import org.jabref.model.FieldChange;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.SpecialField;
import org.jabref.preferences.PreferencesService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,6 +31,8 @@ public class SpecialFieldAction extends SimpleCommand {
private final boolean nullFieldIfValueIsTheSame;
private final String undoText;
private final DialogService dialogService;
private final PreferencesService preferencesService;
private final UndoManager undoManager;
private final StateManager stateManager;

/**
Expand All @@ -40,13 +44,17 @@ public SpecialFieldAction(JabRefFrame frame,
boolean nullFieldIfValueIsTheSame,
String undoText,
DialogService dialogService,
PreferencesService preferencesService,
UndoManager undoManager,
StateManager stateManager) {
this.frame = frame;
this.specialField = specialField;
this.value = value;
this.nullFieldIfValueIsTheSame = nullFieldIfValueIsTheSame;
this.undoText = undoText;
this.dialogService = dialogService;
this.preferencesService = preferencesService;
this.undoManager = undoManager;
this.stateManager = stateManager;

this.executable.bind(ActionHelper.needsEntriesSelected(stateManager));
Expand All @@ -67,8 +75,8 @@ public void execute() {
value,
bibEntry,
nullFieldIfValueIsTheSame,
Globals.prefs.getSpecialFieldsPreferences().isKeywordSyncEnabled(),
Globals.prefs.getKeywordDelimiter());
preferencesService.getSpecialFieldsPreferences().isKeywordSyncEnabled(),
preferencesService.getKeywordDelimiter());

for (FieldChange change : changes) {
ce.addEdit(new UndoableFieldChange(change));
Expand Down Expand Up @@ -97,7 +105,7 @@ public void execute() {
private String getTextDone(SpecialField field, String... params) {
Objects.requireNonNull(params);

SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field, frame.getUndoManager());
SpecialFieldViewModel viewModel = new SpecialFieldViewModel(field, preferencesService, undoManager);

if (field.isSingleValueField() && (params.length == 1) && (params[0] != null)) {
// Single value fields can be toggled only
Expand Down
Loading