Skip to content

Commit

Permalink
Add option to display entry preview as tab in entry editor (#5451)
Browse files Browse the repository at this point in the history
* Add option to display entry preview as tab in entry editor

Adds the entry preview as a tab. Fixes #5244. Plus a bit of refactoring

* Fix checkstyle

* Fix checkstyle part 2
  • Loading branch information
tobiasdiez authored Oct 16, 2019
1 parent aa4585d commit e36daae
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 90 deletions.
4 changes: 1 addition & 3 deletions .idea/runConfigurations/JabRef_Main.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

- We added a short DOI field formatter which shortens DOI to more human-readable form. [koppor#343](https://github.com/koppor/jabref/issues/343)
- We improved the display of group memberships by adding multiple colored bars if the entry belongs to more than one group. [#4574](https://github.com/JabRef/jabref/issues/4574)
- We added an option to show the preview as an extra tab in the entry editor (instead of in a split view). [#5244](https://github.com/JabRef/jabref/issues/5244)

### Fixed

Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ private void createMainTable() {
String clearSearch = "clearSearch";
mainTable.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLEAR_SEARCH), clearSearch);
mainTable.getActionMap().put(clearSearch, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// need to close these here, b/c this action overshadows the responsible actions when the main table is selected
Expand All @@ -697,9 +697,9 @@ public void actionPerformed(ActionEvent e) {
}
}
});
mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Expand All @@ -710,7 +710,7 @@ public void actionPerformed(ActionEvent e) {
}
});
mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Expand All @@ -721,7 +721,7 @@ public void actionPerformed(ActionEvent e) {
}
});
mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Expand Down Expand Up @@ -749,10 +749,8 @@ public void setupMainPanel() {
splitPane.getItems().add(pane);

// Set up name autocompleter for search:
executorService.execute(() -> {
instantiateSearchAutoCompleter();
setupAutoCompletion();
});
setupAutoCompletion();
executorService.execute(this::instantiateSearchAutoCompleter);
this.getDatabase().registerListener(new SearchAutoCompleteListener());

// Saves the divider position as soon as it changes
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,27 @@

import javafx.scene.control.Tooltip;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.preferences.JabRefPreferences;

public class DeprecatedFieldsTab extends FieldsEditorTab {
public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService) {
super(false, databaseContext, suggestionProviders, undoManager, dialogService);

private final BibEntryTypesManager entryTypesManager;

public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationLoader journalAbbreviationLoader) {
super(false, databaseContext, suggestionProviders, undoManager, dialogService, preferences, externalFileTypes, taskExecutor, journalAbbreviationLoader);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
setTooltip(new Tooltip(Localization.lang("Show deprecated BibTeX fields")));
Expand All @@ -32,7 +40,7 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProvide

@Override
protected SortedSet<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = Globals.entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
if (entryType.isPresent()) {
return entryType.get().getDeprecatedFields()
.stream()
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.GUIGlobals;
Expand Down Expand Up @@ -262,22 +263,23 @@ private void navigateToNextEntry() {
}

private List<EntryEditorTab> createTabs() {
// Preview tab
entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, Globals.prefs, ExternalFileTypes.getInstance()));

// Required fields
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));

// Optional fields
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));

// Other fields
entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager,
entryEditorPreferences.getCustomTabFieldNames(), dialogService));
entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, entryEditorPreferences.getCustomTabFieldNames(), dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));

// General fields from preferences
for (Map.Entry<String, Set<Field>> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) {
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, panel.getSuggestionProviders(), undoManager, dialogService));
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));
}

// Special tabs
Expand Down
55 changes: 37 additions & 18 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.stream.Stream;

Expand All @@ -22,17 +23,19 @@
import javafx.scene.layout.Region;
import javafx.scene.layout.RowConstraints;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.FieldEditors;
import org.jabref.gui.fieldeditors.FieldNameLabel;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.preferences.JabRefPreferences;

/**
* A single tab displayed in the EntryEditor holding several FieldEditors.
Expand All @@ -43,17 +46,25 @@ abstract class FieldsEditorTab extends EntryEditorTab {
private final boolean isCompressed;
private final SuggestionProviders suggestionProviders;
private final DialogService dialogService;
private final JabRefPreferences preferences;
private final ExternalFileTypes externalFileTypes;
private final TaskExecutor taskExecutor;
private final JournalAbbreviationLoader journalAbbreviationLoader;
private PreviewPanel previewPanel;
private UndoManager undoManager;
private Collection<Field> fields = new ArrayList<>();
private GridPane gridPane;

public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService) {
public FieldsEditorTab(boolean compressed, BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationLoader journalAbbreviationLoader) {
this.isCompressed = compressed;
this.databaseContext = databaseContext;
this.suggestionProviders = suggestionProviders;
this.undoManager = undoManager;
this.dialogService = dialogService;
this.databaseContext = Objects.requireNonNull(databaseContext);
this.suggestionProviders = Objects.requireNonNull(suggestionProviders);
this.undoManager = Objects.requireNonNull(undoManager);
this.dialogService = Objects.requireNonNull(dialogService);
this.preferences = Objects.requireNonNull(preferences);
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.taskExecutor = Objects.requireNonNull(taskExecutor);
this.journalAbbreviationLoader = Objects.requireNonNull(journalAbbreviationLoader);
}

private static void addColumn(GridPane gridPane, int columnIndex, List<Label> nodes) {
Expand All @@ -64,10 +75,10 @@ private static void addColumn(GridPane gridPane, int columnIndex, Stream<Parent>
gridPane.addColumn(columnIndex, nodes.toArray(Node[]::new));
}

private void setupPanel(BibEntry entry, boolean compressed, SuggestionProviders suggestionProviders, UndoManager undoManager) {
private void setupPanel(BibEntry entry, boolean compressed) {
// The preferences might be not initialized in tests -> return immediately
// TODO: Replace this ugly workaround by proper injection propagation
if (Globals.prefs == null) {
if (preferences == null) {
return;
}

Expand All @@ -80,9 +91,9 @@ private void setupPanel(BibEntry entry, boolean compressed, SuggestionProviders

List<Label> labels = new ArrayList<>();
for (Field field : fields) {
FieldEditorFX fieldEditor = FieldEditors.getForField(field, Globals.TASK_EXECUTOR, dialogService,
Globals.journalAbbreviationLoader.getRepository(Globals.prefs.getJournalAbbreviationPreferences()),
Globals.prefs, databaseContext, entry.getType(), suggestionProviders, undoManager);
FieldEditorFX fieldEditor = FieldEditors.getForField(field, taskExecutor, dialogService,
journalAbbreviationLoader.getRepository(preferences.getJournalAbbreviationPreferences()),
preferences, databaseContext, entry.getType(), suggestionProviders, undoManager);
fieldEditor.bindToEntry(entry);

editors.put(field, fieldEditor);
Expand Down Expand Up @@ -164,19 +175,25 @@ public boolean shouldShow(BibEntry entry) {
@Override
protected void bindToEntry(BibEntry entry) {
initPanel();
setupPanel(entry, isCompressed, suggestionProviders, undoManager);
setupPanel(entry, isCompressed);

previewPanel.setEntry(entry);
if (previewPanel != null) {
previewPanel.setEntry(entry);
}
}

@Override
protected void nextPreviewStyle() {
previewPanel.nextPreviewStyle();
if (previewPanel != null) {
previewPanel.nextPreviewStyle();
}
}

@Override
protected void previousPreviewStyle() {
previewPanel.previousPreviewStyle();
if (previewPanel != null) {
previewPanel.previousPreviewStyle();
}
}

protected abstract SortedSet<Field> determineFieldsToShow(BibEntry entry);
Expand All @@ -190,8 +207,6 @@ private void initPanel() {
gridPane = new GridPane();
gridPane.getStyleClass().add("editorPane");

previewPanel = new PreviewPanel(databaseContext, dialogService, ExternalFileTypes.getInstance(), Globals.getKeyPrefs(), Globals.prefs);

// Warp everything in a scroll-pane
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
Expand All @@ -200,7 +215,11 @@ private void initPanel() {
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);

SplitPane container = new SplitPane(scrollPane, previewPanel);
SplitPane container = new SplitPane(scrollPane);
if (!preferences.getPreviewPreferences().showPreviewAsExtraTab()) {
previewPanel = new PreviewPanel(databaseContext, dialogService, externalFileTypes, preferences.getKeyBindingRepository(), preferences);
container.getItems().add(previewPanel);
}

setContent(container);
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/jabref/gui/entryeditor/OptionalFields2Tab.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@

import javafx.scene.control.Tooltip;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.preferences.JabRefPreferences;

public class OptionalFields2Tab extends FieldsEditorTab {
public OptionalFields2Tab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService) {
super(true, databaseContext, suggestionProviders, undoManager, dialogService);

private final BibEntryTypesManager entryTypesManager;

public OptionalFields2Tab(BibDatabaseContext databaseContext, SuggestionProviders suggestionProviders, UndoManager undoManager, DialogService dialogService, JabRefPreferences preferences, BibEntryTypesManager entryTypesManager, ExternalFileTypes externalFileTypes, TaskExecutor taskExecutor, JournalAbbreviationLoader journalAbbreviationLoader) {
super(true, databaseContext, suggestionProviders, undoManager, dialogService, preferences, externalFileTypes, taskExecutor, journalAbbreviationLoader);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Optional fields 2"));
setTooltip(new Tooltip(Localization.lang("Show optional fields")));
Expand All @@ -29,7 +37,7 @@ public OptionalFields2Tab(BibDatabaseContext databaseContext, SuggestionProvider

@Override
protected SortedSet<Field> determineFieldsToShow(BibEntry entry) {
Optional<BibEntryType> entryType = Globals.entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), databaseContext.getMode());
if (entryType.isPresent()) {
return entryType.get().getSecondaryOptionalNotDeprecatedFields();
} else {
Expand Down
Loading

0 comments on commit e36daae

Please sign in to comment.