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

[WIP] Added number of items found #5740

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 9 additions & 1 deletion src/main/java/org/jabref/gui/importer/ImportEntriesDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
fx:controller="org.jabref.gui.importer.ImportEntriesDialog"
prefHeight="700.0" prefWidth="1000.0">
<content>
<VBox spacing="10">
<VBox spacing="20">
<Label text="%Select the entries to be imported:"/>
<CheckListView fx:id="entriesListView" VBox.vgrow="ALWAYS"/>
<HBox>
<Button text="%Select all new entries" styleClass="text-button" onAction="#selectAllNewEntries"/>
<Button text="%Unselect all" styleClass="text-button" onAction="#unselectAll"/>
</HBox>
<HBox>
<Label text="%Total items found:" styleClass="info-section"/>
<Label fx:id="totalItems" />
</HBox>
<HBox>
<Label text="%Selected items:" styleClass="info-section"/>
<Label fx:id="selectedItems"/>
</HBox>
</VBox>
</content>
<ButtonType fx:id="importButton" text="%Import entries" buttonData="OK_DONE"/>
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/org/jabref/gui/importer/ImportEntriesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import javax.inject.Inject;
import javax.swing.undo.UndoManager;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.css.PseudoClass;
Expand Down Expand Up @@ -48,6 +47,8 @@ public class ImportEntriesDialog extends BaseDialog<Void> {

public CheckListView<BibEntry> entriesListView;
public ButtonType importButton;
public Label totalItems;
public Label selectedItems;
private final BackgroundTask<List<BibEntry>> task;
private ImportEntriesViewModel viewModel;
@Inject private TaskExecutor taskExecutor;
Expand All @@ -61,7 +62,6 @@ public class ImportEntriesDialog extends BaseDialog<Void> {
public ImportEntriesDialog(BibDatabaseContext database, BackgroundTask<List<BibEntry>> task) {
this.database = database;
this.task = task;

ViewLoader.view(this)
.load()
.setAsDialogPane(this);
Expand All @@ -84,12 +84,12 @@ public ImportEntriesDialog(BibDatabaseContext database, BackgroundTask<List<BibE
@FXML
private void initialize() {
viewModel = new ImportEntriesViewModel(task, taskExecutor, database, dialogService, undoManager, preferences, stateManager, fileUpdateMonitor);

Label placeholder = new Label();
placeholder.textProperty().bind(viewModel.messageProperty());
entriesListView.setPlaceholder(placeholder);
entriesListView.setItems(viewModel.getEntries());

totalItems.setText("0");
selectedItems.setText("0");
PseudoClass entrySelected = PseudoClass.getPseudoClass("entry-selected");
new ViewModelListCellFactory<BibEntry>()
.withGraphic(entry -> {
Expand All @@ -103,6 +103,19 @@ private void initialize() {
});
addToggle.getStyleClass().add("addEntryButton");
addToggle.selectedProperty().bindBidirectional(entriesListView.getItemBooleanProperty(entry));
addToggle.selectedProperty().addListener((observable, oldValue, newValue) -> {
if(observable.getValue()){
Copy link
Member

Choose a reason for hiding this comment

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

Please follow our code formatting guidelines. The auto formatter should add some spaces here.

++numberOfSelectedItems;
selectedItems.setText(String.valueOf(numberOfSelectedItems));
}else
if(numberOfSelectedItems == 0){
return;
}
else{
--numberOfSelectedItems;
selectedItems.setText(String.valueOf(numberOfSelectedItems));
}
});
HBox separator = new HBox();
HBox.setHgrow(separator, Priority.SOMETIMES);
Node entryNode = getEntryNode(entry);
Expand All @@ -125,13 +138,11 @@ private void initialize() {
*/
if (entriesListView.getItems().size() == 1) {
selectAllNewEntries();
}

}
totalItems.textProperty().setValue(String.valueOf(entriesListView.getItems().size()));
Copy link
Member

Choose a reason for hiding this comment

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

It should be possible to bind the text directly to the size:
totalItems.textProperty().bind(Bindings.size(viewModel.getEntries())), which can then be moved to line 90.

Copy link
Author

Choose a reason for hiding this comment

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

It actually didn't work as you said, I just pushed some changes that were missing, I hope everything is ok.

return container;
})
.withOnMouseClickedEvent((entry, event) -> entriesListView.getCheckModel().toggleCheckState(entry))
.withPseudoClass(entrySelected, entriesListView::getItemBooleanProperty)
.install(entriesListView);
.withOnMouseClickedEvent((entry, event) -> entriesListView.getCheckModel().toggleCheckState(entry)).withPseudoClass(entrySelected, entriesListView::getItemBooleanProperty).install(entriesListView);
entriesListView.setSelectionModel(new NoSelectionModel<>());
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,8 @@ Cancel\ import=Cancel import
Continue\ with\ import=Continue with import
Import\ canceled=Import canceled
Select\ all\ new\ entries=Select all new entries
Total\ items\ found\:=Total items found:
Selected\ items\:=Selected items:
Select\ the\ entries\ to\ be\ imported\:=Select the entries to be imported\:
Add\ new\ String=Add new String
Remove\ selected\ Strings=Remove selected Strings
Expand Down