Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into allEntriesDuplicates
Browse files Browse the repository at this point in the history
* upstream/main:
  Adds three tests to verify the expected output from the getErroMessage function. The tests check the output message when ParserResult is empty, not empty, or has duplicates. (#10711)
  Extract calls to JabRefFrame and substitute with LibraryTabContainer (#10724)
  • Loading branch information
Siedlerchr committed Jan 2, 2024
2 parents c0f34cc + 37d0518 commit 2fe2b79
Show file tree
Hide file tree
Showing 50 changed files with 492 additions and 492 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/EntryTypeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void runFetcherWorker() {
Localization.lang("Return to dialog"));
if (addEntryFlag) {
new NewEntryAction(
libraryTab.frame(),
() -> libraryTab,
StandardEntryType.Article,
dialogService,
preferencesService,
Expand Down
61 changes: 24 additions & 37 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,31 +267,31 @@ private void initKeyBindings() {
getGlobalSearchBar().focus();
break;
case NEW_ARTICLE:
new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Article, dialogService, prefs, stateManager).execute();
break;
case NEW_BOOK:
new NewEntryAction(this, StandardEntryType.Book, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Book, dialogService, prefs, stateManager).execute();
break;
case NEW_INBOOK:
new NewEntryAction(this, StandardEntryType.InBook, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.InBook, dialogService, prefs, stateManager).execute();
break;
case NEW_MASTERSTHESIS:
new NewEntryAction(this, StandardEntryType.MastersThesis, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.MastersThesis, dialogService, prefs, stateManager).execute();
break;
case NEW_PHDTHESIS:
new NewEntryAction(this, StandardEntryType.PhdThesis, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.PhdThesis, dialogService, prefs, stateManager).execute();
break;
case NEW_PROCEEDINGS:
new NewEntryAction(this, StandardEntryType.Proceedings, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Proceedings, dialogService, prefs, stateManager).execute();
break;
case NEW_TECHREPORT:
new NewEntryAction(this, StandardEntryType.TechReport, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.TechReport, dialogService, prefs, stateManager).execute();
break;
case NEW_UNPUBLISHED:
new NewEntryAction(this, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.Unpublished, dialogService, prefs, stateManager).execute();
break;
case NEW_INPROCEEDINGS:
new NewEntryAction(this, StandardEntryType.InProceedings, dialogService, prefs, stateManager).execute();
new NewEntryAction(this::getCurrentLibraryTab, StandardEntryType.InProceedings, dialogService, prefs, stateManager).execute();
break;
case PASTE:
if (OS.OS_X) { // Workaround for a jdk issue that executes paste twice when using cmd+v in a TextField
Expand Down Expand Up @@ -406,11 +406,11 @@ public boolean quit() {

// Then ask if the user really wants to close, if the library has not been saved since last save.
List<String> filenames = new ArrayList<>();
for (int i = 0; i < tabbedPane.getTabs().size(); i++) {
LibraryTab libraryTab = getLibraryTabAt(i);
for (LibraryTab libraryTab : getLibraryTabs()) {
final BibDatabaseContext context = libraryTab.getBibDatabaseContext();

if (libraryTab.isModified() && (context.getLocation() == DatabaseLocation.LOCAL)) {
tabbedPane.getSelectionModel().select(i);
showLibraryTab(libraryTab);
if (!confirmClose(libraryTab)) {
return false;
}
Expand All @@ -419,6 +419,7 @@ public boolean quit() {
context.getDBMSSynchronizer().closeSharedDatabase();
context.clearDBMSSynchronizer();
}

AutosaveManager.shutdown(context);
BackupManager.shutdown(context, prefs.getFilePreferences().getBackupDirectory(), prefs.getFilePreferences().shouldCreateBackup());
context.getDatabasePath().map(Path::toAbsolutePath).map(Path::toString).ifPresent(filenames::add);
Expand Down Expand Up @@ -540,15 +541,6 @@ private void setDividerPosition() {
}
}

/**
* Returns the indexed LibraryTab.
*
* @param i Index of base
*/
public LibraryTab getLibraryTabAt(int i) {
return (LibraryTab) tabbedPane.getTabs().get(i);
}

/**
* Returns a list of all LibraryTabs in this frame.
*/
Expand All @@ -559,6 +551,7 @@ public List<LibraryTab> getLibraryTabs() {
.collect(Collectors.toList());
}

@Deprecated
public void showLibraryTabAt(int i) {
tabbedPane.getSelectionModel().select(i);
}
Expand Down Expand Up @@ -647,7 +640,7 @@ public void init() {
}

// Update search autocompleter with information for the correct database:
libraryTab.updateSearchManager();
globalSearchBar.setAutoCompleter(libraryTab.getAutoCompleter());

libraryTab.getUndoManager().postUndoRedoEvent();
libraryTab.getMainTable().requestFocus();
Expand All @@ -671,21 +664,6 @@ public LibraryTab getCurrentLibraryTab() {
return (LibraryTab) tabbedPane.getSelectionModel().getSelectedItem();
}

/**
* @return the BasePanel count.
*/
public int getBasePanelCount() {
return tabbedPane.getTabs().size();
}

/**
* @deprecated do not operate on tabs but on BibDatabaseContexts
*/
@Deprecated
public TabPane getTabbedPane() {
return tabbedPane;
}

/**
* This method causes all open LibraryTabs to set up their tables anew. When called from PreferencesDialogViewModel,
* this updates to the new settings. We need to notify all tabs about the changes to avoid problems when changing
Expand Down Expand Up @@ -961,6 +939,15 @@ public Stage getMainStage() {
return mainStage;
}

/**
* Refreshes the ui after preferences changes
*/
public void refresh() {
globalSearchBar.updateHintVisibility();
setupAllTables();
getLibraryTabs().forEach(panel -> panel.getMainTable().getTableModel().refresh());
}

/**
* The action concerned with closing the window.
*/
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class JabRefGUI {
private final List<ParserResult> toOpenTab = new ArrayList<>();

public JabRefGUI(Stage mainStage,
List<ParserResult> databases,
List<ParserResult> parserResults,
boolean isBlank,
PreferencesService preferencesService,
FileUpdateMonitor fileUpdateMonitor) {
this.parserResults = databases;
this.parserResults = parserResults;
this.isBlank = isBlank;
this.preferencesService = preferencesService;
this.fileUpdateMonitor = fileUpdateMonitor;
Expand Down Expand Up @@ -259,26 +259,23 @@ private void openDatabases() {
}

// Display warnings, if any
int tabNumber = 0;
for (ParserResult pr : parserResults) {
ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame, tabNumber++);
for (int tabNumber = 0; tabNumber < parserResults.size(); tabNumber++) {
// ToDo: Method needs to be rewritten, because the index of the parser result and of the libraryTab may not
// be identical, if there are also other tabs opened, that are not libraryTabs. Currently there are none,
// therefor for now this ok.
ParserResult pr = parserResults.get(tabNumber);
if (pr.hasWarnings()) {
ParserResultWarningDialog.showParserResultWarningDialog(pr, mainFrame.getDialogService());
mainFrame.showLibraryTabAt(tabNumber);
}
}

// After adding the databases, go through each and see if
// any post open actions need to be done. For instance, checking
// if we found new entry types that can be imported, or checking
// if the database contents should be modified due to new features
// in this version of JabRef.
// Note that we have to check whether i does not go over getBasePanelCount().
// This is because importToOpen might have been used, which adds to
// loadedDatabases, but not to getBasePanelCount()

for (int i = 0; (i < parserResults.size()) && (i < mainFrame.getBasePanelCount()); i++) {
ParserResult pr = parserResults.get(i);
LibraryTab libraryTab = mainFrame.getLibraryTabAt(i);

OpenDatabaseAction.performPostOpenActions(libraryTab, pr);
}
parserResults.forEach(pr -> OpenDatabaseAction.performPostOpenActions(pr, mainFrame.getDialogService()));

LOGGER.debug("Finished adding panels");
}
Expand Down
47 changes: 19 additions & 28 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.jabref.gui.autocompleter.AutoCompletePreferences;
import org.jabref.gui.autocompleter.PersonNameSuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.autosaveandbackup.AutosaveManager;
import org.jabref.gui.autosaveandbackup.BackupManager;
Expand Down Expand Up @@ -62,6 +63,7 @@
import org.jabref.model.database.event.BibDatabaseContextChangedEvent;
import org.jabref.model.database.event.EntriesAddedEvent;
import org.jabref.model.database.event.EntriesRemovedEvent;
import org.jabref.model.entry.Author;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.LinkedFile;
Expand All @@ -84,7 +86,7 @@
public class LibraryTab extends Tab {

private static final Logger LOGGER = LoggerFactory.getLogger(LibraryTab.class);
private final JabRefFrame frame;
private final LibraryTabContainer tabContainer;
private final CountingUndoManager undoManager;
private final DialogService dialogService;
private final PreferencesService preferencesService;
Expand Down Expand Up @@ -125,15 +127,15 @@ public class LibraryTab extends Tab {
private final TaskExecutor taskExecutor;

public LibraryTab(BibDatabaseContext bibDatabaseContext,
JabRefFrame frame,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
CountingUndoManager undoManager,
TaskExecutor taskExecutor) {
this.frame = Objects.requireNonNull(frame);
this.tabContainer = Objects.requireNonNull(tabContainer);
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
this.undoManager = undoManager;
this.dialogService = dialogService;
Expand Down Expand Up @@ -220,12 +222,12 @@ public Node createLoadingAnimationLayout() {
public void onDatabaseLoadingStarted() {
Node loadingLayout = createLoadingAnimationLayout();
getMainTable().placeholderProperty().setValue(loadingLayout);
frame.addTab(this, true);
tabContainer.addTab(this, true);
}

public void onDatabaseLoadingSucceed(ParserResult result) {
BibDatabaseContext context = result.getDatabaseContext();
OpenDatabaseAction.performPostOpenActions(this, result);
OpenDatabaseAction.performPostOpenActions(result, dialogService);

feedData(context);

Expand Down Expand Up @@ -411,10 +413,6 @@ public void setMode(BasePanelMode mode) {
this.mode = mode;
}

public JabRefFrame frame() {
return frame;
}

/**
* Removes the selected entries from the database
*
Expand Down Expand Up @@ -469,12 +467,6 @@ public void insertEntry(final BibEntry bibEntry) {
}
}

/**
* This method is called from JabRefFrame when the user wants to create a new entry or entries. It is necessary when the user would expect the added entry or one of the added entries to be selected in the entry editor
*
* @param entries The new entries.
*/

public void insertEntries(final List<BibEntry> entries) {
if (!entries.isEmpty()) {
bibDatabaseContext.getDatabase().insertEntries(entries);
Expand All @@ -488,9 +480,9 @@ public void insertEntries(final List<BibEntry> entries) {

this.changedProperty.setValue(true); // The database just changed.
if (preferencesService.getEntryEditorPreferences().shouldOpenOnNewEntry()) {
showAndEdit(entries.get(0));
showAndEdit(entries.getFirst());
}
clearAndSelect(entries.get(0));
clearAndSelect(entries.getFirst());
}
}

Expand All @@ -506,6 +498,7 @@ public void editEntryAndFocusField(BibEntry entry, Field field) {
private void createMainTable() {
mainTable = new MainTable(tableModel,
this,
tabContainer,
bibDatabaseContext,
preferencesService,
dialogService,
Expand Down Expand Up @@ -558,21 +551,21 @@ public void setupMainPanel() {
}

/**
* Set up auto completion for this database
* Set up autocompletion for this database
*/
private void setupAutoCompletion() {
AutoCompletePreferences autoCompletePreferences = preferencesService.getAutoCompletePreferences();
if (autoCompletePreferences.shouldAutoComplete()) {
suggestionProviders = new SuggestionProviders(getDatabase(), Globals.journalAbbreviationRepository, autoCompletePreferences);
} else {
// Create empty suggestion providers if auto completion is deactivated
// Create empty suggestion providers if auto-completion is deactivated
suggestionProviders = new SuggestionProviders();
}
searchAutoCompleter = new PersonNameSuggestionProvider(FieldFactory.getPersonNameFields(), getDatabase());
}

public void updateSearchManager() {
frame.getGlobalSearchBar().setAutoCompleter(searchAutoCompleter);
public SuggestionProvider<Author> getAutoCompleter() {
return searchAutoCompleter;
}

public EntryEditor getEntryEditor() {
Expand Down Expand Up @@ -837,7 +830,7 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
JabRefFrame frame,
LibraryTabContainer tabContainer,
FileUpdateMonitor fileUpdateMonitor,
BibEntryTypesManager entryTypesManager,
CountingUndoManager undoManager,
Expand All @@ -847,7 +840,7 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi

LibraryTab newTab = new LibraryTab(
context,
frame,
tabContainer,
dialogService,
preferencesService,
stateManager,
Expand All @@ -866,7 +859,7 @@ public static LibraryTab createLibraryTab(BackgroundTask<ParserResult> dataLoadi
}

public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext,
JabRefFrame frame,
LibraryTabContainer tabContainer,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
Expand All @@ -876,18 +869,16 @@ public static LibraryTab createLibraryTab(BibDatabaseContext databaseContext,
TaskExecutor taskExecutor) {
Objects.requireNonNull(databaseContext);

LibraryTab libraryTab = new LibraryTab(
return new LibraryTab(
databaseContext,
frame,
tabContainer,
dialogService,
preferencesService,
stateManager,
fileUpdateMonitor,
entryTypesManager,
(CountingUndoManager) undoManager,
taskExecutor);

return libraryTab;
}

private class GroupTreeListener {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/LibraryTabContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.jabref.model.database.BibDatabaseContext;

public interface LibraryTabContainer {
LibraryTab getLibraryTabAt(int i);

List<LibraryTab> getLibraryTabs();

LibraryTab getCurrentLibraryTab();
Expand All @@ -20,4 +18,9 @@ public interface LibraryTabContainer {
void closeTab(LibraryTab libraryTab);

void closeCurrentTab();

/**
* Refreshes the ui after changes to the preferences
*/
void refresh();
}
Loading

0 comments on commit 2fe2b79

Please sign in to comment.