Top Description Fields Constructors Methods
com.dlsc.preferencesfx.util

public Class SearchHandler

extends Object
Class Inheritance
Imports
com.dlsc.preferencesfx.model.Category, .Group, .PreferencesFxModel, .Setting, com.dlsc.preferencesfx.view.FilterableTreeItem, .TreeItemPredicate, javafx.beans.binding.Bindings, javafx.beans.property.*, javafx.scene.control.TreeItem, .TreeView, org.slf4j.Logger, .LoggerFactory, java.util.Collection, .HashMap, .List

Handles everything related to searching in theCategory, Group and Setting.
Authors
François Martin, Marco Sanfratello

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Category>
categoryMatch

Represents the category which is matched by the search and should ultimately be displayed.

private int
private List<Category>
private List<Group>
private List<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>>
private TreeItemPredicate<Category>
filterPredicate

Decides whether a TreeItem should be shown in the TreeView or not.

private List<Category>
private List<Group>
private List<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>>
private HashMap<Group, Category>
private int
private static final Logger
private PreferencesFxModel
private StringProperty
private HashMap<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>, Category>
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
bindFilterPredicate(ObjectProperty<TreeItemPredicate<Category>>
of the rootItem of a FilterableTreeItem
predicateProperty
)

Binds the predicateProperty to ensure filtering according to the searchText.

private void
bindSearchText(StringProperty
textProperty of a TextField where the search string is being input
searchText
)

Makes sure this class is aware of the current text which is being searched for.

public ReadOnlyObjectProperty<Category>
public Category

Returns:

the category with the least amount of matches, taking into account the priority
compareMatches
(Category
category to return, if settingsMatch is chosen
setting
,
Category
category to return, if groupMatch is chosen
group
,
Category
category to return, if categoryMatch is chosen
category
,
int
amount of settings which match
settingMatch
,
int
amount of groups which match
groupMatch
,
int
amount of categories which match
categoryMatch
)

Compares three categories with decreasing priority from the first to the last category.

public Category
private Category
public void
init(PreferencesFxModel
the model of PreferencesFx
model
,
StringProperty
textProperty of a TextField where the search string is being input
searchText
,
ObjectProperty<TreeItemPredicate<Category>>
of the rootItem of a FilterableTreeItem
predicateProperty
)

Initializes the SearchHandler by initially creating all necessary lists for filtering and setting up the bindings.

private void
public void
initializeSearchText(StringProperty
the property of the search text UI element
searchText
)

Initializes the search text by binding it and then adding a listener to react to changes.

private void
initializeSearchTextListener()

Reacts upon changes in the search text.

private void
private void
private void
setCategoryMatch(Category categoryMatch)

private void
private void
public void
updateSearch(String
the new text to be searched for
searchText
)

Updates the search based on a new searchText.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

categoryMatchback to summary
private ObjectProperty<Category> categoryMatch

Represents the category which is matched by the search and should ultimately be displayed.

categoryMatchesback to summary
private int categoryMatches
filteredCategoriesLstback to summary
private List<Category> filteredCategoriesLst
filteredGroupsLstback to summary
private List<Group> filteredGroupsLst
filteredSettingsLstback to summary
private List<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>> filteredSettingsLst
filterPredicateback to summary
private TreeItemPredicate<Category> filterPredicate

Decides whether a TreeItem should be shown in the TreeView or not. If result is true, it will be shown, if the result is false, it will be hidden.

flatCategoriesLstback to summary
private List<Category> flatCategoriesLst
flatGroupsLstback to summary
private List<Group> flatGroupsLst
flatSettingsLstback to summary
private List<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>> flatSettingsLst
groupCategoryMapback to summary
private HashMap<Group, Category> groupCategoryMap
groupMatchesback to summary
private int groupMatches
LOGGERback to summary
private static final Logger LOGGER
modelback to summary
private PreferencesFxModel model
searchTextback to summary
private StringProperty searchText
settingCategoryMapback to summary
private HashMap<Setting<E extends Element<E extends Element<E>>, P extends Property<T>>, Category> settingCategoryMap
settingMatchesback to summary
private int settingMatches

Constructor Detail

SearchHandlerback to summary
public SearchHandler()

Method Detail

bindFilterPredicateback to summary
public void bindFilterPredicate(ObjectProperty<TreeItemPredicate<Category>> predicateProperty)

Binds the predicateProperty to ensure filtering according to the searchText.

Parameters
predicateProperty:ObjectProperty<TreeItemPredicate<Category>>

of the rootItem of a FilterableTreeItem

bindSearchTextback to summary
private void bindSearchText(StringProperty searchText)

Makes sure this class is aware of the current text which is being searched for.

Parameters
searchText:StringProperty

textProperty of a TextField where the search string is being input

categoryMatchPropertyback to summary
public ReadOnlyObjectProperty<Category> categoryMatchProperty()
compareMatchesback to summary
public Category compareMatches(Category setting, Category group, Category category, int settingMatch, int groupMatch, int categoryMatch)

Compares three categories with decreasing priority from the first to the last category. See developer reference for further information.

Parameters
setting:Category

category to return, if settingsMatch is chosen

group:Category

category to return, if groupMatch is chosen

category:Category

category to return, if categoryMatch is chosen

settingMatch:int

amount of settings which match

groupMatch:int

amount of groups which match

categoryMatch:int

amount of categories which match

Returns:Category

the category with the least amount of matches, taking into account the priority

getCategoryMatchback to summary
public Category getCategoryMatch()
getSelectedCategoryByMatchback to summary
private Category getSelectedCategoryByMatch()
initback to summary
public void init(PreferencesFxModel model, StringProperty searchText, ObjectProperty<TreeItemPredicate<Category>> predicateProperty)

Initializes the SearchHandler by initially creating all necessary lists for filtering and setting up the bindings.

API Note

Must be called to make the filtering work.

Parameters
model:PreferencesFxModel

the model of PreferencesFx

searchText:StringProperty

textProperty of a TextField where the search string is being input

predicateProperty:ObjectProperty<TreeItemPredicate<Category>>

of the rootItem of a FilterableTreeItem

initializeSearchback to summary
private void initializeSearch()
initializeSearchTextback to summary
public void initializeSearchText(StringProperty searchText)

Initializes the search text by binding it and then adding a listener to react to changes.

Parameters
searchText:StringProperty

the property of the search text UI element

initializeSearchTextListenerback to summary
private void initializeSearchTextListener()

Reacts upon changes in the search text. If the search text is empty, everything will be unmarked, else the search will be updated.

markMatchesback to summary
private void markMatches()
resetSearchback to summary
private void resetSearch()
setCategoryMatchback to summary
private void setCategoryMatch(Category categoryMatch)
unmarkEverythingback to summary
private void unmarkEverything()
updateFilteredListsback to summary
private void updateFilteredLists(String searchText)
updateSearchback to summary
public void updateSearch(String searchText)

Updates the search based on a new searchText.

Implementation Note

Filters the lists, sets the category match, unmarks everything and marks all matches.

Parameters
searchText:String

the new text to be searched for