use of com.github.bordertech.wcomponents.WSubMenu in project wcomponents by BorderTech.
the class FilterableTableExample method buildFilterSubMenu.
/**
* Creates and populates the sub-menu for each filter menu.
*
* @param menu The WMenu we are currently populating.
* @param column The column index of the table column the menu is in. This is used to get the data off the table's
* Bean to put text content into the menu's items.
*/
private void buildFilterSubMenu(final WMenu menu, final int column) {
List<?> beanList = getFilterableTableModel().getFullBeanList();
int rows = (beanList == null) ? 0 : beanList.size();
if (rows == 0) {
return;
}
final List<String> found = new ArrayList<>();
final WDecoratedLabel filterSubMenuLabel = new WDecoratedLabel(new WText("\u200b"));
filterSubMenuLabel.setToolTip("Filter this column");
filterSubMenuLabel.setHtmlClass(HtmlIconUtil.getIconClasses("fa-filter"));
final WSubMenu submenu = new WSubMenu(filterSubMenuLabel);
submenu.setSelectionMode(SELECTION_MODE);
menu.add(submenu);
WMenuItem item = new WMenuItem(CLEAR_ALL, new ClearFilterAction());
submenu.add(item);
item.setActionObject(item);
item.setSelectability(false);
add(new WAjaxControl(item, table));
Object cellObject;
String cellContent, cellContentMatch;
Object bean;
if (beanList != null) {
for (int i = 0; i < rows; ++i) {
bean = beanList.get(i);
if (bean != null) {
cellObject = getFilterableTableModel().getBeanPropertyValueFullList(BEAN_PROPERTIES[column], bean);
if (cellObject != null) {
if (cellObject instanceof Date) {
cellContent = new SimpleDateFormat(DATE_FORMAT).format((Date) cellObject);
} else {
cellContent = cellObject.toString();
}
if ("".equals(cellContent)) {
cellContent = EMPTY;
}
cellContentMatch = (getFilterableTableModel().isCaseInsensitiveMatch()) ? cellContent.toLowerCase() : cellContent;
if (found.indexOf(cellContentMatch) == -1) {
item = new WMenuItem(cellContent, new FilterAction());
submenu.add(item);
add(new WAjaxControl(item, table));
found.add(cellContentMatch);
}
}
}
}
}
}
use of com.github.bordertech.wcomponents.WSubMenu in project wcomponents by BorderTech.
the class WSubMenuRenderer method doRender.
/**
* Paints the given WSubMenu.
*
* @param component the WSubMenu to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WSubMenu menu = (WSubMenu) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:submenu");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (isTree(menu)) {
xml.appendAttribute("open", String.valueOf(isOpen(menu)));
}
xml.appendOptionalAttribute("disabled", menu.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", menu.isHidden(), "true");
if (menu.isTopLevelMenu()) {
xml.appendOptionalAttribute("accessKey", menu.getAccessKeyAsString());
} else {
xml.appendAttribute("nested", "true");
}
xml.appendOptionalAttribute("type", getMenuType(menu));
switch(menu.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
case SERVER:
// mode server mapped to mode dynamic as per https://github.com/BorderTech/wcomponents/issues/687
xml.appendAttribute("mode", "dynamic");
break;
default:
throw new SystemException("Unknown menu mode: " + menu.getMode());
}
xml.appendClose();
// Paint label
menu.getDecoratedLabel().paint(renderContext);
MenuMode mode = menu.getMode();
// Paint submenu items
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX request
if (mode != MenuMode.EAGER || AjaxHelper.isCurrentAjaxTrigger(menu)) {
// Visibility of content set in prepare paint
menu.paintMenuItems(renderContext);
}
xml.appendEndTag("ui:content");
xml.appendEndTag("ui:submenu");
}
use of com.github.bordertech.wcomponents.WSubMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testAccessKey.
@Test
public void testAccessKey() throws IOException, SAXException, XpathException {
// AccessKey
WMenuItem item = new WMenuItem(itemText, url);
WMenu wrapped = wrapMenuItem(item);
item.setAccessKey('A');
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("A", "//ui:menuitem/@accessKey", item);
// no access key if nested
WSubMenu sub = new WSubMenu("sub");
wrapped.add(sub);
item = new WMenuItem(itemText, url);
sub.add(item);
item.setAccessKey('A');
assertSchemaMatch(wrapped);
assertXpathNotExists("//ui:menuitem/@accessKey", item);
}
Aggregations