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

Refactor Sidepane logic #8202

Merged
merged 37 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
13fc122
Add visibleProperty to SidePaneComponent
HoussemNasri Oct 30, 2021
9688ec6
Making progress into refactoring Sidepane logic
HoussemNasri Oct 31, 2021
e7ddff6
Populate SidePaneType with information
HoussemNasri Oct 31, 2021
eee68e7
Wrap the content of web search side pane into WebSearchPaneView
HoussemNasri Oct 31, 2021
9c3a314
Revert changes to SidePane
HoussemNasri Oct 31, 2021
f59bb3f
Refactor SidePaneContainer
HoussemNasri Oct 31, 2021
41dba61
Bind side pane check menu selection state to side pane visibility
HoussemNasri Oct 31, 2021
c839950
Fix checkstyle
HoussemNasri Oct 31, 2021
69c90df
Remove SidePaneViewModel.java
HoussemNasri Oct 31, 2021
a9e0419
Fix view menu for sidebar option out of sync with sidebar state
HoussemNasri Oct 31, 2021
289165b
Remove unused constructor parameters
HoussemNasri Oct 31, 2021
d807d9b
Remove deprecated Sidepane component
HoussemNasri Oct 31, 2021
971203a
Move Vbox.setVgrow() to SidePaneView
HoussemNasri Nov 1, 2021
2266a67
Merge SidePaneHeaderView into SidePaneView
HoussemNasri Nov 1, 2021
8224cc5
Avoid firing removed and added events on ObservableList
HoussemNasri Nov 2, 2021
5a877ab
Use shorter more declarative code for binding
HoussemNasri Nov 2, 2021
1d35778
Rename SidePaneView to SidePaneComponent and SidePaneContainerView to…
HoussemNasri Nov 6, 2021
6d9d52d
Rename initView() to initialize()
HoussemNasri Nov 6, 2021
2f0590d
Add an overloading of createCheckMenuItem() with a selected property
HoussemNasri Nov 6, 2021
58edb1c
Rename sidePaneVisibleProperty() to paneVisibleProperty()
HoussemNasri Nov 6, 2021
7e70c25
Use the name pane rather than sidePane to call components in the Side…
HoussemNasri Nov 6, 2021
9cd8894
Remove unused method createSidePaneCheckMenuItem()
HoussemNasri Nov 6, 2021
7176862
Share the visibility property of side pane components by moving it to…
HoussemNasri Nov 6, 2021
b0cae97
Remove comment
HoussemNasri Nov 6, 2021
85308f7
Use better names
HoussemNasri Nov 6, 2021
e44ae48
Fix checkstyle
HoussemNasri Nov 6, 2021
2616335
Move close/toggle pane actions to separate files
HoussemNasri Nov 8, 2021
ab49960
Move sidepane binding logic to SidePaneViewModel
HoussemNasri Nov 14, 2021
e2141bc
Merge remote-tracking branch 'upstream/main' into refactor-sidepane
calixtus Dec 1, 2021
e573811
Removed unnecessary properties in stateManager, refactored to mvvm pa…
calixtus Dec 5, 2021
2149f6c
Moved listener from sidepane visibility property to list of children …
calixtus Dec 5, 2021
e74403c
Removed unused method
calixtus Dec 6, 2021
531dafc
Fixed sidepane width issue on startup
calixtus Dec 11, 2021
1b56325
Created tests
calixtus Dec 11, 2021
9af0d79
Cleanups
calixtus Dec 11, 2021
ecfb529
CHANGELOG.md
calixtus Dec 11, 2021
2ff238b
more CHANGELOG.md
calixtus Dec 11, 2021
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
15 changes: 12 additions & 3 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
Expand Down Expand Up @@ -113,6 +114,7 @@
import org.jabref.gui.shared.PullChangesFromSharedAction;
import org.jabref.gui.sidepane.SidePane;
import org.jabref.gui.sidepane.SidePaneComponent;
import org.jabref.gui.sidepane.SidePaneContainerView;
import org.jabref.gui.sidepane.SidePaneType;
import org.jabref.gui.slr.ExistingStudySearchAction;
import org.jabref.gui.slr.StartNewStudyAction;
Expand Down Expand Up @@ -145,6 +147,7 @@
import com.google.common.eventbus.Subscribe;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyObservableList;
import de.saxsys.mvvmfx.utils.commands.Command;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.TaskProgressView;
import org.fxmisc.richtext.CodeArea;
Expand Down Expand Up @@ -343,7 +346,7 @@ public void about() {
* FIXME: Currently some threads remain and therefore hinder JabRef to be closed properly
*
* @param filenames the filenames of all currently opened files - used for storing them if prefs openLastEdited is
* set to true
* set to true
*/
private void tearDownJabRef(List<String> filenames) {
if (prefs.getGuiPreferences().shouldOpenLastEdited()) {
Expand Down Expand Up @@ -941,6 +944,12 @@ private Button createNewEntryFromIdButton() {
return newEntryFromIdButton;
}

private CheckMenuItem createSidePaneCheckMenuItem(SidePaneContainerView container, ActionFactory factory, SidePaneType paneType, Command toggleCommand) {
CheckMenuItem checkMenuItem = factory.createCheckMenuItem(paneType.getToggleAction(), toggleCommand, (container.isPaneVisibleProperty(paneType).get()));
checkMenuItem.selectedProperty().bindBidirectional(container.isPaneVisibleProperty(paneType));
calixtus marked this conversation as resolved.
Show resolved Hide resolved
return checkMenuItem;
}

private Group createTaskIndicator() {
ProgressIndicator indicator = new ProgressIndicator();
indicator.getStyleClass().add("progress-indicatorToolbar");
Expand Down Expand Up @@ -1108,7 +1117,7 @@ private boolean readyForAutosave(BibDatabaseContext context) {
/**
* Opens the import inspection dialog to let the user decide which of the given entries to import.
*
* @param panel The BasePanel to add to.
* @param panel The BasePanel to add to.
* @param parserResult The entries to add.
*/
private void addImportedEntries(final LibraryTab panel, final ParserResult parserResult) {
Expand Down Expand Up @@ -1241,7 +1250,7 @@ public CloseDatabaseAction(LibraryTab libraryTab) {

/**
* Using this constructor will result in executing the command on the currently open library tab
* */
*/
public CloseDatabaseAction() {
this(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.jabref.gui.importer.fetcher;

import javafx.css.PseudoClass;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.search.SearchTextField;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;

public class WebSearchPaneView extends VBox {

private static final PseudoClass QUERY_INVALID = PseudoClass.getPseudoClass("invalid");

private final WebSearchPaneViewModel viewModel;
private final PreferencesService preferences;

public WebSearchPaneView(PreferencesService preferences, DialogService dialogService, StateManager stateManager) {
this.preferences = preferences;
this.viewModel = new WebSearchPaneViewModel(preferences, dialogService, stateManager);
initView();
}

private void initView() {
HoussemNasri marked this conversation as resolved.
Show resolved Hide resolved
ComboBox<SearchBasedFetcher> fetchers = new ComboBox<>();
new ViewModelListCellFactory<SearchBasedFetcher>()
.withText(SearchBasedFetcher::getName)
.install(fetchers);
fetchers.itemsProperty().bind(viewModel.fetchersProperty());
fetchers.valueProperty().bindBidirectional(viewModel.selectedFetcherProperty());
fetchers.setMaxWidth(Double.POSITIVE_INFINITY);

// Create help button for currently selected fetcher
StackPane helpButtonContainer = new StackPane();
ActionFactory factory = new ActionFactory(preferences.getKeyBindingRepository());
EasyBind.subscribe(viewModel.selectedFetcherProperty(), fetcher -> {
if ((fetcher != null) && fetcher.getHelpPage().isPresent()) {
Button helpButton = factory.createIconButton(StandardActions.HELP, new HelpAction(fetcher.getHelpPage().get()));
helpButtonContainer.getChildren().setAll(helpButton);
} else {
helpButtonContainer.getChildren().clear();
}
});
HBox fetcherContainer = new HBox(fetchers, helpButtonContainer);
HBox.setHgrow(fetchers, Priority.ALWAYS);

// Create text field for query input
TextField query = SearchTextField.create();
query.getStyleClass().add("searchBar");

viewModel.queryProperty().bind(query.textProperty());
EasyBind.subscribe(viewModel.queryValidationStatus().validProperty(),
valid -> {
if (!valid && viewModel.queryValidationStatus().getHighestMessage().isPresent()) {
query.setTooltip(new Tooltip(viewModel.queryValidationStatus().getHighestMessage().get().getMessage()));
query.pseudoClassStateChanged(QUERY_INVALID, true);
} else {
query.setTooltip(null);
query.pseudoClassStateChanged(QUERY_INVALID, false);
}
});

// Allows triggering search on pressing enter
query.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) {
viewModel.search();
}
});

// Create button that triggers search
Button search = new Button(Localization.lang("Search"));
search.setDefaultButton(false);
search.setOnAction(event -> viewModel.search());

setAlignment(Pos.CENTER);
getChildren().addAll(fetcherContainer, query, search);
}
}
15 changes: 0 additions & 15 deletions src/main/java/org/jabref/gui/sidepane/SidePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public SidePane(PreferencesService preferencesService,
this.dialogService = dialogService;
this.stateManager = stateManager;
this.undoManager = undoManager;
initComponents();

setId("sidePane");

Expand All @@ -54,21 +53,7 @@ public SidePane(PreferencesService preferencesService,
updateView();
}

private void initComponents() {
components.put(SidePaneType.GROUPS, new GroupSidePane(this, taskExecutor, stateManager, preferencesService, dialogService));
components.put(SidePaneType.OPEN_OFFICE, new OpenOfficeSidePanel(this, taskExecutor, preferencesService, dialogService, stateManager, undoManager));
components.put(SidePaneType.WEB_SEARCH, new WebSearchPane(this, preferencesService, dialogService, stateManager));
components.forEach((key, value) -> value.visibleProperty().addListener((x, y, isVisible) -> {
if (isVisible) {
show(key);
} else {
hide(key);
}
}));
}

public boolean isComponentVisible(SidePaneType type) {
// TODO('return getComponent(type).visiblePropertyProperty().get();')
return visibleComponents.contains(getComponent(type));
}

Expand Down
Loading