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

Extract calls to JabRefFrame and substitute with LibraryTabContainer #10724

Merged
merged 33 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
21af9d4
Extracted frame out of EditAction
calixtus Dec 23, 2023
6dd80a1
Extracted frame out of EditAction
calixtus Dec 23, 2023
a26b385
Extracted frame out of NewEntryAction
calixtus Dec 23, 2023
d78cdf6
Extracted frame out of MergeReviewIntoCommentAction
calixtus Dec 23, 2023
ba056ff
Removed getTabbedPane and getBasePanelCount
calixtus Dec 23, 2023
97b44b4
Extracted call to libraryTab.frame() out of MainTableContextHeaderMenu
calixtus Dec 23, 2023
e04b3bd
Extracted call to frame() out of RightClickMenu
calixtus Dec 23, 2023
87151fe
Extracted call to frame() out of SaveDatabaseActionTest
calixtus Dec 23, 2023
53c4717
Extracted calls to JabRefFrame
calixtus Dec 24, 2023
449a0de
Extracted calls to JabRefFrame from NewSubLibraryAction and ConnectTo…
calixtus Dec 25, 2023
ff3a7a7
Extracted calls to JabRefFrame from GenerateCitationKeyAction
calixtus Dec 25, 2023
d2870bc
Extracted calls to JabRefFrame from ImportCommand
calixtus Dec 25, 2023
f4fe1da
Extracted calls to JabRefFrame from ExportCommand
calixtus Dec 25, 2023
f2dccb5
Extracted calls to JabRefFrame from UndoRedoAction
calixtus Dec 25, 2023
4894246
Extracted calls to JabRefFrame from SaveAllAction
calixtus Dec 25, 2023
98c641a
Extracted calls to JabRefFrame from LookupIdentifierAction
calixtus Dec 25, 2023
217462f
Extracted calls to JabRefFrame from StartNewStudyAction
calixtus Dec 25, 2023
84c361b
Extracted calls to JabRefFrame from GlobalSearchBar
calixtus Dec 25, 2023
022bfb0
Extracted calls to JabRefFrame from CleanupAction
calixtus Dec 25, 2023
8093e5f
Extracted calls to JabRefFrame from DuplicateSearch
calixtus Dec 25, 2023
0599297
Extracted calls to JabRefFrame from ReplaceStringAction
calixtus Dec 25, 2023
1074e5e
Extracted calls to JabRefFrame from OpenEntryEditorAction
calixtus Dec 25, 2023
9a2cb6e
Extracted calls to JabRefFrame from PreviewSwitchAction
calixtus Dec 25, 2023
6eabadd
Extracted calls to JabRefFrame from IntegrityCheckAction
calixtus Dec 25, 2023
996e35b
Extracted calls to JabRefFrame from AbbreviateAction
calixtus Dec 25, 2023
a4314ae
Extracted calls to JabRefFrame from GlobalSearchBarTest
calixtus Dec 25, 2023
7bd7f60
Switched to suppliers
calixtus Dec 25, 2023
b4a359a
Reworded for consistency
calixtus Dec 25, 2023
396be2d
Mark index based tab selectors as deprecated
calixtus Dec 25, 2023
8382e20
Removed unused arg
calixtus Dec 25, 2023
faa2e27
Removed deprecated index based tab selector
calixtus Dec 25, 2023
7446632
Applied suggestions from pr comments
calixtus Dec 26, 2023
eb9fe06
Merge branch 'main' into extract-frame
calixtus Dec 30, 2023
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
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
calixtus marked this conversation as resolved.
Show resolved Hide resolved
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();
calixtus marked this conversation as resolved.
Show resolved Hide resolved
}
Loading