C
- type of the categoriesS
- type of the sub-itemspublic class SimpleMenuBuilder<C extends MenuEntry,S extends MenuEntry> extends Object
SimpleMenu
with entries that are sorted according to a declarative
defined position. This builder also supports a filtering mechanism to dynamically decide whether
a certain category or category entry should be included in the menu.Constructor and Description |
---|
SimpleMenuBuilder() |
Modifier and Type | Method and Description |
---|---|
boolean |
addCategory(C item,
PositionDescriptor positionDescriptor)
Add a new category to the first level of the menu.
|
void |
addCategoryEntryFilter(MenuEntryFilter<S> filter)
Add a filter that will be called when the menu is built to decide whether a menu entry should
be added to its category.
|
void |
addCategoryFilter(MenuEntryFilter<C> filter)
Add a filter that will be called when the menu is built to decide whether a category should
be included in the menu.
|
boolean |
addToCategory(String categoryId,
S item,
PositionDescriptor positionDescriptor)
Add a menu item to a category.
|
SimpleMenu<C,S> |
buildMenu()
Create the final menu.
|
protected boolean |
filterCategory(C category)
Apply the registered category filters to the category and return whether it should be added
to the menu
|
protected boolean |
filterEntry(S entry)
Apply the registered filters to the entry and return whether it should be added to the
category.
|
C |
getCategory(String categoryId)
Get a category
|
S |
getCategoryEntry(String categoryId,
String entryId)
Get a category entry.
|
protected boolean |
isCachable()
Denotes whether the built menu can be cached and should only be recreated if the menu content
changed.
|
protected void |
menuContentChanged()
Is invoked if a category or category entry was added or removed.
|
boolean |
removeCategory(C item)
Remove a previously added category.
|
boolean |
removeCategory(String categoryId)
Same as
removeCategory(C) but removes the category by its
ID. |
void |
removeCategoryEntryFilter(MenuEntryFilter<S> filter)
Remove a previously added filter
|
void |
removeCategoryFilter(MenuEntryFilter<C> filter)
Remove a previously added filter
|
S |
removeFromCategory(String categoryId,
S item)
Remove a previously added item from a category.
|
S |
removeFromCategory(String categoryId,
String itemId)
Same as
removeFromCategory(String, S) but
searches the item by its ID. |
public boolean addCategory(C item, PositionDescriptor positionDescriptor)
If called several times with position type TOP
the categories which were added
later will be positioned before those added earlier. If called several times with position
type BOTTOM
or AFTER
(and the same menu entry ID to position
after), the categories which were added later will be positioned after those added earlier.
Entries with position type TOP
are always before the BOTTOM
positioned categories. Categories with position type AFTER
will not appear in
the resulting menu if the referenced category does not exist. However, if that referenced
category is added later on, the categories to position after that category will than be
contained in the menu.
item
- the item to addpositionDescriptor
- descriptor defining where the item should be added. If null the category will be
added to the bottom.public void addCategoryEntryFilter(MenuEntryFilter<S> filter)
filter
- the filter to addpublic void addCategoryFilter(MenuEntryFilter<C> filter)
filter
- the filter to addpublic boolean addToCategory(String categoryId, S item, PositionDescriptor positionDescriptor)
If called several times with position type TOP
the entries which were added
later will be positioned before those added earlier. If called several times with position
type BOTTOM
or AFTER
(and the same menu entry ID to position
after), the entries which were added later will be positioned after those added earlier.
Entries with position type TOP
are always before the BOTTOM
positioned entries. Entries with position type AFTER
will not appear in the
resulting menu if the referenced menu entry does not exist. However, if that referenced entry
is added later on, the entries to position after that entry will than be contained in the
category.
categoryId
- the ID of the categoryitem
- the item to addpositionDescriptor
- descriptor defining where the item should be added. If null the item will be added
to the bottompublic SimpleMenu<C,S> buildMenu()
protected boolean filterCategory(C category)
category
- the category to testprotected boolean filterEntry(S entry)
entry
- the entry to testpublic C getCategory(String categoryId)
categoryId
- the ID of the categorypublic S getCategoryEntry(String categoryId, String entryId)
categoryId
- the ID of the categoryentryId
- the ID of the entry in the categoryprotected boolean isCachable()
This implementation assumes that registered filters lead to a menu that is not cacheable.
protected void menuContentChanged()
This implementation discards the cached menu.
public boolean removeCategory(C item)
item
- the category to removepublic boolean removeCategory(String categoryId)
removeCategory(C)
but removes the category by its
ID.categoryId
- the ID of the category to removepublic void removeCategoryEntryFilter(MenuEntryFilter<S> filter)
filter
- the filter to removepublic void removeCategoryFilter(MenuEntryFilter<C> filter)
filter
- the filter to removepublic S removeFromCategory(String categoryId, S item)
categoryId
- the ID of the category from which the entry should be removeditem
- the item to removepublic S removeFromCategory(String categoryId, String itemId)
removeFromCategory(String, S)
but
searches the item by its ID.categoryId
- the ID of the category from which the entry should be removeditemId
- the ID of the item to removeCopyright © 2019 Communote team. All rights reserved.