();
/** For internal use only. May be removed or replaced in the future. */
public boolean immediate;
/** For internal use only. May be removed or replaced in the future. */
public String selectedOptionKey;
/** For internal use only. May be removed or replaced in the future. */
public boolean waitingForFilteringResponse = false;
/** For internal use only. May be removed or replaced in the future. */
public boolean updateSelectionWhenReponseIsReceived = false;
/** For internal use only. May be removed or replaced in the future. */
public boolean initDone = false;
/** For internal use only. May be removed or replaced in the future. */
public String lastFilter = "";
/** For internal use only. May be removed or replaced in the future. */
public enum Select {
NONE, FIRST, LAST
}
/** For internal use only. May be removed or replaced in the future. */
public Select selectPopupItemWhenResponseIsReceived = Select.NONE;
/**
* The current suggestion selected from the dropdown. This is one of the
* values in currentSuggestions except when filtering, in this case
* currentSuggestion might not be in currentSuggestions.
*
* For internal use only. May be removed or replaced in the future.
*/
public FilterSelectSuggestion currentSuggestion;
/** For internal use only. May be removed or replaced in the future. */
public boolean allowNewItem;
/** For internal use only. May be removed or replaced in the future. */
public int totalMatches;
/** For internal use only. May be removed or replaced in the future. */
public boolean nullSelectionAllowed;
/** For internal use only. May be removed or replaced in the future. */
public boolean nullSelectItem;
/** For internal use only. May be removed or replaced in the future. */
public boolean enabled;
/** For internal use only. May be removed or replaced in the future. */
public boolean readonly;
/** For internal use only. May be removed or replaced in the future. */
public FilteringMode filteringmode = FilteringMode.OFF;
// shown in unfocused empty field, disappears on focus (e.g "Search here")
private static final String CLASSNAME_PROMPT = "prompt";
/** For internal use only. May be removed or replaced in the future. */
public String inputPrompt = "";
/** For internal use only. May be removed or replaced in the future. */
public boolean prompting = false;
/**
* Set true when popupopened has been clicked. Cleared on each UIDL-update.
* This handles the special case where are not filtering yet and the
* selected value has changed on the server-side. See #2119
*
* For internal use only. May be removed or replaced in the future.
*/
public boolean popupOpenerClicked;
/** For internal use only. May be removed or replaced in the future. */
public int suggestionPopupMinWidth = 0;
private int popupWidth = -1;
/**
* Stores the last new item string to avoid double submissions. Cleared on
* uidl updates.
*
* For internal use only. May be removed or replaced in the future.
*/
public String lastNewItemString;
/** For internal use only. May be removed or replaced in the future. */
public boolean focused = false;
/**
* If set to false, the component should not allow entering text to the
* field even for filtering.
*/
private boolean textInputEnabled = true;
/**
* Default constructor.
*/
public VFilterSelect() {
tb = createTextBox();
suggestionPopup = createSuggestionPopup();
popupOpener.sinkEvents(Event.ONMOUSEDOWN);
Roles.getButtonRole()
.setAriaHiddenState(popupOpener.getElement(), true);
Roles.getButtonRole().set(popupOpener.getElement());
panel.add(tb);
panel.add(popupOpener);
initWidget(panel);
Roles.getComboboxRole().set(panel.getElement());
tb.addKeyDownHandler(this);
tb.addKeyUpHandler(this);
tb.addFocusHandler(this);
tb.addBlurHandler(this);
tb.addClickHandler(this);
popupOpener.addClickHandler(this);
setStyleName(CLASSNAME);
sinkEvents(Event.ONPASTE);
}
private static int getMarginBorderPaddingWidth(Element element) {
final ComputedStyle s = new ComputedStyle(element);
int[] margin = s.getMargin();
int[] border = s.getBorder();
int[] padding = s.getPadding();
return margin[1] + margin[3] + border[1] + border[3] + padding[1]
+ padding[3];
}
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.user.client.ui.Composite#onBrowserEvent(com.google.gwt
* .user.client.Event)
*/
@Override
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
if (event.getTypeInt() == Event.ONPASTE) {
if (textInputEnabled) {
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
filterOptions(currentPage);
}
});
}
}
}
/**
* This method will create the TextBox used by the VFilterSelect instance.
* It is invoked during the Constructor and should only be overridden if a
* custom TextBox shall be used. The overriding method cannot use any
* instance variables.
*
* @since 7.1.5
* @return TextBox instance used by this VFilterSelect
*/
protected TextBox createTextBox() {
return new FilterSelectTextBox();
}
/**
* This method will create the SuggestionPopup used by the VFilterSelect
* instance. It is invoked during the Constructor and should only be
* overridden if a custom SuggestionPopup shall be used. The overriding
* method cannot use any instance variables.
*
* @since 7.1.5
* @return SuggestionPopup instance used by this VFilterSelect
*/
protected SuggestionPopup createSuggestionPopup() {
return new SuggestionPopup();
}
@Override
public void setStyleName(String style) {
super.setStyleName(style);
updateStyleNames();
}
@Override
public void setStylePrimaryName(String style) {
super.setStylePrimaryName(style);
updateStyleNames();
}
protected void updateStyleNames() {
tb.setStyleName(getStylePrimaryName() + "-input");
popupOpener.setStyleName(getStylePrimaryName() + "-button");
suggestionPopup.setStyleName(getStylePrimaryName() + "-suggestpopup");
}
/**
* Does the Select have more pages?
*
* @return true if a next page exists, else false if the current page is the
* last page
*/
public boolean hasNextPage() {
if (pageLength > 0 && totalMatches > (currentPage + 1) * pageLength) {
return true;
} else {
return false;
}
}
/**
* Filters the options at a certain page. Uses the text box input as a
* filter
*
* @param page
* The page which items are to be filtered
*/
public void filterOptions(int page) {
filterOptions(page, tb.getText());
}
/**
* Filters the options at certain page using the given filter
*
* @param page
* The page to filter
* @param filter
* The filter to apply to the components
*/
public void filterOptions(int page, String filter) {
filterOptions(page, filter, true);
}
/**
* Filters the options at certain page using the given filter
*
* @param page
* The page to filter
* @param filter
* The filter to apply to the options
* @param immediate
* Whether to send the options request immediately
*/
private void filterOptions(int page, String filter, boolean immediate) {
debug("VFS: filterOptions(" + page + ", " + filter + ", " + immediate
+ ")");
if (filter.equals(lastFilter) && currentPage == page) {
if (!suggestionPopup.isAttached()) {
suggestionPopup.showSuggestions(currentSuggestions,
currentPage, totalMatches);
}
return;
}
if (!filter.equals(lastFilter)) {
// when filtering, let the server decide the page unless we've
// set the filter to empty and explicitly said that we want to see
// the results starting from page 0.
if ("".equals(filter) && page != 0) {
// let server decide
page = -1;
} else {
page = 0;
}
}
waitingForFilteringResponse = true;
client.updateVariable(paintableId, "filter", filter, false);
client.updateVariable(paintableId, "page", page, immediate);
afterUpdateClientVariables();
lastFilter = filter;
currentPage = page;
}
/** For internal use only. May be removed or replaced in the future. */
public void updateReadOnly() {
debug("VFS: updateReadOnly()");
tb.setReadOnly(readonly || !textInputEnabled);
}
public void setTextInputEnabled(boolean textInputEnabled) {
debug("VFS: setTextInputEnabled()");
// Always update styles as they might have been overwritten
if (textInputEnabled) {
removeStyleDependentName(STYLE_NO_INPUT);
Roles.getTextboxRole().removeAriaReadonlyProperty(tb.getElement());
} else {
addStyleDependentName(STYLE_NO_INPUT);
Roles.getTextboxRole().setAriaReadonlyProperty(tb.getElement(),
true);
}
if (this.textInputEnabled == textInputEnabled) {
return;
}
this.textInputEnabled = textInputEnabled;
updateReadOnly();
}
/**
* Sets the text in the text box.
*
* @param text
* the text to set in the text box
*/
public void setTextboxText(final String text) {
if (enableDebug) {
debug("VFS: setTextboxText(" + text + ")");
}
setText(text);
}
private void setText(final String text) {
/**
* To leave caret in the beginning of the line. SetSelectionRange
* wouldn't work on IE (see #13477)
*/
Direction previousDirection = tb.getDirection();
tb.setDirection(Direction.RTL);
tb.setText(text);
tb.setDirection(previousDirection);
}
/**
* Turns prompting on. When prompting is turned on a command prompt is shown
* in the text box if nothing has been entered.
*/
public void setPromptingOn() {
debug("VFS: setPromptingOn()");
if (!prompting) {
prompting = true;
addStyleDependentName(CLASSNAME_PROMPT);
}
setTextboxText(inputPrompt);
}
/**
* Turns prompting off. When prompting is turned on a command prompt is
* shown in the text box if nothing has been entered.
*
* For internal use only. May be removed or replaced in the future.
*
* @param text
* The text the text box should contain.
*/
public void setPromptingOff(String text) {
debug("VFS: setPromptingOff()");
setTextboxText(text);
if (prompting) {
prompting = false;
removeStyleDependentName(CLASSNAME_PROMPT);
}
}
/**
* Triggered when a suggestion is selected
*
* @param suggestion
* The suggestion that just got selected.
*/
public void onSuggestionSelected(FilterSelectSuggestion suggestion) {
if (enableDebug) {
debug("VFS: onSuggestionSelected(" + suggestion.caption + ": "
+ suggestion.key + ")");
}
updateSelectionWhenReponseIsReceived = false;
currentSuggestion = suggestion;
String newKey;
if (suggestion.key.equals("")) {
// "nullselection"
newKey = "";
} else {
// normal selection
newKey = suggestion.getOptionKey();
}
String text = suggestion.getReplacementString();
if ("".equals(newKey) && !focused) {
setPromptingOn();
} else {
setPromptingOff(text);
}
setSelectedItemIcon(suggestion.getIconUri());
if (!(newKey.equals(selectedOptionKey) || ("".equals(newKey) && selectedOptionKey == null))) {
selectedOptionKey = newKey;
client.updateVariable(paintableId, "selected",
new String[] { selectedOptionKey }, immediate);
afterUpdateClientVariables();
// currentPage = -1; // forget the page
}
suggestionPopup.hide();
}
/**
* Sets the icon URI of the selected item. The icon is shown on the left
* side of the item caption text. Set the URI to null to remove the icon.
*
* @param iconUri
* The URI of the icon
*/
public void setSelectedItemIcon(String iconUri) {
if (iconUri == null || iconUri.length() == 0) {
if (selectedItemIcon != null) {
panel.remove(selectedItemIcon);
selectedItemIcon = null;
afterSelectedItemIconChange();
}
} else {
if (selectedItemIcon != null) {
panel.remove(selectedItemIcon);
}
selectedItemIcon = new IconWidget(client.getIcon(iconUri));
// Older IE versions don't scale icon correctly if DOM
// contains height and width attributes.
selectedItemIcon.getElement().removeAttribute("height");
selectedItemIcon.getElement().removeAttribute("width");
selectedItemIcon.addDomHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
afterSelectedItemIconChange();
}
}, LoadEvent.getType());
panel.insert(selectedItemIcon, 0);
afterSelectedItemIconChange();
}
}
private void afterSelectedItemIconChange() {
if (BrowserInfo.get().isWebkit() || BrowserInfo.get().isIE8()) {
// Some browsers need a nudge to reposition the text field
forceReflow();
}
updateRootWidth();
if (selectedItemIcon != null) {
updateSelectedIconPosition();
}
}
private void forceReflow() {
WidgetUtil.setStyleTemporarily(tb.getElement(), "zoom", "1");
}
/**
* Positions the icon vertically in the middle. Should be called after the
* icon has loaded
*/
private void updateSelectedIconPosition() {
// Position icon vertically to middle
int availableHeight = 0;
availableHeight = getOffsetHeight();
int iconHeight = WidgetUtil.getRequiredHeight(selectedItemIcon);
int marginTop = (availableHeight - iconHeight) / 2;
selectedItemIcon.getElement().getStyle()
.setMarginTop(marginTop, Unit.PX);
}
private static Set navigationKeyCodes = new HashSet();
static {
navigationKeyCodes.add(KeyCodes.KEY_DOWN);
navigationKeyCodes.add(KeyCodes.KEY_UP);
navigationKeyCodes.add(KeyCodes.KEY_PAGEDOWN);
navigationKeyCodes.add(KeyCodes.KEY_PAGEUP);
navigationKeyCodes.add(KeyCodes.KEY_ENTER);
}
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.dom.client.KeyDownHandler#onKeyDown(com.google.gwt
* .event.dom.client.KeyDownEvent)
*/
@Override
public void onKeyDown(KeyDownEvent event) {
if (enabled && !readonly) {
int keyCode = event.getNativeKeyCode();
if (enableDebug) {
debug("VFS: key down: " + keyCode);
}
if (waitingForFilteringResponse
&& navigationKeyCodes.contains(keyCode)) {
/*
* Keyboard navigation events should not be handled while we are
* waiting for a response. This avoids flickering, disappearing
* items, wrongly interpreted responses and more.
*/
if (enableDebug) {
debug("Ignoring "
+ keyCode
+ " because we are waiting for a filtering response");
}
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
event.stopPropagation();
return;
}
if (suggestionPopup.isAttached()) {
if (enableDebug) {
debug("Keycode " + keyCode + " target is popup");
}
popupKeyDown(event);
} else {
if (enableDebug) {
debug("Keycode " + keyCode + " target is text field");
}
inputFieldKeyDown(event);
}
}
}
private void debug(String string) {
if (enableDebug) {
VConsole.error(string);
}
}
/**
* Triggered when a key is pressed in the text box
*
* @param event
* The KeyDownEvent
*/
private void inputFieldKeyDown(KeyDownEvent event) {
if (enableDebug) {
debug("VFS: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");
}
switch (event.getNativeKeyCode()) {
case KeyCodes.KEY_DOWN:
case KeyCodes.KEY_UP:
case KeyCodes.KEY_PAGEDOWN:
case KeyCodes.KEY_PAGEUP:
// open popup as from gadget
filterOptions(-1, "");
lastFilter = "";
tb.selectAll();
break;
case KeyCodes.KEY_ENTER:
/*
* This only handles the case when new items is allowed, a text is
* entered, the popup opener button is clicked to close the popup
* and enter is then pressed (see #7560).
*/
if (!allowNewItem) {
return;
}
if (currentSuggestion != null
&& tb.getText().equals(
currentSuggestion.getReplacementString())) {
// Retain behavior from #6686 by returning without stopping
// propagation if there's nothing to do
return;
}
suggestionPopup.menu.doSelectedItemAction();
event.stopPropagation();
break;
}
}
/**
* Triggered when a key was pressed in the suggestion popup.
*
* @param event
* The KeyDownEvent of the key
*/
private void popupKeyDown(KeyDownEvent event) {
if (enableDebug) {
debug("VFS: popupKeyDown(" + event.getNativeKeyCode() + ")");
}
// Propagation of handled events is stopped so other handlers such as
// shortcut key handlers do not also handle the same events.
switch (event.getNativeKeyCode()) {
case KeyCodes.KEY_DOWN:
suggestionPopup.selectNextItem();
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
event.stopPropagation();
break;
case KeyCodes.KEY_UP:
suggestionPopup.selectPrevItem();
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
event.stopPropagation();
break;
case KeyCodes.KEY_PAGEDOWN:
selectNextPage();
event.stopPropagation();
break;
case KeyCodes.KEY_PAGEUP:
selectPrevPage();
event.stopPropagation();
break;
case KeyCodes.KEY_ESCAPE:
reset();
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
event.stopPropagation();
break;
case KeyCodes.KEY_TAB:
case KeyCodes.KEY_ENTER:
if (!allowNewItem) {
onSuggestionSelected(currentSuggestions
.get(suggestionPopup.menu.getSelectedIndex()));
} else {
// Handle addition of new items.
suggestionPopup.menu.doSelectedItemAction();
}
event.stopPropagation();
break;
}
}
/*
* Show the prev page.
*/
private void selectPrevPage() {
if (currentPage > 0) {
filterOptions(currentPage - 1, lastFilter);
selectPopupItemWhenResponseIsReceived = Select.LAST;
}
}
/*
* Show the next page.
*/
private void selectNextPage() {
if (hasNextPage()) {
filterOptions(currentPage + 1, lastFilter);
selectPopupItemWhenResponseIsReceived = Select.FIRST;
}
}
/**
* Triggered when a key was depressed
*
* @param event
* The KeyUpEvent of the key depressed
*/
@Override
public void onKeyUp(KeyUpEvent event) {
if (enableDebug) {
debug("VFS: onKeyUp(" + event.getNativeKeyCode() + ")");
}
if (enabled && !readonly) {
switch (event.getNativeKeyCode()) {
case KeyCodes.KEY_ENTER:
case KeyCodes.KEY_TAB:
case KeyCodes.KEY_SHIFT:
case KeyCodes.KEY_CTRL:
case KeyCodes.KEY_ALT:
case KeyCodes.KEY_DOWN:
case KeyCodes.KEY_UP:
case KeyCodes.KEY_PAGEDOWN:
case KeyCodes.KEY_PAGEUP:
case KeyCodes.KEY_ESCAPE:
// NOP
break;
default:
if (textInputEnabled) {
// when filtering, we always want to see the results on the
// first page first.
filterOptions(0);
}
break;
}
}
}
/**
* Resets the Select to its initial state
*/
private void reset() {
debug("VFS: reset()");
if (currentSuggestion != null) {
String text = currentSuggestion.getReplacementString();
setPromptingOff(text);
setSelectedItemIcon(currentSuggestion.getIconUri());
selectedOptionKey = currentSuggestion.key;
} else {
if (focused || readonly || !enabled) {
setPromptingOff("");
} else {
setPromptingOn();
}
setSelectedItemIcon(null);
selectedOptionKey = null;
}
lastFilter = "";
suggestionPopup.hide();
}
/**
* Listener for popupopener
*/
@Override
public void onClick(ClickEvent event) {
debug("VFS: onClick()");
if (textInputEnabled
&& event.getNativeEvent().getEventTarget().cast() == tb
.getElement()) {
// Don't process clicks on the text field if text input is enabled
return;
}
if (enabled && !readonly) {
// ask suggestionPopup if it was just closed, we are using GWT
// Popup's auto close feature
if (!suggestionPopup.isJustClosed()) {
// If a focus event is not going to be sent, send the options
// request immediately; otherwise queue in the same burst as the
// focus event. Fixes #8321.
boolean immediate = focused
|| !client.hasEventListeners(this, EventId.FOCUS);
filterOptions(-1, "", immediate);
popupOpenerClicked = true;
lastFilter = "";
}
DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
focus();
tb.selectAll();
}
}
/**
* Update minimum width for FilterSelect textarea based on input prompt and
* suggestions.
*
* For internal use only. May be removed or replaced in the future.
*/
public void updateSuggestionPopupMinWidth() {
// used only to calculate minimum width
String captions = WidgetUtil.escapeHTML(inputPrompt);
for (FilterSelectSuggestion suggestion : currentSuggestions) {
// Collect captions so we can calculate minimum width for
// textarea
if (captions.length() > 0) {
captions += "|";
}
captions += WidgetUtil
.escapeHTML(suggestion.getReplacementString());
}
// Calculate minimum textarea width
suggestionPopupMinWidth = minWidth(captions);
}
/**
* Calculate minimum width for FilterSelect textarea.
*
* For internal use only. May be removed or replaced in the future.
*/
public native int minWidth(String captions)
/*-{
if(!captions || captions.length <= 0)
return 0;
captions = captions.split("|");
var d = $wnd.document.createElement("div");
var html = "";
for(var i=0; i < captions.length; i++) {
html += "
" + captions[i] + "
";
// TODO apply same CSS classname as in suggestionmenu
}
d.style.position = "absolute";
d.style.top = "0";
d.style.left = "0";
d.style.visibility = "hidden";
d.innerHTML = html;
$wnd.document.body.appendChild(d);
var w = d.offsetWidth;
$wnd.document.body.removeChild(d);
return w;
}-*/;
/**
* A flag which prevents a focus event from taking place
*/
boolean iePreventNextFocus = false;
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.dom.client.FocusHandler#onFocus(com.google.gwt.event
* .dom.client.FocusEvent)
*/
@Override
public void onFocus(FocusEvent event) {
debug("VFS: onFocus()");
/*
* When we disable a blur event in ie we need to refocus the textfield.
* This will cause a focus event we do not want to process, so in that
* case we just ignore it.
*/
if (BrowserInfo.get().isIE() && iePreventNextFocus) {
iePreventNextFocus = false;
return;
}
focused = true;
if (prompting && !readonly) {
setPromptingOff("");
}
addStyleDependentName("focus");
if (client.hasEventListeners(this, EventId.FOCUS)) {
client.updateVariable(paintableId, EventId.FOCUS, "", true);
afterUpdateClientVariables();
}
ComponentConnector connector = ConnectorMap.get(client).getConnector(
this);
client.getVTooltip().showAssistive(
connector.getTooltipInfo(getElement()));
}
/**
* A flag which cancels the blur event and sets the focus back to the
* textfield if the Browser is IE
*/
boolean preventNextBlurEventInIE = false;
/*
* (non-Javadoc)
*
* @see
* com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event
* .dom.client.BlurEvent)
*/
@Override
public void onBlur(BlurEvent event) {
debug("VFS: onBlur()");
if (BrowserInfo.get().isIE() && preventNextBlurEventInIE) {
/*
* Clicking in the suggestion popup or on the popup button in IE
* causes a blur event to be sent for the field. In other browsers
* this is prevented by canceling/preventing default behavior for
* the focus event, in IE we handle it here by refocusing the text
* field and ignoring the resulting focus event for the textfield
* (in onFocus).
*/
preventNextBlurEventInIE = false;
Element focusedElement = WidgetUtil.getFocusedElement();
if (getElement().isOrHasChild(focusedElement)
|| suggestionPopup.getElement()
.isOrHasChild(focusedElement)) {
// IF the suggestion popup or another part of the VFilterSelect
// was focused, move the focus back to the textfield and prevent
// the triggered focus event (in onFocus).
iePreventNextFocus = true;
tb.setFocus(true);
return;
}
}
focused = false;
if (!readonly) {
if (selectedOptionKey == null) {
setPromptingOn();
} else if (currentSuggestion != null) {
setPromptingOff(currentSuggestion.caption);
}
}
removeStyleDependentName("focus");
if (client.hasEventListeners(this, EventId.BLUR)) {
client.updateVariable(paintableId, EventId.BLUR, "", true);
afterUpdateClientVariables();
}
}
/*
* (non-Javadoc)
*
* @see com.vaadin.client.Focusable#focus()
*/
@Override
public void focus() {
debug("VFS: focus()");
focused = true;
if (prompting && !readonly) {
setPromptingOff("");
}
tb.setFocus(true);
}
/**
* Calculates the width of the select if the select has undefined width.
* Should be called when the width changes or when the icon changes.
*
* For internal use only. May be removed or replaced in the future.
*/
public void updateRootWidth() {
ComponentConnector paintable = ConnectorMap.get(client).getConnector(
this);
if (paintable.isUndefinedWidth()) {
/*
* When the select has a undefined with we need to check that we are
* only setting the text box width relative to the first page width
* of the items. If this is not done the text box width will change
* when the popup is used to view longer items than the text box is
* wide.
*/
int w = WidgetUtil.getRequiredWidth(this);
if ((!initDone || currentPage + 1 < 0)
&& suggestionPopupMinWidth > w) {
/*
* We want to compensate for the paddings just to preserve the
* exact size as in Vaadin 6.x, but we get here before
* MeasuredSize has been initialized.
* Util.measureHorizontalPaddingAndBorder does not work with
* border-box, so we must do this the hard way.
*/
Style style = getElement().getStyle();
String originalPadding = style.getPadding();
String originalBorder = style.getBorderWidth();
style.setPaddingLeft(0, Unit.PX);
style.setBorderWidth(0, Unit.PX);
style.setProperty("padding", originalPadding);
style.setProperty("borderWidth", originalBorder);
// Use util.getRequiredWidth instead of getOffsetWidth here
int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil
.getRequiredWidth(selectedItemIcon);
int buttonWidth = popupOpener == null ? 0 : WidgetUtil
.getRequiredWidth(popupOpener);
/*
* Instead of setting the width of the wrapper, set the width of
* the combobox. Subtract the width of the icon and the
* popupopener
*/
tb.setWidth((suggestionPopupMinWidth - iconWidth - buttonWidth)
+ "px");
}
/*
* Lock the textbox width to its current value if it's not already
* locked
*/
if (!tb.getElement().getStyle().getWidth().endsWith("px")) {
int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon
.getOffsetWidth();
tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px");
}
}
}
/**
* Get the width of the select in pixels where the text area and icon has
* been included.
*
* @return The width in pixels
*/
private int getMainWidth() {
return getOffsetWidth();
}
@Override
public void setWidth(String width) {
super.setWidth(width);
if (width.length() != 0) {
tb.setWidth("100%");
}
}
/**
* Handles special behavior of the mouse down event
*
* @param event
*/
private void handleMouseDownEvent(Event event) {
/*
* Prevent the keyboard focus from leaving the textfield by preventing
* the default behaviour of the browser. Fixes #4285.
*/
if (event.getTypeInt() == Event.ONMOUSEDOWN) {
event.preventDefault();
event.stopPropagation();
/*
* In IE the above wont work, the blur event will still trigger. So,
* we set a flag here to prevent the next blur event from happening.
* This is not needed if do not already have focus, in that case
* there will not be any blur event and we should not cancel the
* next blur.
*/
if (BrowserInfo.get().isIE() && focused) {
preventNextBlurEventInIE = true;
debug("VFS: Going to prevent next blur event on IE");
}
}
}
@Override
protected void onDetach() {
super.onDetach();
suggestionPopup.hide();
}
@Override
public com.google.gwt.user.client.Element getSubPartElement(String subPart) {
String[] parts = subPart.split("/");
if ("textbox".equals(parts[0])) {
return tb.getElement();
} else if ("button".equals(parts[0])) {
return popupOpener.getElement();
} else if ("popup".equals(parts[0]) && suggestionPopup.isAttached()) {
if (parts.length == 2) {
return suggestionPopup.menu.getSubPartElement(parts[1]);
}
return suggestionPopup.getElement();
}
return null;
}
@Override
public String getSubPartName(com.google.gwt.user.client.Element subElement) {
if (tb.getElement().isOrHasChild(subElement)) {
return "textbox";
} else if (popupOpener.getElement().isOrHasChild(subElement)) {
return "button";
} else if (suggestionPopup.getElement().isOrHasChild(subElement)) {
return "popup";
}
return null;
}
@Override
public void setAriaRequired(boolean required) {
AriaHelper.handleInputRequired(tb, required);
}
@Override
public void setAriaInvalid(boolean invalid) {
AriaHelper.handleInputInvalid(tb, invalid);
}
@Override
public void bindAriaCaption(
com.google.gwt.user.client.Element captionElement) {
AriaHelper.bindCaption(tb, captionElement);
}
/*
* Anything that should be set after the client updates the server.
*/
private void afterUpdateClientVariables() {
// We need this here to be consistent with the all the calls.
// Then set your specific selection type only after
// client.updateVariable() method call.
selectPopupItemWhenResponseIsReceived = Select.NONE;
}
@Override
public boolean isWorkPending() {
return waitingForFilteringResponse
|| suggestionPopup.lazyPageScroller.isRunning();
}
}