com.vaadin.client.ui.VFilterSelect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-client Show documentation
Show all versions of vaadin-client Show documentation
Vaadin is a web application framework for Rich Internet Applications (RIA).
Vaadin enables easy development and maintenance of fast and
secure rich web
applications with a stunning look and feel and a wide browser support.
It features a server-side architecture with the majority of the logic
running
on the server. Ajax technology is used at the browser-side to ensure a
rich
and interactive user experience.
/*
* Copyright 2000-2013 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.client.ui;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwt.user.client.ui.TextBox;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.BrowserInfo;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorMap;
import com.vaadin.client.Focusable;
import com.vaadin.client.UIDL;
import com.vaadin.client.Util;
import com.vaadin.client.VConsole;
import com.vaadin.client.ui.aria.AriaHelper;
import com.vaadin.client.ui.aria.HandlesAriaCaption;
import com.vaadin.client.ui.aria.HandlesAriaInvalid;
import com.vaadin.client.ui.aria.HandlesAriaRequired;
import com.vaadin.client.ui.menubar.MenuBar;
import com.vaadin.client.ui.menubar.MenuItem;
import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.EventId;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.ui.combobox.FilteringMode;
/**
* Client side implementation of the Select component.
*
* TODO needs major refactoring (to be extensible etc)
*/
@SuppressWarnings("deprecation")
public class VFilterSelect extends Composite implements Field, KeyDownHandler,
KeyUpHandler, ClickHandler, FocusHandler, BlurHandler, Focusable,
SubPartAware, HandlesAriaCaption, HandlesAriaInvalid,
HandlesAriaRequired {
/**
* Represents a suggestion in the suggestion popup box
*/
public class FilterSelectSuggestion implements Suggestion, Command {
private final String key;
private final String caption;
private String iconUri;
/**
* Constructor
*
* @param uidl
* The UIDL recieved from the server
*/
public FilterSelectSuggestion(UIDL uidl) {
key = uidl.getStringAttribute("key");
caption = uidl.getStringAttribute("caption");
if (uidl.hasAttribute("icon")) {
iconUri = client.translateVaadinUri(uidl
.getStringAttribute("icon"));
}
}
/**
* Gets the visible row in the popup as a HTML string. The string
* contains an image tag with the rows icon (if an icon has been
* specified) and the caption of the item
*/
@Override
public String getDisplayString() {
final StringBuffer sb = new StringBuffer();
if (iconUri != null) {
sb.append("");
}
String content;
if ("".equals(caption)) {
// Ensure that empty options use the same height as other
// options and are not collapsed (#7506)
content = " ";
} else {
content = Util.escapeHTML(caption);
}
sb.append("" + content + "");
return sb.toString();
}
/**
* Get a string that represents this item. This is used in the text box.
*/
@Override
public String getReplacementString() {
return caption;
}
/**
* Get the option key which represents the item on the server side.
*
* @return The key of the item
*/
public String getOptionKey() {
return key;
}
/**
* Get the URI of the icon. Used when constructing the displayed option.
*
* @return
*/
public String getIconUri() {
return iconUri;
}
/**
* Executes a selection of this item.
*/
@Override
public void execute() {
onSuggestionSelected(this);
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof FilterSelectSuggestion)) {
return false;
}
FilterSelectSuggestion other = (FilterSelectSuggestion) obj;
if ((key == null && other.key != null)
|| (key != null && !key.equals(other.key))) {
return false;
}
if ((caption == null && other.caption != null)
|| (caption != null && !caption.equals(other.caption))) {
return false;
}
if ((iconUri == null && other.iconUri != null)
|| (iconUri != null && !iconUri.equals(other.iconUri))) {
return false;
}
return true;
}
}
/**
* Represents the popup box with the selection options. Wraps a suggestion
* menu.
*/
public class SuggestionPopup extends VOverlay implements PositionCallback,
CloseHandler {
private static final int Z_INDEX = 30000;
/** For internal use only. May be removed or replaced in the future. */
public final SuggestionMenu menu;
private final Element up = DOM.createDiv();
private final Element down = DOM.createDiv();
private final Element status = DOM.createDiv();
private boolean isPagingEnabled = true;
private long lastAutoClosed;
private int popupOuterPadding = -1;
private int topPosition;
/**
* Default constructor
*/
SuggestionPopup() {
super(true, false, true);
debug("VFS.SP: constructor()");
setOwner(VFilterSelect.this);
menu = new SuggestionMenu();
setWidget(menu);
getElement().getStyle().setZIndex(Z_INDEX);
final Element root = getContainerElement();
up.setInnerHTML("Prev");
DOM.sinkEvents(up, Event.ONCLICK);
down.setInnerHTML("Next");
DOM.sinkEvents(down, Event.ONCLICK);
root.insertFirst(up);
root.appendChild(down);
root.appendChild(status);
DOM.sinkEvents(root, Event.ONMOUSEDOWN | Event.ONMOUSEWHEEL);
addCloseHandler(this);
Roles.getListRole().set(getElement());
}
/**
* Shows the popup where the user can see the filtered options
*
* @param currentSuggestions
* The filtered suggestions
* @param currentPage
* The current page number
* @param totalSuggestions
* The total amount of suggestions
*/
public void showSuggestions(
final Collection currentSuggestions,
final int currentPage, final int totalSuggestions) {
if (enableDebug) {
debug("VFS.SP: showSuggestions(" + currentSuggestions + ", "
+ currentPage + ", " + totalSuggestions + ")");
}
/*
* We need to defer the opening of the popup so that the parent DOM
* has stabilized so we can calculate an absolute top and left
* correctly. This issue manifests when a Combobox is placed in
* another popupView which also needs to calculate the absoluteTop()
* to position itself. #9768
*/
final SuggestionPopup popup = this;
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
// Add TT anchor point
getElement().setId("VAADIN_COMBOBOX_OPTIONLIST");
menu.setSuggestions(currentSuggestions);
final int x = VFilterSelect.this.getAbsoluteLeft();
topPosition = tb.getAbsoluteTop();
topPosition += tb.getOffsetHeight();
setPopupPosition(x, topPosition);
int nullOffset = (nullSelectionAllowed
&& "".equals(lastFilter) ? 1 : 0);
boolean firstPage = (currentPage == 0);
final int first = currentPage * pageLength + 1
- (firstPage ? 0 : nullOffset);
final int last = first
+ currentSuggestions.size()
- 1
- (firstPage && "".equals(lastFilter) ? nullOffset
: 0);
final int matches = totalSuggestions - nullOffset;
if (last > 0) {
// nullsel not counted, as requested by user
status.setInnerText((matches == 0 ? 0 : first) + "-"
+ last + "/" + matches);
} else {
status.setInnerText("");
}
// We don't need to show arrows or statusbar if there is
// only one
// page
if (totalSuggestions <= pageLength || pageLength == 0) {
setPagingEnabled(false);
} else {
setPagingEnabled(true);
}
setPrevButtonActive(first > 1);
setNextButtonActive(last < matches);
// clear previously fixed width
menu.setWidth("");
menu.getElement().getFirstChildElement().getStyle()
.clearWidth();
setPopupPositionAndShow(popup);
}
});
}
/**
* Should the next page button be visible to the user?
*
* @param active
*/
private void setNextButtonActive(boolean active) {
if (enableDebug) {
debug("VFS.SP: setNextButtonActive(" + active + ")");
}
if (active) {
DOM.sinkEvents(down, Event.ONCLICK);
down.setClassName(VFilterSelect.this.getStylePrimaryName()
+ "-nextpage");
} else {
DOM.sinkEvents(down, 0);
down.setClassName(VFilterSelect.this.getStylePrimaryName()
+ "-nextpage-off");
}
}
/**
* Should the previous page button be visible to the user
*
* @param active
*/
private void setPrevButtonActive(boolean active) {
if (enableDebug) {
debug("VFS.SP: setPrevButtonActive(" + active + ")");
}
if (active) {
DOM.sinkEvents(up, Event.ONCLICK);
up.setClassName(VFilterSelect.this.getStylePrimaryName()
+ "-prevpage");
} else {
DOM.sinkEvents(up, 0);
up.setClassName(VFilterSelect.this.getStylePrimaryName()
+ "-prevpage-off");
}
}
/**
* Selects the next item in the filtered selections
*/
public void selectNextItem() {
debug("VFS.SP: selectNextItem()");
final MenuItem cur = menu.getSelectedItem();
final int index = 1 + menu.getItems().indexOf(cur);
if (menu.getItems().size() > index) {
final MenuItem newSelectedItem = menu.getItems().get(index);
menu.selectItem(newSelectedItem);
tb.setText(newSelectedItem.getText());
tb.setSelectionRange(lastFilter.length(), newSelectedItem
.getText().length() - lastFilter.length());
} else if (hasNextPage()) {
selectPopupItemWhenResponseIsReceived = Select.FIRST;
filterOptions(currentPage + 1, lastFilter);
}
}
/**
* Selects the previous item in the filtered selections
*/
public void selectPrevItem() {
debug("VFS.SP: selectPrevItem()");
final MenuItem cur = menu.getSelectedItem();
final int index = -1 + menu.getItems().indexOf(cur);
if (index > -1) {
final MenuItem newSelectedItem = menu.getItems().get(index);
menu.selectItem(newSelectedItem);
tb.setText(newSelectedItem.getText());
tb.setSelectionRange(lastFilter.length(), newSelectedItem
.getText().length() - lastFilter.length());
} else if (index == -1) {
if (currentPage > 0) {
selectPopupItemWhenResponseIsReceived = Select.LAST;
filterOptions(currentPage - 1, lastFilter);
}
} else {
final MenuItem newSelectedItem = menu.getItems().get(
menu.getItems().size() - 1);
menu.selectItem(newSelectedItem);
tb.setText(newSelectedItem.getText());
tb.setSelectionRange(lastFilter.length(), newSelectedItem
.getText().length() - lastFilter.length());
}
}
/*
* Using a timer to scroll up or down the pages so when we receive lots
* of consecutive mouse wheel events the pages does not flicker.
*/
private LazyPageScroller lazyPageScroller = new LazyPageScroller();
private class LazyPageScroller extends Timer {
private int pagesToScroll = 0;
@Override
public void run() {
debug("VFS.SP.LPS: run()");
if (pagesToScroll != 0) {
if (!waitingForFilteringResponse) {
/*
* Avoid scrolling while we are waiting for a response
* because otherwise the waiting flag will be reset in
* the first response and the second response will be
* ignored, causing an empty popup...
*
* As long as the scrolling delay is suitable
* double/triple clicks will work by scrolling two or
* three pages at a time and this should not be a
* problem.
*/
filterOptions(currentPage + pagesToScroll, lastFilter);
}
pagesToScroll = 0;
}
}
public void scrollUp() {
debug("VFS.SP.LPS: scrollUp()");
if (currentPage + pagesToScroll > 0) {
pagesToScroll--;
cancel();
schedule(200);
}
}
public void scrollDown() {
debug("VFS.SP.LPS: scrollDown()");
if (totalMatches > (currentPage + pagesToScroll + 1)
* pageLength) {
pagesToScroll++;
cancel();
schedule(200);
}
}
}
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.user.client.ui.Widget#onBrowserEvent(com.google.gwt
* .user.client.Event)
*/
@Override
public void onBrowserEvent(Event event) {
debug("VFS.SP: onBrowserEvent()");
if (event.getTypeInt() == Event.ONCLICK) {
final Element target = DOM.eventGetTarget(event);
if (target == up || target == DOM.getChild(up, 0)) {
lazyPageScroller.scrollUp();
} else if (target == down || target == DOM.getChild(down, 0)) {
lazyPageScroller.scrollDown();
}
} else if (event.getTypeInt() == Event.ONMOUSEWHEEL) {
int velocity = event.getMouseWheelVelocityY();
if (velocity > 0) {
lazyPageScroller.scrollDown();
} else {
lazyPageScroller.scrollUp();
}
}
/*
* Prevent the keyboard focus from leaving the textfield by
* preventing the default behaviour of the browser. Fixes #4285.
*/
handleMouseDownEvent(event);
}
/**
* Should paging be enabled. If paging is enabled then only a certain
* amount of items are visible at a time and a scrollbar or buttons are
* visible to change page. If paging is turned of then all options are
* rendered into the popup menu.
*
* @param paging
* Should the paging be turned on?
*/
public void setPagingEnabled(boolean paging) {
debug("VFS.SP: setPagingEnabled(" + paging + ")");
if (isPagingEnabled == paging) {
return;
}
if (paging) {
down.getStyle().clearDisplay();
up.getStyle().clearDisplay();
status.getStyle().clearDisplay();
} else {
down.getStyle().setDisplay(Display.NONE);
up.getStyle().setDisplay(Display.NONE);
status.getStyle().setDisplay(Display.NONE);
}
isPagingEnabled = paging;
}
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.user.client.ui.PopupPanel$PositionCallback#setPosition
* (int, int)
*/
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
debug("VFS.SP: setPosition()");
int top = -1;
int left = -1;
// reset menu size and retrieve its "natural" size
menu.setHeight("");
if (currentPage > 0) {
// fix height to avoid height change when getting to last page
menu.fixHeightTo(pageLength);
}
offsetHeight = getOffsetHeight();
final int desiredWidth = getMainWidth();
Element menuFirstChild = menu.getElement().getFirstChildElement()
.cast();
int naturalMenuWidth = menuFirstChild.getOffsetWidth();
if (popupOuterPadding == -1) {
popupOuterPadding = Util.measureHorizontalPaddingAndBorder(
getElement(), 2);
}
if (naturalMenuWidth < desiredWidth) {
menu.setWidth((desiredWidth - popupOuterPadding) + "px");
menuFirstChild.getStyle().setWidth(100, Unit.PCT);
naturalMenuWidth = desiredWidth;
}
if (BrowserInfo.get().isIE()) {
/*
* IE requires us to specify the width for the container
* element. Otherwise it will be 100% wide
*/
int rootWidth = naturalMenuWidth - popupOuterPadding;
getContainerElement().getStyle().setWidth(rootWidth, Unit.PX);
}
if (offsetHeight + getPopupTop() > Window.getClientHeight()
+ Window.getScrollTop()) {
// popup on top of input instead
top = getPopupTop() - offsetHeight
- VFilterSelect.this.getOffsetHeight();
if (top < 0) {
top = 0;
}
} else {
top = getPopupTop();
/*
* Take popup top margin into account. getPopupTop() returns the
* top value including the margin but the value we give must not
* include the margin.
*/
int topMargin = (top - topPosition);
top -= topMargin;
}
// fetch real width (mac FF bugs here due GWT popups overflow:auto )
offsetWidth = menuFirstChild.getOffsetWidth();
if (offsetWidth + getPopupLeft() > Window.getClientWidth()
+ Window.getScrollLeft()) {
left = VFilterSelect.this.getAbsoluteLeft()
+ VFilterSelect.this.getOffsetWidth()
+ Window.getScrollLeft() - offsetWidth;
if (left < 0) {
left = 0;
}
} else {
left = getPopupLeft();
}
setPopupPosition(left, top);
}
/**
* Was the popup just closed?
*
* @return true if popup was just closed
*/
public boolean isJustClosed() {
debug("VFS.SP: justClosed()");
final long now = (new Date()).getTime();
return (lastAutoClosed > 0 && (now - lastAutoClosed) < 200);
}
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.logical.shared.CloseHandler#onClose(com.google
* .gwt.event.logical.shared.CloseEvent)
*/
@Override
public void onClose(CloseEvent event) {
if (enableDebug) {
debug("VFS.SP: onClose(" + event.isAutoClosed() + ")");
}
if (event.isAutoClosed()) {
lastAutoClosed = (new Date()).getTime();
}
}
/**
* Updates style names in suggestion popup to help theme building.
*
* @param uidl
* UIDL for the whole combo box
* @param componentState
* shared state of the combo box
*/
public void updateStyleNames(UIDL uidl,
AbstractComponentState componentState) {
debug("VFS.SP: updateStyleNames()");
setStyleName(VFilterSelect.this.getStylePrimaryName()
+ "-suggestpopup");
menu.setStyleName(VFilterSelect.this.getStylePrimaryName()
+ "-suggestmenu");
status.setClassName(VFilterSelect.this.getStylePrimaryName()
+ "-status");
if (ComponentStateUtil.hasStyles(componentState)) {
for (String style : componentState.styles) {
if (!"".equals(style)) {
addStyleDependentName(style);
}
}
}
}
}
/**
* The menu where the suggestions are rendered
*/
public class SuggestionMenu extends MenuBar implements SubPartAware,
LoadHandler {
/**
* Tracks the item that is currently selected using the keyboard. This
* is need only because mouseover changes the selection and we do not
* want to use that selection when pressing enter to select the item.
*/
private MenuItem keyboardSelectedItem;
private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor(
100, new ScheduledCommand() {
@Override
public void execute() {
debug("VFS.SM: delayedImageLoadExecutioner()");
if (suggestionPopup.isVisible()
&& suggestionPopup.isAttached()) {
setWidth("");
getElement().getFirstChildElement().getStyle()
.clearWidth();
suggestionPopup
.setPopupPositionAndShow(suggestionPopup);
}
}
});
/**
* Default constructor
*/
SuggestionMenu() {
super(true);
debug("VFS.SM: constructor()");
addDomHandler(this, LoadEvent.getType());
}
/**
* Fixes menus height to use same space as full page would use. Needed
* to avoid height changes when quickly "scrolling" to last page
*/
public void fixHeightTo(int pagelenth) {
if (currentSuggestions.size() > 0) {
final int pixels = pagelenth * (getOffsetHeight() - 2)
/ currentSuggestions.size();
setHeight((pixels + 2) + "px");
}
}
/**
* Sets the suggestions rendered in the menu
*
* @param suggestions
* The suggestions to be rendered in the menu
*/
public void setSuggestions(
Collection suggestions) {
if (enableDebug) {
debug("VFS.SM: setSuggestions(" + suggestions + ")");
}
// Reset keyboard selection when contents is updated to avoid
// reusing old, invalid data
setKeyboardSelectedItem(null);
clearItems();
final Iterator it = suggestions.iterator();
while (it.hasNext()) {
final FilterSelectSuggestion s = it.next();
final MenuItem mi = new MenuItem(s.getDisplayString(), true, s);
Roles.getListitemRole().set(mi.getElement());
Util.sinkOnloadForImages(mi.getElement());
this.addItem(mi);
if (s == currentSuggestion) {
selectItem(mi);
}
}
}
/**
* Send the current selection to the server. Triggered when a selection
* is made or on a blur event.
*/
public void doSelectedItemAction() {
debug("VFS.SM: doSelectedItemAction()");
// do not send a value change event if null was and stays selected
final String enteredItemValue = tb.getText();
if (nullSelectionAllowed && "".equals(enteredItemValue)
&& selectedOptionKey != null
&& !"".equals(selectedOptionKey)) {
if (nullSelectItem) {
reset();
return;
}
// null is not visible on pages != 0, and not visible when
// filtering: handle separately
client.updateVariable(paintableId, "filter", "", false);
client.updateVariable(paintableId, "page", 0, false);
client.updateVariable(paintableId, "selected", new String[] {},
immediate);
suggestionPopup.hide();
return;
}
updateSelectionWhenReponseIsReceived = waitingForFilteringResponse;
if (!waitingForFilteringResponse) {
doPostFilterSelectedItemAction();
}
}
/**
* Triggered after a selection has been made
*/
public void doPostFilterSelectedItemAction() {
debug("VFS.SM: doPostFilterSelectedItemAction()");
final MenuItem item = getSelectedItem();
final String enteredItemValue = tb.getText();
updateSelectionWhenReponseIsReceived = false;
// check for exact match in menu
int p = getItems().size();
if (p > 0) {
for (int i = 0; i < p; i++) {
final MenuItem potentialExactMatch = getItems().get(i);
if (potentialExactMatch.getText().equals(enteredItemValue)) {
selectItem(potentialExactMatch);
// do not send a value change event if null was and
// stays selected
if (!"".equals(enteredItemValue)
|| (selectedOptionKey != null && !""
.equals(selectedOptionKey))) {
doItemAction(potentialExactMatch, true);
}
suggestionPopup.hide();
return;
}
}
}
if (allowNewItem) {
if (!prompting && !enteredItemValue.equals(lastNewItemString)) {
/*
* Store last sent new item string to avoid double sends
*/
lastNewItemString = enteredItemValue;
client.updateVariable(paintableId, "newitem",
enteredItemValue, immediate);
}
} else if (item != null
&& !"".equals(lastFilter)
&& (filteringmode == FilteringMode.CONTAINS ? item
.getText().toLowerCase()
.contains(lastFilter.toLowerCase()) : item
.getText().toLowerCase()
.startsWith(lastFilter.toLowerCase()))) {
doItemAction(item, true);
} else {
// currentSuggestion has key="" for nullselection
if (currentSuggestion != null
&& !currentSuggestion.key.equals("")) {
// An item (not null) selected
String text = currentSuggestion.getReplacementString();
tb.setText(text);
selectedOptionKey = currentSuggestion.key;
} else {
// Null selected
tb.setText("");
selectedOptionKey = null;
}
}
suggestionPopup.hide();
}
private static final String SUBPART_PREFIX = "item";
@Override
public Element getSubPartElement(String subPart) {
int index = Integer.parseInt(subPart.substring(SUBPART_PREFIX
.length()));
MenuItem item = getItems().get(index);
return item.getElement();
}
@Override
public String getSubPartName(Element subElement) {
if (!getElement().isOrHasChild(subElement)) {
return null;
}
Element menuItemRoot = subElement;
while (menuItemRoot != null
&& !menuItemRoot.getTagName().equalsIgnoreCase("td")) {
menuItemRoot = menuItemRoot.getParentElement().cast();
}
// "menuItemRoot" is now the root of the menu item
final int itemCount = getItems().size();
for (int i = 0; i < itemCount; i++) {
if (getItems().get(i).getElement() == menuItemRoot) {
String name = SUBPART_PREFIX + i;
return name;
}
}
return null;
}
@Override
public void onLoad(LoadEvent event) {
debug("VFS.SM: onLoad()");
// Handle icon onload events to ensure shadow is resized
// correctly
delayedImageLoadExecutioner.trigger();
}
public void selectFirstItem() {
debug("VFS.SM: selectFirstItem()");
MenuItem firstItem = getItems().get(0);
selectItem(firstItem);
}
private MenuItem getKeyboardSelectedItem() {
return keyboardSelectedItem;
}
public void setKeyboardSelectedItem(MenuItem firstItem) {
keyboardSelectedItem = firstItem;
}
public void selectLastItem() {
debug("VFS.SM: selectLastItem()");
List