-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Feature: implement search filter in show preferences #4759
Changes from 4 commits
74048b6
897c612
e377b73
d7e1f59
9d9d172
259626c
a7a7e79
882aa6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,9 @@ | ||||||||||||
package org.jabref.gui.preferences; | ||||||||||||
|
||||||||||||
import java.util.List; | ||||||||||||
import java.util.Locale; | ||||||||||||
import java.util.Objects; | ||||||||||||
import java.util.stream.Collectors; | ||||||||||||
|
||||||||||||
import javafx.beans.property.ReadOnlyObjectWrapper; | ||||||||||||
import javafx.beans.property.ReadOnlyStringWrapper; | ||||||||||||
|
@@ -11,6 +14,7 @@ | |||||||||||
import javafx.scene.control.Label; | ||||||||||||
import javafx.scene.control.TableColumn; | ||||||||||||
import javafx.scene.control.TableView; | ||||||||||||
import javafx.scene.control.TextField; | ||||||||||||
|
||||||||||||
import org.jabref.gui.util.BaseDialog; | ||||||||||||
import org.jabref.logic.l10n.Localization; | ||||||||||||
|
@@ -22,6 +26,7 @@ public class PreferencesFilterDialog extends BaseDialog<Void> { | |||||||||||
|
||||||||||||
private final JabRefPreferencesFilter preferencesFilter; | ||||||||||||
private final ObservableList<JabRefPreferencesFilter.PreferenceOption> preferenceOptions; | ||||||||||||
private final List<JabRefPreferencesFilter.PreferenceOption> auxillaryPreferenceOptions; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use the jabref/src/main/java/org/jabref/gui/maintable/MainTableDataModel.java Lines 29 to 33 in b39ed7b
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the suggestions! I have made the necessary changes. |
||||||||||||
|
||||||||||||
@FXML private TableView<JabRefPreferencesFilter.PreferenceOption> table; | ||||||||||||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, JabRefPreferencesFilter.PreferenceType> columnType; | ||||||||||||
|
@@ -30,10 +35,12 @@ public class PreferencesFilterDialog extends BaseDialog<Void> { | |||||||||||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, Object> columnDefaultValue; | ||||||||||||
@FXML private CheckBox showOnlyDeviatingPreferenceOptions; | ||||||||||||
@FXML private Label count; | ||||||||||||
@FXML private TextField searchField; | ||||||||||||
|
||||||||||||
public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { | ||||||||||||
this.preferencesFilter = Objects.requireNonNull(preferencesFilter); | ||||||||||||
this.preferenceOptions = FXCollections.observableArrayList(); | ||||||||||||
this.auxillaryPreferenceOptions = preferencesFilter.getPreferenceOptions(); | ||||||||||||
|
||||||||||||
ViewLoader.view(this) | ||||||||||||
.load() | ||||||||||||
|
@@ -45,6 +52,7 @@ public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { | |||||||||||
@FXML | ||||||||||||
private void initialize() { | ||||||||||||
showOnlyDeviatingPreferenceOptions.setOnAction(event -> updateModel()); | ||||||||||||
searchField.textProperty().addListener((observable, previousText, newText) -> filterPreferences(newText.toLowerCase(Locale.ROOT))); | ||||||||||||
columnType.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getType())); | ||||||||||||
columnKey.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getKey())); | ||||||||||||
columnValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getValue())); | ||||||||||||
|
@@ -54,11 +62,30 @@ private void initialize() { | |||||||||||
} | ||||||||||||
|
||||||||||||
private void updateModel() { | ||||||||||||
auxillaryPreferenceOptions.clear(); | ||||||||||||
if (showOnlyDeviatingPreferenceOptions.isSelected()) { | ||||||||||||
preferenceOptions.setAll(preferencesFilter.getDeviatingPreferences()); | ||||||||||||
auxillaryPreferenceOptions.addAll(preferencesFilter.getDeviatingPreferences()); | ||||||||||||
} else { | ||||||||||||
preferenceOptions.setAll(preferencesFilter.getPreferenceOptions()); | ||||||||||||
auxillaryPreferenceOptions.addAll(preferencesFilter.getPreferenceOptions()); | ||||||||||||
} | ||||||||||||
preferenceOptions.setAll(auxillaryPreferenceOptions); | ||||||||||||
count.setText(String.format("(%d)", preferenceOptions.size())); | ||||||||||||
String searchText = searchField.getText(); | ||||||||||||
if (!searchText.isEmpty()) { | ||||||||||||
filterPreferences(searchText); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
private void filterPreferences(String searchText) { | ||||||||||||
if (searchText.isEmpty()) { | ||||||||||||
updateModel(); | ||||||||||||
return; | ||||||||||||
} | ||||||||||||
|
||||||||||||
List<JabRefPreferencesFilter.PreferenceOption> filteredOptions = auxillaryPreferenceOptions.stream() | ||||||||||||
.filter(p -> p.getKey().toLowerCase(Locale.ROOT).contains(searchText)) | ||||||||||||
.collect(Collectors.toList()); | ||||||||||||
preferenceOptions.setAll(filteredOptions); | ||||||||||||
} | ||||||||||||
|
||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use
%Search
so that the text get localized properly.