From f2e5bf233551a19b785ea10ba9aaa1fdc7a38bde Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 3 Nov 2019 20:43:16 +0100 Subject: [PATCH] Select newly added jstyle in table to prevent exception (#5556) Fixes #5452 --- .../gui/openoffice/StyleSelectDialogViewModel.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index ded9dd93b79..e318671c6e1 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -47,13 +47,7 @@ public StyleSelectDialogViewModel(DialogService dialogService, StyleLoader loade styles.addAll(loadStyles()); String currentStyle = preferences.getCurrentStyle(); - Optional lastUsedStyle = styles.stream().filter(style -> style.getStylePath().equals(currentStyle)).findFirst(); - - if (lastUsedStyle.isPresent()) { - selectedItem.setValue(lastUsedStyle.get()); - } else { - selectedItem.setValue(styles.get(0)); - } + selectedItem.setValue(getStyleOrDefault(currentStyle)); } public StyleSelectItemViewModel fromOOBibStyle(OOBibStyle style) { @@ -75,6 +69,7 @@ public void addStyleFile() { if (loader.addStyleIfValid(stylePath)) { preferences.setCurrentStyle(stylePath); styles.setAll(loadStyles()); + selectedItem.setValue(getStyleOrDefault(stylePath)); } else { dialogService.showErrorDialogAndWait(Localization.lang("Invalid style selected"), Localization.lang("You must select a valid style file.")); } @@ -129,4 +124,8 @@ public void storePrefs() { preferences.setCurrentStyle(selectedItem.getValue().getStylePath()); preferencesService.setOpenOfficePreferences(preferences); } + + private StyleSelectItemViewModel getStyleOrDefault(String stylePath) { + return styles.stream().filter(style -> style.getStylePath().equals(stylePath)).findFirst().orElse(styles.get(0)); + } }