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

Use binding to update global state manager #5325

Merged
merged 1 commit into from
Sep 16, 2019
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

### Fixed

- Inherit fields from cross-referenced entries as specified by biblatex [#5045](https://github.com/JabRef/jabref/issues/5045)
- We fixed an issue where it was no longer possible to connect to LibreOffice [#5261](https://github.com/JabRef/jabref/issues/5261)
- Inherit fields from cross-referenced entries as specified by biblatex. [#5045](https://github.com/JabRef/jabref/issues/5045)
- We fixed an issue where it was no longer possible to connect to LibreOffice. [#5261](https://github.com/JabRef/jabref/issues/5261)
- The "All entries group" is no longer shown when no library is open.
- The group panel is now properly updated when switching between libraries (or when closing/opening one). [#3142](https://github.com/JabRef/jabref/issues/3142)
- We fixed an error where the number of matched entries shown in the group pane was not updated correctly. [#4441](https://github.com/JabRef/jabref/issues/4441)
- We fixed an error mentioning "javafx.controls/com.sun.javafx.scene.control" that was thrown when interacting with the toolbar.


### Removed
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ run {
'--add-exports', 'org.controlsfx.controls/impl.org.controlsfx.skin=org.jabref',
'--add-opens', 'javafx.controls/javafx.scene.control=org.jabref',
'--add-opens', 'org.controlsfx.controls/org.controlsfx.control.textfield=org.jabref',
'--add-opens', 'javafx.controls/com.sun.javafx.scene.control=org.jabref',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was about to report that. Encountered this yesterday but forgot to report it

// Not sure why we need to restate the controlfx exports
// Taken from here: https://github.com/controlsfx/controlsfx/blob/9.0.0/build.gradle#L1
"--add-exports", "javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls",
Expand Down
123 changes: 63 additions & 60 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,65 +163,8 @@ public JabRefFrame(Stage mainStage) {
this.undoManager = Globals.undoManager;
}

public void init() {
sidePaneManager = new SidePaneManager(Globals.prefs, this);
sidePane = sidePaneManager.getPane();

tabbedPane = new TabPane();
tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);

initLayout();

initKeyBindings();

initDragAndDrop();

//setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
//WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X,
// JabRefPreferences.SIZE_Y);
//pw.displayWindowAtStoredLocation();

/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), e -> {
if (e == null) {
stateManager.activeDatabaseProperty().setValue(Optional.empty());
return;
}

BasePanel currentBasePanel = getCurrentBasePanel();
if (currentBasePanel == null) {
return;
}

// Poor-mans binding to global state
stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext()));
stateManager.setSelectedEntries(currentBasePanel.getSelectedEntries());

// Update search query
String content = "";
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content);

// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class));
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));

setWindowTitle();
// Update search autocompleter with information for the correct database:
currentBasePanel.updateSearchManager();

currentBasePanel.getUndoManager().postUndoRedoEvent();
currentBasePanel.getMainTable().requestFocus();
});
initShowTrackingNotification();
private static BasePanel getBasePanel(Tab tab) {
return (BasePanel) tab.getContent();
}

public void initDragAndDrop() {
Expand Down Expand Up @@ -612,14 +555,74 @@ public void showBasePanel(BasePanel bp) {
tabbedPane.getSelectionModel().select(getTab(bp));
}

public void init() {
sidePaneManager = new SidePaneManager(Globals.prefs, this);
sidePane = sidePaneManager.getPane();

tabbedPane = new TabPane();
tabbedPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);

initLayout();

initKeyBindings();

initDragAndDrop();

//setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed or why is this (still) uncommented? What did it do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I have no idea ;-) Probably to restore the window size on start. Feel free to investigate ;-)

//WindowLocation pw = new WindowLocation(this, JabRefPreferences.POS_X, JabRefPreferences.POS_Y, JabRefPreferences.SIZE_X,
// JabRefPreferences.SIZE_Y);
//pw.displayWindowAtStoredLocation();

// Bind global state
stateManager.activeDatabaseProperty().bind(
EasyBind.map(tabbedPane.getSelectionModel().selectedItemProperty(),
tab -> Optional.ofNullable(tab).map(JabRefFrame::getBasePanel).map(BasePanel::getBibDatabaseContext)));
/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
EasyBind.subscribe(tabbedPane.getSelectionModel().selectedItemProperty(), tab -> {
if (tab == null) {
return;
}

BasePanel newBasePanel = getBasePanel(tab);

// Poor-mans binding to global state
stateManager.setSelectedEntries(newBasePanel.getSelectedEntries());

// Update search query
String content = "";
Optional<SearchQuery> currentSearchQuery = newBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content);

// groupSidePane.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(GroupSidePane.class));
//previewToggle.setSelected(Globals.prefs.getPreviewPreferences().isPreviewPanelEnabled());
//generalFetcher.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(WebSearchPane.class));
//openOfficePanel.getToggleCommand().setSelected(sidePaneManager.isComponentVisible(OpenOfficeSidePanel.class));

setWindowTitle();
// Update search autocompleter with information for the correct database:
newBasePanel.updateSearchManager();

newBasePanel.getUndoManager().postUndoRedoEvent();
newBasePanel.getMainTable().requestFocus();
});
initShowTrackingNotification();
}

/**
* Returns the currently viewed BasePanel.
*/
public BasePanel getCurrentBasePanel() {
if ((tabbedPane == null) || (tabbedPane.getSelectionModel().getSelectedItem() == null)) {
return null;
}
return (BasePanel) tabbedPane.getSelectionModel().getSelectedItem().getContent();
return getBasePanel(tabbedPane.getSelectionModel().getSelectedItem());
}

/**
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.inject.Inject;

import javafx.beans.property.ObjectProperty;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Control;
Expand Down Expand Up @@ -84,13 +81,10 @@ public void initialize() {
dragExpansionHandler = new DragExpansionHandler();

// Set-up bindings
Consumer<ObservableList<GroupNodeViewModel>> updateSelectedGroups =
(newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode);

BindingsHelper.bindContentBidirectional(
groupTree.getSelectionModel().getSelectedItems(),
viewModel.selectedGroupsProperty(),
updateSelectedGroups,
(newSelectedGroups) -> newSelectedGroups.forEach(this::selectNode),
this::updateSelection
);

Expand All @@ -104,11 +98,17 @@ public void initialize() {

groupTree.rootProperty().bind(
EasyBind.map(viewModel.rootGroupProperty(),
group -> new RecursiveTreeItem<>(
group,
GroupNodeViewModel::getChildren,
GroupNodeViewModel::expandedProperty,
viewModel.filterPredicateProperty())));
group -> {
if (group == null) {
return null;
} else {
return new RecursiveTreeItem<>(
group,
GroupNodeViewModel::getChildren,
GroupNodeViewModel::expandedProperty,
viewModel.filterPredicateProperty());
}
}));

// Icon and group name
mainColumn.setCellValueFactory(cellData -> cellData.getValue().valueProperty());
Expand Down Expand Up @@ -343,7 +343,8 @@ private ContextMenu createContextMenuForGroup(GroupNodeViewModel group) {
return menu;
}

public void addNewGroup(ActionEvent actionEvent) {
@FXML
private void addNewGroup() {
viewModel.addNewGroupToRoot();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ private void onActiveDatabaseChanged(Optional<BibDatabaseContext> newDatabase) {
.orElse(GroupNodeViewModel.getAllEntriesGroup(newDatabase.get(), stateManager, taskExecutor, localDragboard));

rootGroup.setValue(newRoot);
this.selectedGroups.setAll(
selectedGroups.setAll(
stateManager.getSelectedGroup(newDatabase.get()).stream()
.map(selectedGroup -> new GroupNodeViewModel(newDatabase.get(), stateManager, taskExecutor, selectedGroup, localDragboard))
.collect(Collectors.toList()));
} else {
rootGroup.setValue(GroupNodeViewModel.getAllEntriesGroup(new BibDatabaseContext(), stateManager, taskExecutor, localDragboard));
rootGroup.setValue(null);
}

currentDatabase = newDatabase;
Expand Down