Skip to content

Commit

Permalink
Make activeTab observable
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed Nov 30, 2024
1 parent 5bac391 commit f247c7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/LibraryTabContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import javafx.collections.ObservableList;

import org.jabref.model.database.BibDatabaseContext;

import org.jspecify.annotations.NonNull;
Expand All @@ -10,7 +12,7 @@

@NullMarked
public interface LibraryTabContainer {
List<LibraryTab> getLibraryTabs();
ObservableList<LibraryTab> getLibraryTabs();

@Nullable
LibraryTab getCurrentLibraryTab();
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.event.Event;
import javafx.geometry.Orientation;
Expand Down Expand Up @@ -454,11 +455,8 @@ private void initBindings() {
/**
* Returns a list of all LibraryTabs in this frame.
*/
public @NonNull List<LibraryTab> getLibraryTabs() {
return tabbedPane.getTabs().stream()
.filter(LibraryTab.class::isInstance)
.map(LibraryTab.class::cast)
.toList();
public @NonNull ObservableList<LibraryTab> getLibraryTabs() {
return EasyBind.map(tabbedPane.getTabs().filtered(LibraryTab.class::isInstance), LibraryTab.class::cast);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jabref/gui/importer/NewEntryActionTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jabref.gui.importer;

import java.util.List;
import javafx.collections.FXCollections;

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
Expand Down Expand Up @@ -40,7 +40,7 @@ void setUp() {
void executeOnSuccessWithFixedType() {
EntryType type = StandardEntryType.Article;
newEntryAction = new NewEntryAction(() -> libraryTab, type, dialogService, preferences, stateManager);
when(tabContainer.getLibraryTabs()).thenReturn(List.of(libraryTab));
when(tabContainer.getLibraryTabs()).thenReturn(FXCollections.observableArrayList(libraryTab));

newEntryAction.execute();
verify(libraryTab, times(1)).insertEntry(new BibEntry(type));
Expand Down

0 comments on commit f247c7c

Please sign in to comment.