use of com.github.bordertech.wcomponents.WMenuItem in project wcomponents by BorderTech.
the class MenuPanel method addRecentExample.
/**
* Adds an example to the recent subMenu.
*
* @param text the text to display.
* @param data the example data instance
* @param select should the menuItem be selected
*/
private void addRecentExample(final String text, final ExampleData data, final boolean select) {
WMenuItem item = new WMenuItem(text, new SelectExampleAction());
menu.add(item);
item.setActionObject(data);
if (select) {
menu.setSelectedMenuItem(item);
}
}
use of com.github.bordertech.wcomponents.WMenuItem 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.WMenuItem in project wcomponents by BorderTech.
the class WMenuItemRenderer method doRender.
/**
* Paints the given WMenuItem.
*
* @param component the WMenuItem to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMenuItem item = (WMenuItem) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:menuitem");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (item.isSubmit()) {
xml.appendAttribute("submit", "true");
} else {
xml.appendOptionalUrlAttribute("url", item.getUrl());
xml.appendOptionalAttribute("targetWindow", item.getTargetWindow());
}
xml.appendOptionalAttribute("disabled", item.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", item.isHidden(), "true");
xml.appendOptionalAttribute("selected", item.isSelected(), "true");
xml.appendOptionalAttribute("role", getRole(item));
xml.appendOptionalAttribute("cancel", item.isCancel(), "true");
xml.appendOptionalAttribute("msg", item.getMessage());
xml.appendOptionalAttribute("toolTip", item.getToolTip());
if (item.isTopLevelItem()) {
xml.appendOptionalAttribute("accessKey", item.getAccessKeyAsString());
}
xml.appendClose();
item.getDecoratedLabel().paint(renderContext);
xml.appendEndTag("ui:menuitem");
}
use of com.github.bordertech.wcomponents.WMenuItem in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testUrl.
@Test
public void testUrl() throws IOException, SAXException, XpathException {
// Test with URL
WMenuItem item = new WMenuItem(itemText, url);
WMenu wrapped = wrapMenuItem(item);
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo(itemText, "normalize-space(//ui:menuitem/ui:decoratedlabel)", item);
assertXpathUrlEvaluatesTo(url, "//ui:menuitem/@url", item);
assertXpathNotExists("//ui:menuitem/@submit", item);
}
use of com.github.bordertech.wcomponents.WMenuItem in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testRoleWhenSelectedNotSelectable.
@Test
public void testRoleWhenSelectedNotSelectable() throws IOException, SAXException, XpathException {
/*
* A WMenuItem may be set as selected even if it is not in a selection container. This is a flaw in an
* old part of the WComponents API.
*/
WMenuItem item = new WMenuItem(itemText);
WMenu wrapped = wrapMenuItem(item);
wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
assertXpathNotExists("//ui:menuitem/@selected", item);
wrapped.setSelectedItem(item);
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("true", "//ui:menuitem/@selected", item);
}
Aggregations