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

Fix NPE with bibdatabasecontext in preview style dialog #4278

Merged
merged 1 commit into from
Aug 20, 2018
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
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
this.preview = new PreviewPanel(this, getBibDatabaseContext(), preferences.getKeyBindings(), preferences.getPreviewPreferences(), dialogService, externalFileTypes);
frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(preview);


}

@Subscribe
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/jabref/gui/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.StringReader;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -70,18 +71,18 @@ public class PreviewPanel extends ScrollPane implements SearchQueryHighlightList
/**
* If a database is set, the preview will attempt to resolve strings in the previewed entry using that database.
*/
private Optional<BibDatabaseContext> databaseContext = Optional.empty();
private BibDatabaseContext databaseContext;
private final WebView previewView;
private Optional<Future<?>> citationStyleFuture = Optional.empty();

private final NewDroppedFileHandler fileHandler;

/**
* @param panel (may be null) Only set this if the preview is associated to the main window.
* @param databaseContext (may be null) Used for resolving pdf directories for links.
* @param databaseContext Used for resolving pdf directories for links. Must not be null.
*/
public PreviewPanel(BasePanel panel, BibDatabaseContext databaseContext, KeyBindingRepository keyBindingRepository, PreviewPreferences preferences, DialogService dialogService, ExternalFileTypes externalFileTypes) {
this.databaseContext = Optional.ofNullable(databaseContext);
this.databaseContext = Objects.requireNonNull(databaseContext);
this.basePanel = Optional.ofNullable(panel);
this.dialogService = dialogService;
this.clipBoardManager = Globals.clipboardManager;
Expand Down Expand Up @@ -198,7 +199,7 @@ private ContextMenu createPopupMenu() {
}

public void setDatabaseContext(BibDatabaseContext databaseContext) {
this.databaseContext = Optional.ofNullable(databaseContext);
this.databaseContext = databaseContext;
}

public Optional<BasePanel> getBasePanel() {
Expand Down Expand Up @@ -281,7 +282,7 @@ public void update() {
if (layout.isPresent()) {
StringBuilder sb = new StringBuilder();
bibEntry.ifPresent(entry -> sb.append(layout.get()
.doLayout(entry, databaseContext.map(BibDatabaseContext::getDatabase).orElse(null))));
.doLayout(entry, databaseContext.getDatabase())));
setPreviewLabel(sb.toString());
} else if (basePanel.isPresent() && bibEntry.isPresent()) {
Future<?> citationStyleWorker = BackgroundTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jabref.logic.openoffice.StyleLoader;
import org.jabref.logic.util.StandardFileType;
import org.jabref.logic.util.TestEntry;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -134,7 +135,7 @@ private void init() {
// Create a preview panel for previewing styles
// Must be done before creating the table to avoid NPEs
DefaultTaskExecutor.runInJavaFXThread(() -> {
preview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), dialogService, ExternalFileTypes.getInstance());
preview = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), dialogService, ExternalFileTypes.getInstance());
// Use the test entry from the Preview settings tab in Preferences:
preview.setEntry(prevEntry);
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/preftabs/PreviewPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void setupLogic() {
btnTest.setOnAction(event -> {
try {
DefaultTaskExecutor.runInJavaFXThread(() -> {
PreviewPanel testPane = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), dialogService, externalFileTypes);
PreviewPanel testPane = new PreviewPanel(null, new BibDatabaseContext(), Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), dialogService, externalFileTypes);
if (chosen.getSelectionModel().getSelectedItems().isEmpty()) {
testPane.setFixedLayout(layout.getText());
testPane.setEntry(TestEntry.getTestEntry());
Expand Down