You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VFilterSelect.java 93KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Date;
  20. import java.util.HashSet;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Set;
  24. import com.google.gwt.aria.client.Roles;
  25. import com.google.gwt.core.client.JavaScriptObject;
  26. import com.google.gwt.core.client.Scheduler;
  27. import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  28. import com.google.gwt.dom.client.Document;
  29. import com.google.gwt.dom.client.Element;
  30. import com.google.gwt.dom.client.NativeEvent;
  31. import com.google.gwt.dom.client.Node;
  32. import com.google.gwt.dom.client.Style;
  33. import com.google.gwt.dom.client.Style.Display;
  34. import com.google.gwt.dom.client.Style.Unit;
  35. import com.google.gwt.dom.client.Style.Visibility;
  36. import com.google.gwt.event.dom.client.BlurEvent;
  37. import com.google.gwt.event.dom.client.BlurHandler;
  38. import com.google.gwt.event.dom.client.ClickEvent;
  39. import com.google.gwt.event.dom.client.ClickHandler;
  40. import com.google.gwt.event.dom.client.FocusEvent;
  41. import com.google.gwt.event.dom.client.FocusHandler;
  42. import com.google.gwt.event.dom.client.KeyCodes;
  43. import com.google.gwt.event.dom.client.KeyDownEvent;
  44. import com.google.gwt.event.dom.client.KeyDownHandler;
  45. import com.google.gwt.event.dom.client.KeyUpEvent;
  46. import com.google.gwt.event.dom.client.KeyUpHandler;
  47. import com.google.gwt.event.dom.client.LoadEvent;
  48. import com.google.gwt.event.dom.client.LoadHandler;
  49. import com.google.gwt.event.logical.shared.CloseEvent;
  50. import com.google.gwt.event.logical.shared.CloseHandler;
  51. import com.google.gwt.i18n.client.HasDirection.Direction;
  52. import com.google.gwt.user.client.Command;
  53. import com.google.gwt.user.client.DOM;
  54. import com.google.gwt.user.client.Event;
  55. import com.google.gwt.user.client.Timer;
  56. import com.google.gwt.user.client.Window;
  57. import com.google.gwt.user.client.ui.Composite;
  58. import com.google.gwt.user.client.ui.FlowPanel;
  59. import com.google.gwt.user.client.ui.HTML;
  60. import com.google.gwt.user.client.ui.PopupPanel;
  61. import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
  62. import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
  63. import com.google.gwt.user.client.ui.TextBox;
  64. import com.google.gwt.user.client.ui.Widget;
  65. import com.vaadin.client.ApplicationConnection;
  66. import com.vaadin.client.BrowserInfo;
  67. import com.vaadin.client.ComputedStyle;
  68. import com.vaadin.client.DeferredWorker;
  69. import com.vaadin.client.Focusable;
  70. import com.vaadin.client.VConsole;
  71. import com.vaadin.client.WidgetUtil;
  72. import com.vaadin.client.ui.aria.AriaHelper;
  73. import com.vaadin.client.ui.aria.HandlesAriaCaption;
  74. import com.vaadin.client.ui.aria.HandlesAriaInvalid;
  75. import com.vaadin.client.ui.aria.HandlesAriaRequired;
  76. import com.vaadin.client.ui.combobox.ComboBoxConnector;
  77. import com.vaadin.client.ui.menubar.MenuBar;
  78. import com.vaadin.client.ui.menubar.MenuItem;
  79. import com.vaadin.shared.AbstractComponentState;
  80. import com.vaadin.shared.EventId;
  81. import com.vaadin.shared.ui.ComponentStateUtil;
  82. import com.vaadin.shared.ui.combobox.FilteringMode;
  83. import com.vaadin.shared.util.SharedUtil;
  84. /**
  85. * Client side implementation of the Select component.
  86. *
  87. * TODO needs major refactoring (to be extensible etc)
  88. */
  89. @SuppressWarnings("deprecation")
  90. public class VFilterSelect extends Composite implements Field, KeyDownHandler,
  91. KeyUpHandler, ClickHandler, FocusHandler, BlurHandler, Focusable,
  92. SubPartAware, HandlesAriaCaption, HandlesAriaInvalid,
  93. HandlesAriaRequired, DeferredWorker {
  94. /**
  95. * Represents a suggestion in the suggestion popup box
  96. */
  97. public class FilterSelectSuggestion implements Suggestion, Command {
  98. private final String key;
  99. private final String caption;
  100. private String untranslatedIconUri;
  101. private String style;
  102. /**
  103. * Constructor
  104. *
  105. * @param key
  106. * item key, empty string for a special null item not in
  107. * container
  108. * @param caption
  109. * item caption
  110. * @param style
  111. * item style name, can be empty string
  112. * @param untranslatedIconUri
  113. * icon URI or null
  114. */
  115. public FilterSelectSuggestion(String key, String caption, String style,
  116. String untranslatedIconUri) {
  117. this.key = key;
  118. this.caption = caption;
  119. this.style = style;
  120. this.untranslatedIconUri = untranslatedIconUri;
  121. }
  122. /**
  123. * Gets the visible row in the popup as a HTML string. The string
  124. * contains an image tag with the rows icon (if an icon has been
  125. * specified) and the caption of the item
  126. */
  127. @Override
  128. public String getDisplayString() {
  129. final StringBuffer sb = new StringBuffer();
  130. ApplicationConnection client = connector.getConnection();
  131. final Icon icon = client.getIcon(client
  132. .translateVaadinUri(untranslatedIconUri));
  133. if (icon != null) {
  134. sb.append(icon.getElement().getString());
  135. }
  136. String content;
  137. if ("".equals(caption)) {
  138. // Ensure that empty options use the same height as other
  139. // options and are not collapsed (#7506)
  140. content = " ";
  141. } else {
  142. content = WidgetUtil.escapeHTML(caption);
  143. }
  144. sb.append("<span>" + content + "</span>");
  145. return sb.toString();
  146. }
  147. /**
  148. * Get a string that represents this item. This is used in the text box.
  149. */
  150. @Override
  151. public String getReplacementString() {
  152. return caption;
  153. }
  154. /**
  155. * Get the option key which represents the item on the server side.
  156. *
  157. * @return The key of the item
  158. */
  159. public String getOptionKey() {
  160. return key;
  161. }
  162. /**
  163. * Get the URI of the icon. Used when constructing the displayed option.
  164. *
  165. * @return
  166. */
  167. public String getIconUri() {
  168. ApplicationConnection client = connector.getConnection();
  169. return client.translateVaadinUri(untranslatedIconUri);
  170. }
  171. /**
  172. * Gets the style set for this suggestion item. Styles are typically set
  173. * by a server-side {@link com.vaadin.ui.ComboBox.ItemStyleGenerator}.
  174. * The returned style is prefixed by <code>v-filterselect-item-</code>.
  175. *
  176. * @since 7.5.6
  177. * @return the style name to use, or <code>null</code> to not apply any
  178. * custom style.
  179. */
  180. public String getStyle() {
  181. return style;
  182. }
  183. /**
  184. * Executes a selection of this item.
  185. */
  186. @Override
  187. public void execute() {
  188. onSuggestionSelected(this);
  189. }
  190. @Override
  191. public boolean equals(Object obj) {
  192. if (!(obj instanceof FilterSelectSuggestion)) {
  193. return false;
  194. }
  195. FilterSelectSuggestion other = (FilterSelectSuggestion) obj;
  196. if ((key == null && other.key != null)
  197. || (key != null && !key.equals(other.key))) {
  198. return false;
  199. }
  200. if ((caption == null && other.caption != null)
  201. || (caption != null && !caption.equals(other.caption))) {
  202. return false;
  203. }
  204. if (!SharedUtil.equals(untranslatedIconUri,
  205. other.untranslatedIconUri)) {
  206. return false;
  207. }
  208. if (!SharedUtil.equals(style, other.style)) {
  209. return false;
  210. }
  211. return true;
  212. }
  213. }
  214. /** An inner class that handles all logic related to mouse wheel. */
  215. private class MouseWheeler extends JsniMousewheelHandler {
  216. public MouseWheeler() {
  217. super(VFilterSelect.this);
  218. }
  219. @Override
  220. protected native JavaScriptObject createMousewheelListenerFunction(
  221. Widget widget)
  222. /*-{
  223. return $entry(function(e) {
  224. var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX;
  225. var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY;
  226. // IE8 has only delta y
  227. if (isNaN(deltaY)) {
  228. deltaY = -0.5*e.wheelDelta;
  229. }
  230. @com.vaadin.client.ui.VFilterSelect.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode);
  231. });
  232. }-*/;
  233. }
  234. /**
  235. * A utility class that contains utility methods that are usually called
  236. * from JSNI.
  237. * <p>
  238. * The methods are moved in this class to minimize the amount of JSNI code
  239. * as much as feasible.
  240. */
  241. static class JsniUtil {
  242. private static final int DOM_DELTA_PIXEL = 0;
  243. private static final int DOM_DELTA_LINE = 1;
  244. private static final int DOM_DELTA_PAGE = 2;
  245. // Rough estimation of item height
  246. private static final int SCROLL_UNIT_PX = 25;
  247. private static double deltaSum = 0;
  248. public static void moveScrollFromEvent(final Widget widget,
  249. final double deltaX, final double deltaY,
  250. final NativeEvent event, final int deltaMode) {
  251. if (!Double.isNaN(deltaY)) {
  252. VFilterSelect filterSelect = (VFilterSelect) widget;
  253. switch (deltaMode) {
  254. case DOM_DELTA_LINE:
  255. if (deltaY >= 0) {
  256. filterSelect.suggestionPopup.selectNextItem();
  257. } else {
  258. filterSelect.suggestionPopup.selectPrevItem();
  259. }
  260. break;
  261. case DOM_DELTA_PAGE:
  262. if (deltaY >= 0) {
  263. filterSelect.selectNextPage();
  264. } else {
  265. filterSelect.selectPrevPage();
  266. }
  267. break;
  268. case DOM_DELTA_PIXEL:
  269. default:
  270. // Accumulate dampened deltas
  271. deltaSum += Math.pow(Math.abs(deltaY), 0.7)
  272. * Math.signum(deltaY);
  273. // "Scroll" if change exceeds item height
  274. while (Math.abs(deltaSum) >= SCROLL_UNIT_PX) {
  275. if (!filterSelect.waitingForFilteringResponse) {
  276. // Move selection if page flip is not in progress
  277. if (deltaSum < 0) {
  278. filterSelect.suggestionPopup.selectPrevItem();
  279. } else {
  280. filterSelect.suggestionPopup.selectNextItem();
  281. }
  282. }
  283. deltaSum -= SCROLL_UNIT_PX * Math.signum(deltaSum);
  284. }
  285. break;
  286. }
  287. }
  288. }
  289. }
  290. /**
  291. * Represents the popup box with the selection options. Wraps a suggestion
  292. * menu.
  293. */
  294. public class SuggestionPopup extends VOverlay implements PositionCallback,
  295. CloseHandler<PopupPanel> {
  296. private static final int Z_INDEX = 30000;
  297. /** For internal use only. May be removed or replaced in the future. */
  298. public final SuggestionMenu menu;
  299. private final Element up = DOM.createDiv();
  300. private final Element down = DOM.createDiv();
  301. private final Element status = DOM.createDiv();
  302. private boolean isPagingEnabled = true;
  303. private long lastAutoClosed;
  304. private int popupOuterPadding = -1;
  305. private int topPosition;
  306. private final MouseWheeler mouseWheeler = new MouseWheeler();
  307. /**
  308. * Default constructor
  309. */
  310. SuggestionPopup() {
  311. super(true, false, true);
  312. debug("VFS.SP: constructor()");
  313. setOwner(VFilterSelect.this);
  314. menu = new SuggestionMenu();
  315. setWidget(menu);
  316. getElement().getStyle().setZIndex(Z_INDEX);
  317. final Element root = getContainerElement();
  318. up.setInnerHTML("<span>Prev</span>");
  319. DOM.sinkEvents(up, Event.ONCLICK);
  320. down.setInnerHTML("<span>Next</span>");
  321. DOM.sinkEvents(down, Event.ONCLICK);
  322. root.insertFirst(up);
  323. root.appendChild(down);
  324. root.appendChild(status);
  325. DOM.sinkEvents(root, Event.ONMOUSEDOWN | Event.ONMOUSEWHEEL);
  326. addCloseHandler(this);
  327. Roles.getListRole().set(getElement());
  328. setPreviewingAllNativeEvents(true);
  329. }
  330. @Override
  331. protected void onLoad() {
  332. super.onLoad();
  333. // Register mousewheel listener on paged select
  334. if (pageLength > 0) {
  335. mouseWheeler.attachMousewheelListener(getElement());
  336. }
  337. }
  338. @Override
  339. protected void onUnload() {
  340. mouseWheeler.detachMousewheelListener(getElement());
  341. super.onUnload();
  342. }
  343. /**
  344. * Shows the popup where the user can see the filtered options
  345. *
  346. * @param currentSuggestions
  347. * The filtered suggestions
  348. * @param currentPage
  349. * The current page number
  350. * @param totalSuggestions
  351. * The total amount of suggestions
  352. */
  353. public void showSuggestions(
  354. final Collection<FilterSelectSuggestion> currentSuggestions,
  355. final int currentPage, final int totalSuggestions) {
  356. debug("VFS.SP: showSuggestions(" + currentSuggestions + ", "
  357. + currentPage + ", " + totalSuggestions + ")");
  358. /*
  359. * We need to defer the opening of the popup so that the parent DOM
  360. * has stabilized so we can calculate an absolute top and left
  361. * correctly. This issue manifests when a Combobox is placed in
  362. * another popupView which also needs to calculate the absoluteTop()
  363. * to position itself. #9768
  364. *
  365. * After deferring the showSuggestions method, a problem with
  366. * navigating in the combo box occurs. Because of that the method
  367. * navigateItemAfterPageChange in ComboBoxConnector class, which
  368. * navigates to the exact item after page was changed also was
  369. * marked as deferred. #11333
  370. */
  371. final SuggestionPopup popup = this;
  372. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  373. @Override
  374. public void execute() {
  375. // Add TT anchor point
  376. getElement().setId("VAADIN_COMBOBOX_OPTIONLIST");
  377. menu.setSuggestions(currentSuggestions);
  378. final int x = VFilterSelect.this.getAbsoluteLeft();
  379. topPosition = tb.getAbsoluteTop();
  380. topPosition += tb.getOffsetHeight();
  381. setPopupPosition(x, topPosition);
  382. int nullOffset = (nullSelectionAllowed
  383. && "".equals(lastFilter) ? 1 : 0);
  384. boolean firstPage = (currentPage == 0);
  385. final int first = currentPage * pageLength + 1
  386. - (firstPage ? 0 : nullOffset);
  387. final int last = first
  388. + currentSuggestions.size()
  389. - 1
  390. - (firstPage && "".equals(lastFilter) ? nullOffset
  391. : 0);
  392. final int matches = totalSuggestions - nullOffset;
  393. if (last > 0) {
  394. // nullsel not counted, as requested by user
  395. status.setInnerText((matches == 0 ? 0 : first) + "-"
  396. + last + "/" + matches);
  397. } else {
  398. status.setInnerText("");
  399. }
  400. // We don't need to show arrows or statusbar if there is
  401. // only one page
  402. if (totalSuggestions <= pageLength || pageLength == 0) {
  403. setPagingEnabled(false);
  404. } else {
  405. setPagingEnabled(true);
  406. }
  407. setPrevButtonActive(first > 1);
  408. setNextButtonActive(last < matches);
  409. // clear previously fixed width
  410. menu.setWidth("");
  411. menu.getElement().getFirstChildElement().getStyle()
  412. .clearWidth();
  413. setPopupPositionAndShow(popup);
  414. // Fix for #14173
  415. // IE9 and IE10 have a bug, when resize an a element with
  416. // box-shadow.
  417. // IE9 and IE10 need explicit update to remove extra
  418. // box-shadows
  419. if (BrowserInfo.get().isIE9() || BrowserInfo.get().isIE10()) {
  420. forceReflow();
  421. }
  422. }
  423. });
  424. }
  425. /**
  426. * Should the next page button be visible to the user?
  427. *
  428. * @param active
  429. */
  430. private void setNextButtonActive(boolean active) {
  431. if (enableDebug) {
  432. debug("VFS.SP: setNextButtonActive(" + active + ")");
  433. }
  434. if (active) {
  435. DOM.sinkEvents(down, Event.ONCLICK);
  436. down.setClassName(VFilterSelect.this.getStylePrimaryName()
  437. + "-nextpage");
  438. } else {
  439. DOM.sinkEvents(down, 0);
  440. down.setClassName(VFilterSelect.this.getStylePrimaryName()
  441. + "-nextpage-off");
  442. }
  443. }
  444. /**
  445. * Should the previous page button be visible to the user
  446. *
  447. * @param active
  448. */
  449. private void setPrevButtonActive(boolean active) {
  450. if (enableDebug) {
  451. debug("VFS.SP: setPrevButtonActive(" + active + ")");
  452. }
  453. if (active) {
  454. DOM.sinkEvents(up, Event.ONCLICK);
  455. up.setClassName(VFilterSelect.this.getStylePrimaryName()
  456. + "-prevpage");
  457. } else {
  458. DOM.sinkEvents(up, 0);
  459. up.setClassName(VFilterSelect.this.getStylePrimaryName()
  460. + "-prevpage-off");
  461. }
  462. }
  463. /**
  464. * Selects the next item in the filtered selections
  465. */
  466. public void selectNextItem() {
  467. debug("VFS.SP: selectNextItem()");
  468. final int index = menu.getSelectedIndex() + 1;
  469. if (menu.getItems().size() > index) {
  470. selectItem(menu.getItems().get(index));
  471. } else {
  472. selectNextPage();
  473. }
  474. }
  475. /**
  476. * Selects the previous item in the filtered selections
  477. */
  478. public void selectPrevItem() {
  479. debug("VFS.SP: selectPrevItem()");
  480. final int index = menu.getSelectedIndex() - 1;
  481. if (index > -1) {
  482. selectItem(menu.getItems().get(index));
  483. } else if (index == -1) {
  484. selectPrevPage();
  485. } else {
  486. if (!menu.getItems().isEmpty()) {
  487. selectLastItem();
  488. }
  489. }
  490. }
  491. /**
  492. * Select the first item of the suggestions list popup.
  493. *
  494. * @since 7.2.6
  495. */
  496. public void selectFirstItem() {
  497. debug("VFS.SP: selectFirstItem()");
  498. selectItem(menu.getFirstItem());
  499. }
  500. /**
  501. * Select the last item of the suggestions list popup.
  502. *
  503. * @since 7.2.6
  504. */
  505. public void selectLastItem() {
  506. debug("VFS.SP: selectLastItem()");
  507. selectItem(menu.getLastItem());
  508. }
  509. /*
  510. * Sets the selected item in the popup menu.
  511. */
  512. private void selectItem(final MenuItem newSelectedItem) {
  513. menu.selectItem(newSelectedItem);
  514. // Set the icon.
  515. FilterSelectSuggestion suggestion = (FilterSelectSuggestion) newSelectedItem
  516. .getCommand();
  517. setSelectedItemIcon(suggestion.getIconUri());
  518. // Set the text.
  519. setText(suggestion.getReplacementString());
  520. }
  521. /*
  522. * Using a timer to scroll up or down the pages so when we receive lots
  523. * of consecutive mouse wheel events the pages does not flicker.
  524. */
  525. private LazyPageScroller lazyPageScroller = new LazyPageScroller();
  526. private class LazyPageScroller extends Timer {
  527. private int pagesToScroll = 0;
  528. @Override
  529. public void run() {
  530. debug("VFS.SP.LPS: run()");
  531. if (pagesToScroll != 0) {
  532. if (!isWaitingForFilteringResponse()) {
  533. /*
  534. * Avoid scrolling while we are waiting for a response
  535. * because otherwise the waiting flag will be reset in
  536. * the first response and the second response will be
  537. * ignored, causing an empty popup...
  538. *
  539. * As long as the scrolling delay is suitable
  540. * double/triple clicks will work by scrolling two or
  541. * three pages at a time and this should not be a
  542. * problem.
  543. */
  544. filterOptions(currentPage + pagesToScroll, lastFilter);
  545. }
  546. pagesToScroll = 0;
  547. }
  548. }
  549. public void scrollUp() {
  550. debug("VFS.SP.LPS: scrollUp()");
  551. if (pageLength > 0 && currentPage + pagesToScroll > 0) {
  552. pagesToScroll--;
  553. cancel();
  554. schedule(200);
  555. }
  556. }
  557. public void scrollDown() {
  558. debug("VFS.SP.LPS: scrollDown()");
  559. if (pageLength > 0
  560. && totalMatches > (currentPage + pagesToScroll + 1)
  561. * pageLength) {
  562. pagesToScroll++;
  563. cancel();
  564. schedule(200);
  565. }
  566. }
  567. }
  568. private void scroll(double deltaY) {
  569. boolean scrollActive = menu.isScrollActive();
  570. debug("VFS.SP: scroll() scrollActive: " + scrollActive);
  571. if (!scrollActive) {
  572. if (deltaY > 0d) {
  573. lazyPageScroller.scrollDown();
  574. } else {
  575. lazyPageScroller.scrollUp();
  576. }
  577. }
  578. }
  579. @Override
  580. public void onBrowserEvent(Event event) {
  581. debug("VFS.SP: onBrowserEvent()");
  582. if (event.getTypeInt() == Event.ONCLICK) {
  583. final Element target = DOM.eventGetTarget(event);
  584. if (target == up || target == DOM.getChild(up, 0)) {
  585. lazyPageScroller.scrollUp();
  586. } else if (target == down || target == DOM.getChild(down, 0)) {
  587. lazyPageScroller.scrollDown();
  588. }
  589. }
  590. /*
  591. * Prevent the keyboard focus from leaving the textfield by
  592. * preventing the default behaviour of the browser. Fixes #4285.
  593. */
  594. handleMouseDownEvent(event);
  595. }
  596. /**
  597. * Should paging be enabled. If paging is enabled then only a certain
  598. * amount of items are visible at a time and a scrollbar or buttons are
  599. * visible to change page. If paging is turned of then all options are
  600. * rendered into the popup menu.
  601. *
  602. * @param paging
  603. * Should the paging be turned on?
  604. */
  605. public void setPagingEnabled(boolean paging) {
  606. debug("VFS.SP: setPagingEnabled(" + paging + ")");
  607. if (isPagingEnabled == paging) {
  608. return;
  609. }
  610. if (paging) {
  611. down.getStyle().clearDisplay();
  612. up.getStyle().clearDisplay();
  613. status.getStyle().clearDisplay();
  614. } else {
  615. down.getStyle().setDisplay(Display.NONE);
  616. up.getStyle().setDisplay(Display.NONE);
  617. status.getStyle().setDisplay(Display.NONE);
  618. }
  619. isPagingEnabled = paging;
  620. }
  621. @Override
  622. public void setPosition(int offsetWidth, int offsetHeight) {
  623. debug("VFS.SP: setPosition(" + offsetWidth + ", " + offsetHeight
  624. + ")");
  625. int top = topPosition;
  626. int left = getPopupLeft();
  627. // reset menu size and retrieve its "natural" size
  628. menu.setHeight("");
  629. if (currentPage > 0 && !hasNextPage()) {
  630. // fix height to avoid height change when getting to last page
  631. menu.fixHeightTo(pageLength);
  632. }
  633. final int desiredHeight = offsetHeight = getOffsetHeight();
  634. final int desiredWidth = getMainWidth();
  635. debug("VFS.SP: desired[" + desiredWidth + ", " + desiredHeight
  636. + "]");
  637. Element menuFirstChild = menu.getElement().getFirstChildElement();
  638. int naturalMenuWidth;
  639. if (BrowserInfo.get().isIE()
  640. && BrowserInfo.get().getBrowserMajorVersion() < 10) {
  641. // On IE 8 & 9 visibility is set to hidden and measuring
  642. // elements while they are hidden yields incorrect results
  643. String before = menu.getElement().getParentElement().getStyle()
  644. .getVisibility();
  645. menu.getElement().getParentElement().getStyle()
  646. .setVisibility(Visibility.VISIBLE);
  647. naturalMenuWidth = WidgetUtil.getRequiredWidth(menuFirstChild);
  648. menu.getElement().getParentElement().getStyle()
  649. .setProperty("visibility", before);
  650. } else {
  651. naturalMenuWidth = WidgetUtil.getRequiredWidth(menuFirstChild);
  652. }
  653. if (popupOuterPadding == -1) {
  654. popupOuterPadding = WidgetUtil
  655. .measureHorizontalPaddingAndBorder(menu.getElement(), 2)
  656. + WidgetUtil.measureHorizontalPaddingAndBorder(
  657. suggestionPopup.getElement(), 0);
  658. }
  659. updateMenuWidth(desiredWidth, naturalMenuWidth);
  660. if (BrowserInfo.get().isIE()
  661. && BrowserInfo.get().getBrowserMajorVersion() < 11) {
  662. // Must take margin,border,padding manually into account for
  663. // menu element as we measure the element child and set width to
  664. // the element parent
  665. double naturalMenuOuterWidth;
  666. if (BrowserInfo.get().getBrowserMajorVersion() < 10) {
  667. // On IE 8 & 9 visibility is set to hidden and measuring
  668. // elements while they are hidden yields incorrect results
  669. String before = menu.getElement().getParentElement()
  670. .getStyle().getVisibility();
  671. menu.getElement().getParentElement().getStyle()
  672. .setVisibility(Visibility.VISIBLE);
  673. naturalMenuOuterWidth = WidgetUtil
  674. .getRequiredWidthDouble(menuFirstChild)
  675. + getMarginBorderPaddingWidth(menu.getElement());
  676. menu.getElement().getParentElement().getStyle()
  677. .setProperty("visibility", before);
  678. } else {
  679. naturalMenuOuterWidth = WidgetUtil
  680. .getRequiredWidthDouble(menuFirstChild)
  681. + getMarginBorderPaddingWidth(menu.getElement());
  682. }
  683. /*
  684. * IE requires us to specify the width for the container
  685. * element. Otherwise it will be 100% wide
  686. */
  687. double rootWidth = Math.max(desiredWidth - popupOuterPadding,
  688. naturalMenuOuterWidth);
  689. getContainerElement().getStyle().setWidth(rootWidth, Unit.PX);
  690. }
  691. final int textInputHeight = VFilterSelect.this.getOffsetHeight();
  692. final int textInputTopOnPage = tb.getAbsoluteTop();
  693. final int viewportOffset = Document.get().getScrollTop();
  694. final int textInputTopInViewport = textInputTopOnPage
  695. - viewportOffset;
  696. final int textInputBottomInViewport = textInputTopInViewport
  697. + textInputHeight;
  698. final int spaceAboveInViewport = textInputTopInViewport;
  699. final int spaceBelowInViewport = Window.getClientHeight()
  700. - textInputBottomInViewport;
  701. if (spaceBelowInViewport < offsetHeight
  702. && spaceBelowInViewport < spaceAboveInViewport) {
  703. // popup on top of input instead
  704. if (offsetHeight > spaceAboveInViewport) {
  705. // Shrink popup height to fit above
  706. offsetHeight = spaceAboveInViewport;
  707. }
  708. top = textInputTopOnPage - offsetHeight;
  709. } else {
  710. // Show below, position calculated in showSuggestions for some
  711. // strange reason
  712. top = topPosition;
  713. offsetHeight = Math.min(offsetHeight, spaceBelowInViewport);
  714. }
  715. // fetch real width (mac FF bugs here due GWT popups overflow:auto )
  716. offsetWidth = menuFirstChild.getOffsetWidth();
  717. if (offsetHeight < desiredHeight) {
  718. int menuHeight = offsetHeight;
  719. if (isPagingEnabled) {
  720. menuHeight -= up.getOffsetHeight() + down.getOffsetHeight()
  721. + status.getOffsetHeight();
  722. } else {
  723. final ComputedStyle s = new ComputedStyle(menu.getElement());
  724. menuHeight -= s.getIntProperty("marginBottom")
  725. + s.getIntProperty("marginTop");
  726. }
  727. // If the available page height is really tiny then this will be
  728. // negative and an exception will be thrown on setHeight.
  729. int menuElementHeight = menu.getItemOffsetHeight();
  730. if (menuHeight < menuElementHeight) {
  731. menuHeight = menuElementHeight;
  732. }
  733. menu.setHeight(menuHeight + "px");
  734. if (suggestionPopupWidth == null) {
  735. final int naturalMenuWidthPlusScrollBar = naturalMenuWidth
  736. + WidgetUtil.getNativeScrollbarSize();
  737. if (offsetWidth < naturalMenuWidthPlusScrollBar) {
  738. menu.setWidth(naturalMenuWidthPlusScrollBar + "px");
  739. }
  740. }
  741. }
  742. if (offsetWidth + left > Window.getClientWidth()) {
  743. left = VFilterSelect.this.getAbsoluteLeft()
  744. + VFilterSelect.this.getOffsetWidth() - offsetWidth;
  745. if (left < 0) {
  746. left = 0;
  747. menu.setWidth(Window.getClientWidth() + "px");
  748. }
  749. if (BrowserInfo.get().isIE()
  750. && BrowserInfo.get().getBrowserMajorVersion() < 10) {
  751. setTdWidth(menu.getElement(), Window.getClientWidth() - 8);
  752. }
  753. }
  754. setPopupPosition(left, top);
  755. menu.scrollSelectionIntoView();
  756. }
  757. /**
  758. * Adds in-line CSS rules to the DOM according to the
  759. * suggestionPopupWidth field
  760. *
  761. * @param desiredWidth
  762. * @param naturalMenuWidth
  763. */
  764. private void updateMenuWidth(final int desiredWidth,
  765. int naturalMenuWidth) {
  766. /**
  767. * Three different width modes for the suggestion pop-up:
  768. *
  769. * 1. Legacy "null"-mode: width is determined by the longest item
  770. * caption for each page while still maintaining minimum width of
  771. * (desiredWidth - popupOuterPadding)
  772. *
  773. * 2. relative to the component itself
  774. *
  775. * 3. fixed width
  776. */
  777. String width = "auto";
  778. if (suggestionPopupWidth == null) {
  779. if (naturalMenuWidth < desiredWidth) {
  780. naturalMenuWidth = desiredWidth - popupOuterPadding;
  781. width = (desiredWidth - popupOuterPadding) + "px";
  782. }
  783. } else if (isrelativeUnits(suggestionPopupWidth)) {
  784. float mainComponentWidth = desiredWidth - popupOuterPadding;
  785. // convert percentage value to fraction
  786. int widthInPx = Math.round(mainComponentWidth
  787. * asFraction(suggestionPopupWidth));
  788. width = widthInPx + "px";
  789. } else {
  790. // use as fixed width CSS definition
  791. width = WidgetUtil.escapeAttribute(suggestionPopupWidth);
  792. }
  793. menu.setWidth(width);
  794. // IE8 or 9?
  795. if (BrowserInfo.get().isIE()
  796. && BrowserInfo.get().getBrowserMajorVersion() < 10) {
  797. // using legacy mode?
  798. if (suggestionPopupWidth == null) {
  799. // set the TD widths manually as these browsers do not
  800. // respect display: block; width:100% rules
  801. setTdWidth(menu.getElement(), naturalMenuWidth);
  802. } else {
  803. int compensation = WidgetUtil
  804. .measureHorizontalPaddingAndBorder(
  805. menu.getElement(), 4);
  806. setTdWidth(menu.getElement(), menu.getOffsetWidth()
  807. - compensation);
  808. }
  809. }
  810. }
  811. /**
  812. * Descends to child elements until finds TD elements and sets their
  813. * width in pixels. Can be used to workaround IE8 & 9 TD element
  814. * display: block issues
  815. *
  816. * @param parent
  817. * @param width
  818. */
  819. private void setTdWidth(Node parent, int width) {
  820. for (int i = 0; i < parent.getChildCount(); i++) {
  821. Node child = parent.getChild(i);
  822. if ("td".equals(child.getNodeName().toLowerCase())) {
  823. ((Element) child).getStyle().setWidth(width, Unit.PX);
  824. } else {
  825. setTdWidth(child, width);
  826. }
  827. }
  828. }
  829. /**
  830. * Returns the percentage value as a fraction, e.g. 42% -> 0.42
  831. *
  832. * @param percentage
  833. */
  834. private float asFraction(String percentage) {
  835. String trimmed = percentage.trim();
  836. String withoutPercentSign = trimmed.substring(0,
  837. trimmed.length() - 1);
  838. float asFraction = Float.parseFloat(withoutPercentSign) / 100;
  839. return asFraction;
  840. }
  841. /**
  842. * @since 7.7
  843. * @param suggestionPopupWidth
  844. * @return
  845. */
  846. private boolean isrelativeUnits(String suggestionPopupWidth) {
  847. return suggestionPopupWidth.trim().endsWith("%");
  848. }
  849. /**
  850. * Was the popup just closed?
  851. *
  852. * @return true if popup was just closed
  853. */
  854. public boolean isJustClosed() {
  855. debug("VFS.SP: justClosed()");
  856. final long now = (new Date()).getTime();
  857. return (lastAutoClosed > 0 && (now - lastAutoClosed) < 200);
  858. }
  859. /*
  860. * (non-Javadoc)
  861. *
  862. * @see
  863. * com.google.gwt.event.logical.shared.CloseHandler#onClose(com.google
  864. * .gwt.event.logical.shared.CloseEvent)
  865. */
  866. @Override
  867. public void onClose(CloseEvent<PopupPanel> event) {
  868. if (enableDebug) {
  869. debug("VFS.SP: onClose(" + event.isAutoClosed() + ")");
  870. }
  871. if (event.isAutoClosed()) {
  872. lastAutoClosed = (new Date()).getTime();
  873. }
  874. }
  875. /**
  876. * Updates style names in suggestion popup to help theme building.
  877. *
  878. * @param componentState
  879. * shared state of the combo box
  880. */
  881. public void updateStyleNames(AbstractComponentState componentState) {
  882. debug("VFS.SP: updateStyleNames()");
  883. setStyleName(VFilterSelect.this.getStylePrimaryName()
  884. + "-suggestpopup");
  885. menu.setStyleName(VFilterSelect.this.getStylePrimaryName()
  886. + "-suggestmenu");
  887. status.setClassName(VFilterSelect.this.getStylePrimaryName()
  888. + "-status");
  889. if (ComponentStateUtil.hasStyles(componentState)) {
  890. for (String style : componentState.styles) {
  891. if (!"".equals(style)) {
  892. addStyleDependentName(style);
  893. }
  894. }
  895. }
  896. }
  897. }
  898. /**
  899. * The menu where the suggestions are rendered
  900. */
  901. public class SuggestionMenu extends MenuBar implements SubPartAware,
  902. LoadHandler {
  903. private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor(
  904. 100, new ScheduledCommand() {
  905. @Override
  906. public void execute() {
  907. debug("VFS.SM: delayedImageLoadExecutioner()");
  908. if (suggestionPopup.isVisible()
  909. && suggestionPopup.isAttached()) {
  910. setWidth("");
  911. getElement().getFirstChildElement().getStyle()
  912. .clearWidth();
  913. suggestionPopup
  914. .setPopupPositionAndShow(suggestionPopup);
  915. }
  916. }
  917. });
  918. /**
  919. * Default constructor
  920. */
  921. SuggestionMenu() {
  922. super(true);
  923. debug("VFS.SM: constructor()");
  924. addDomHandler(this, LoadEvent.getType());
  925. setScrollEnabled(true);
  926. }
  927. /**
  928. * Fixes menus height to use same space as full page would use. Needed
  929. * to avoid height changes when quickly "scrolling" to last page.
  930. */
  931. public void fixHeightTo(int pageItemsCount) {
  932. setHeight(getPreferredHeight(pageItemsCount));
  933. }
  934. /*
  935. * Gets the preferred height of the menu including pageItemsCount items.
  936. */
  937. String getPreferredHeight(int pageItemsCount) {
  938. if (currentSuggestions.size() > 0) {
  939. final int pixels = (getPreferredHeight() / currentSuggestions
  940. .size()) * pageItemsCount;
  941. return pixels + "px";
  942. } else {
  943. return "";
  944. }
  945. }
  946. /**
  947. * Sets the suggestions rendered in the menu
  948. *
  949. * @param suggestions
  950. * The suggestions to be rendered in the menu
  951. */
  952. public void setSuggestions(
  953. Collection<FilterSelectSuggestion> suggestions) {
  954. if (enableDebug) {
  955. debug("VFS.SM: setSuggestions(" + suggestions + ")");
  956. }
  957. clearItems();
  958. final Iterator<FilterSelectSuggestion> it = suggestions.iterator();
  959. boolean isFirstIteration = true;
  960. while (it.hasNext()) {
  961. final FilterSelectSuggestion s = it.next();
  962. final MenuItem mi = new MenuItem(s.getDisplayString(), true, s);
  963. String style = s.getStyle();
  964. if (style != null) {
  965. mi.addStyleName("v-filterselect-item-" + style);
  966. }
  967. Roles.getListitemRole().set(mi.getElement());
  968. WidgetUtil.sinkOnloadForImages(mi.getElement());
  969. this.addItem(mi);
  970. // By default, first item on the list is always highlighted,
  971. // unless adding new items is allowed.
  972. if (isFirstIteration && !allowNewItem) {
  973. selectItem(mi);
  974. }
  975. // If the filter matches the current selection, highlight that
  976. // instead of the first item.
  977. if (tb.getText().equals(s.getReplacementString())
  978. && s == currentSuggestion) {
  979. selectItem(mi);
  980. }
  981. isFirstIteration = false;
  982. }
  983. if (suggestionPopupWidth != null && BrowserInfo.get().isIE()
  984. && BrowserInfo.get().getBrowserMajorVersion() < 10) {
  985. // set TD width to a low value so that they won't mandate the
  986. // suggestion pop-up width
  987. suggestionPopup
  988. .setTdWidth(suggestionPopup.menu.getElement(), 1);
  989. }
  990. }
  991. /**
  992. * Send the current selection to the server. Triggered when a selection
  993. * is made with the ENTER key.
  994. */
  995. public void doSelectedItemAction() {
  996. debug("VFS.SM: doSelectedItemAction()");
  997. // do not send a value change event if null was and stays selected
  998. final String enteredItemValue = tb.getText();
  999. if (nullSelectionAllowed && "".equals(enteredItemValue)
  1000. && selectedOptionKey != null
  1001. && !"".equals(selectedOptionKey)) {
  1002. if (nullSelectItem) {
  1003. reset();
  1004. return;
  1005. }
  1006. // null is not visible on pages != 0, and not visible when
  1007. // filtering: handle separately
  1008. connector.requestFirstPage();
  1009. suggestionPopup.hide();
  1010. return;
  1011. }
  1012. doPostFilterWhenReady();
  1013. }
  1014. /**
  1015. * Perform the post-filter action either now (if not waiting for a
  1016. * server response) or when a response is received.
  1017. */
  1018. private void doPostFilterWhenReady() {
  1019. if (isWaitingForFilteringResponse()) {
  1020. dataReceivedHandler.setUpdateOnDataReceived(true);
  1021. } else {
  1022. dataReceivedHandler.setUpdateOnDataReceived(false);
  1023. doPostFilterSelectedItemAction();
  1024. }
  1025. }
  1026. /**
  1027. * Triggered after a selection has been made.
  1028. */
  1029. public void doPostFilterSelectedItemAction() {
  1030. debug("VFS.SM: doPostFilterSelectedItemAction()");
  1031. final MenuItem item = getSelectedItem();
  1032. final String enteredItemValue = tb.getText();
  1033. // check for exact match in menu
  1034. int p = getItems().size();
  1035. if (p > 0) {
  1036. for (int i = 0; i < p; i++) {
  1037. final MenuItem potentialExactMatch = getItems().get(i);
  1038. if (potentialExactMatch.getText().equals(enteredItemValue)) {
  1039. selectItem(potentialExactMatch);
  1040. // do not send a value change event if null was and
  1041. // stays selected
  1042. if (!"".equals(enteredItemValue)
  1043. || (selectedOptionKey != null && !""
  1044. .equals(selectedOptionKey))) {
  1045. doItemAction(potentialExactMatch, true);
  1046. }
  1047. suggestionPopup.hide();
  1048. return;
  1049. }
  1050. }
  1051. }
  1052. if (allowNewItem) {
  1053. if (!prompting && !enteredItemValue.equals(lastNewItemString)) {
  1054. /*
  1055. * Store last sent new item string to avoid double sends
  1056. */
  1057. lastNewItemString = enteredItemValue;
  1058. connector.sendNewItem(enteredItemValue);
  1059. }
  1060. } else if (item != null
  1061. && !"".equals(lastFilter)
  1062. && (filteringmode == FilteringMode.CONTAINS ? item
  1063. .getText().toLowerCase()
  1064. .contains(lastFilter.toLowerCase()) : item
  1065. .getText().toLowerCase()
  1066. .startsWith(lastFilter.toLowerCase()))) {
  1067. doItemAction(item, true);
  1068. } else {
  1069. // currentSuggestion has key="" for nullselection
  1070. if (currentSuggestion != null
  1071. && !currentSuggestion.key.equals("")) {
  1072. // An item (not null) selected
  1073. String text = currentSuggestion.getReplacementString();
  1074. setText(text);
  1075. selectedOptionKey = currentSuggestion.key;
  1076. } else {
  1077. // Null selected
  1078. setText("");
  1079. selectedOptionKey = null;
  1080. }
  1081. }
  1082. suggestionPopup.hide();
  1083. }
  1084. private static final String SUBPART_PREFIX = "item";
  1085. @Override
  1086. public com.google.gwt.user.client.Element getSubPartElement(
  1087. String subPart) {
  1088. int index = Integer.parseInt(subPart.substring(SUBPART_PREFIX
  1089. .length()));
  1090. MenuItem item = getItems().get(index);
  1091. return item.getElement();
  1092. }
  1093. @Override
  1094. public String getSubPartName(
  1095. com.google.gwt.user.client.Element subElement) {
  1096. if (!getElement().isOrHasChild(subElement)) {
  1097. return null;
  1098. }
  1099. Element menuItemRoot = subElement;
  1100. while (menuItemRoot != null
  1101. && !menuItemRoot.getTagName().equalsIgnoreCase("td")) {
  1102. menuItemRoot = menuItemRoot.getParentElement().cast();
  1103. }
  1104. // "menuItemRoot" is now the root of the menu item
  1105. final int itemCount = getItems().size();
  1106. for (int i = 0; i < itemCount; i++) {
  1107. if (getItems().get(i).getElement() == menuItemRoot) {
  1108. String name = SUBPART_PREFIX + i;
  1109. return name;
  1110. }
  1111. }
  1112. return null;
  1113. }
  1114. @Override
  1115. public void onLoad(LoadEvent event) {
  1116. debug("VFS.SM: onLoad()");
  1117. // Handle icon onload events to ensure shadow is resized
  1118. // correctly
  1119. delayedImageLoadExecutioner.trigger();
  1120. }
  1121. /**
  1122. * @deprecated use {@link SuggestionPopup#selectFirstItem()} instead.
  1123. */
  1124. @Deprecated
  1125. public void selectFirstItem() {
  1126. debug("VFS.SM: selectFirstItem()");
  1127. MenuItem firstItem = getItems().get(0);
  1128. selectItem(firstItem);
  1129. }
  1130. /**
  1131. * @deprecated use {@link SuggestionPopup#selectLastItem()} instead.
  1132. */
  1133. @Deprecated
  1134. public void selectLastItem() {
  1135. debug("VFS.SM: selectLastItem()");
  1136. List<MenuItem> items = getItems();
  1137. MenuItem lastItem = items.get(items.size() - 1);
  1138. selectItem(lastItem);
  1139. }
  1140. /*
  1141. * Gets the height of one menu item.
  1142. */
  1143. int getItemOffsetHeight() {
  1144. List<MenuItem> items = getItems();
  1145. return items != null && items.size() > 0 ? items.get(0)
  1146. .getOffsetHeight() : 0;
  1147. }
  1148. /*
  1149. * Gets the width of one menu item.
  1150. */
  1151. int getItemOffsetWidth() {
  1152. List<MenuItem> items = getItems();
  1153. return items != null && items.size() > 0 ? items.get(0)
  1154. .getOffsetWidth() : 0;
  1155. }
  1156. /**
  1157. * Returns true if the scroll is active on the menu element or if the
  1158. * menu currently displays the last page with less items then the
  1159. * maximum visibility (in which case the scroll is not active, but the
  1160. * scroll is active for any other page in general).
  1161. *
  1162. * @since 7.2.6
  1163. */
  1164. @Override
  1165. public boolean isScrollActive() {
  1166. String height = getElement().getStyle().getHeight();
  1167. String preferredHeight = getPreferredHeight(pageLength);
  1168. return !(height == null || height.length() == 0 || height
  1169. .equals(preferredHeight));
  1170. }
  1171. }
  1172. /**
  1173. * TextBox variant used as input element for filter selects, which prevents
  1174. * selecting text when disabled.
  1175. *
  1176. * @since 7.1.5
  1177. */
  1178. public class FilterSelectTextBox extends TextBox {
  1179. /**
  1180. * Creates a new filter select text box.
  1181. *
  1182. * @since 7.6.4
  1183. */
  1184. public FilterSelectTextBox() {
  1185. /*-
  1186. * Stop the browser from showing its own suggestion popup.
  1187. *
  1188. * Using an invalid value instead of "off" as suggested by
  1189. * https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
  1190. *
  1191. * Leaving the non-standard Safari options autocapitalize and
  1192. * autocorrect untouched since those do not interfere in the same
  1193. * way, and they might be useful in a combo box where new items are
  1194. * allowed.
  1195. */
  1196. getElement().setAttribute("autocomplete", "nope");
  1197. }
  1198. /**
  1199. * Overridden to avoid selecting text when text input is disabled
  1200. */
  1201. @Override
  1202. public void setSelectionRange(int pos, int length) {
  1203. if (textInputEnabled) {
  1204. /*
  1205. * set selection range with a backwards direction: anchor at the
  1206. * back, focus at the front. This means that items that are too
  1207. * long to display will display from the start and not the end
  1208. * even on Firefox.
  1209. *
  1210. * We need the JSNI function to set selection range so that we
  1211. * can use the optional direction attribute to set the anchor to
  1212. * the end and the focus to the start. This makes Firefox work
  1213. * the same way as other browsers (#13477)
  1214. */
  1215. WidgetUtil.setSelectionRange(getElement(), pos, length,
  1216. "backward");
  1217. } else {
  1218. /*
  1219. * Setting the selectionrange for an uneditable textbox leads to
  1220. * unwanted behaviour when the width of the textbox is narrower
  1221. * than the width of the entry: the end of the entry is shown
  1222. * instead of the beginning. (see #13477)
  1223. *
  1224. * To avoid this, we set the caret to the beginning of the line.
  1225. */
  1226. super.setSelectionRange(0, 0);
  1227. }
  1228. }
  1229. }
  1230. /**
  1231. * Handler receiving notifications from the connector and updating the
  1232. * widget state accordingly.
  1233. *
  1234. * This class is still subject to change and should not be considered as
  1235. * public stable API.
  1236. *
  1237. * @since
  1238. */
  1239. public class DataReceivedHandler {
  1240. private Runnable navigationCallback = null;
  1241. /**
  1242. * Set true when popupopened has been clicked. Cleared on each
  1243. * UIDL-update. This handles the special case where are not filtering
  1244. * yet and the selected value has changed on the server-side. See #2119
  1245. * <p>
  1246. * For internal use only. May be removed or replaced in the future.
  1247. */
  1248. private boolean popupOpenerClicked = false;
  1249. private boolean updateOnDataReceived = false;
  1250. /**
  1251. * Called by the connector when new data for the last requested filter
  1252. * is received from the server.
  1253. */
  1254. public void dataReceived() {
  1255. suggestionPopup.showSuggestions(currentSuggestions, currentPage,
  1256. totalMatches);
  1257. setWaitingForFilteringResponse(false);
  1258. if (!popupOpenerClicked) {
  1259. navigateItemAfterPageChange();
  1260. }
  1261. if (updateOnDataReceived) {
  1262. updateOnDataReceived = false;
  1263. suggestionPopup.menu.doPostFilterSelectedItemAction();
  1264. }
  1265. popupOpenerClicked = false;
  1266. }
  1267. /*
  1268. * This method navigates to the proper item in the combobox page. This
  1269. * should be executed after setSuggestions() method which is called from
  1270. * vFilterSelect.showSuggestions(). ShowSuggestions() method builds the
  1271. * page content. As far as setSuggestions() method is called as
  1272. * deferred, navigateItemAfterPageChange method should be also be called
  1273. * as deferred. #11333
  1274. */
  1275. private void navigateItemAfterPageChange() {
  1276. if (navigationCallback != null) {
  1277. // pageChangeCallback is not reset here but after any server
  1278. // request in case you are in between two requests both changing
  1279. // the page back and forth
  1280. // we're paging w/ arrows
  1281. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  1282. @Override
  1283. public void execute() {
  1284. if (navigationCallback != null) {
  1285. navigationCallback.run();
  1286. }
  1287. }
  1288. });
  1289. }
  1290. }
  1291. /**
  1292. * Called by the connector when any request has been sent to the server,
  1293. * before waiting for a reply.
  1294. */
  1295. public void anyRequestSentToServer() {
  1296. navigationCallback = null;
  1297. }
  1298. /**
  1299. * Set a callback that is invoked when a page change occurs if there
  1300. * have not been intervening requests to the server. The callback is
  1301. * reset when any additional request is made to the server.
  1302. *
  1303. * @param callback
  1304. */
  1305. public void setNavigationCallback(Runnable callback) {
  1306. navigationCallback = callback;
  1307. }
  1308. /**
  1309. * Record that the popup opener has been clicked and the popup should be
  1310. * opened on the next request.
  1311. *
  1312. * This handles the special case where are not filtering yet and the
  1313. * selected value has changed on the server-side. See #2119. The flag is
  1314. * cleared on each UIDL reply.
  1315. */
  1316. public void popupOpenerClicked() {
  1317. popupOpenerClicked = true;
  1318. }
  1319. /**
  1320. * Returns true if the popup opener has been clicked. This method is for
  1321. * internal use only and will most likely be removed in the future.
  1322. */
  1323. public boolean isPopupOpenerClicked() {
  1324. return popupOpenerClicked;
  1325. }
  1326. public void setUpdateOnDataReceived(boolean update) {
  1327. updateOnDataReceived = update;
  1328. }
  1329. /**
  1330. * Called by the connector when it has finished handling any reply from
  1331. * the server, regardless of what was updated.
  1332. */
  1333. public void serverReplyHandled() {
  1334. popupOpenerClicked = false;
  1335. }
  1336. }
  1337. @Deprecated
  1338. public static final FilteringMode FILTERINGMODE_OFF = FilteringMode.OFF;
  1339. @Deprecated
  1340. public static final FilteringMode FILTERINGMODE_STARTSWITH = FilteringMode.STARTSWITH;
  1341. @Deprecated
  1342. public static final FilteringMode FILTERINGMODE_CONTAINS = FilteringMode.CONTAINS;
  1343. public static final String CLASSNAME = "v-filterselect";
  1344. private static final String STYLE_NO_INPUT = "no-input";
  1345. /** For internal use only. May be removed or replaced in the future. */
  1346. public int pageLength = 10;
  1347. private boolean enableDebug = false;
  1348. private final FlowPanel panel = new FlowPanel();
  1349. /**
  1350. * The text box where the filter is written
  1351. * <p>
  1352. * For internal use only. May be removed or replaced in the future.
  1353. */
  1354. public final TextBox tb;
  1355. /** For internal use only. May be removed or replaced in the future. */
  1356. public final SuggestionPopup suggestionPopup;
  1357. /**
  1358. * Used when measuring the width of the popup
  1359. */
  1360. private final HTML popupOpener = new HTML("") {
  1361. /*
  1362. * (non-Javadoc)
  1363. *
  1364. * @see
  1365. * com.google.gwt.user.client.ui.Widget#onBrowserEvent(com.google.gwt
  1366. * .user.client.Event)
  1367. */
  1368. @Override
  1369. public void onBrowserEvent(Event event) {
  1370. super.onBrowserEvent(event);
  1371. /*
  1372. * Prevent the keyboard focus from leaving the textfield by
  1373. * preventing the default behaviour of the browser. Fixes #4285.
  1374. */
  1375. handleMouseDownEvent(event);
  1376. }
  1377. };
  1378. private class IconWidget extends Widget {
  1379. IconWidget(Icon icon) {
  1380. setElement(icon.getElement());
  1381. addDomHandler(VFilterSelect.this, ClickEvent.getType());
  1382. }
  1383. }
  1384. private IconWidget selectedItemIcon;
  1385. /** For internal use only. May be removed or replaced in the future. */
  1386. public ComboBoxConnector connector;
  1387. /** For internal use only. May be removed or replaced in the future. */
  1388. public int currentPage;
  1389. /**
  1390. * A collection of available suggestions (options) as received from the
  1391. * server.
  1392. * <p>
  1393. * For internal use only. May be removed or replaced in the future.
  1394. */
  1395. public final List<FilterSelectSuggestion> currentSuggestions = new ArrayList<FilterSelectSuggestion>();
  1396. /** For internal use only. May be removed or replaced in the future. */
  1397. public String selectedOptionKey;
  1398. /** For internal use only. May be removed or replaced in the future. */
  1399. private boolean waitingForFilteringResponse = false;
  1400. /** For internal use only. May be removed or replaced in the future. */
  1401. public boolean initDone = false;
  1402. /** For internal use only. May be removed or replaced in the future. */
  1403. public String lastFilter = "";
  1404. /**
  1405. * The current suggestion selected from the dropdown. This is one of the
  1406. * values in currentSuggestions except when filtering, in this case
  1407. * currentSuggestion might not be in currentSuggestions.
  1408. * <p>
  1409. * For internal use only. May be removed or replaced in the future.
  1410. */
  1411. public FilterSelectSuggestion currentSuggestion;
  1412. /** For internal use only. May be removed or replaced in the future. */
  1413. public boolean allowNewItem;
  1414. /** For internal use only. May be removed or replaced in the future. */
  1415. public int totalMatches;
  1416. /** For internal use only. May be removed or replaced in the future. */
  1417. public boolean nullSelectionAllowed;
  1418. /** For internal use only. May be removed or replaced in the future. */
  1419. public boolean nullSelectItem;
  1420. /** For internal use only. May be removed or replaced in the future. */
  1421. public boolean enabled;
  1422. /** For internal use only. May be removed or replaced in the future. */
  1423. public boolean readonly;
  1424. /** For internal use only. May be removed or replaced in the future. */
  1425. public FilteringMode filteringmode = FilteringMode.OFF;
  1426. // shown in unfocused empty field, disappears on focus (e.g "Search here")
  1427. private static final String CLASSNAME_PROMPT = "prompt";
  1428. /** For internal use only. May be removed or replaced in the future. */
  1429. public String inputPrompt = "";
  1430. /** For internal use only. May be removed or replaced in the future. */
  1431. public boolean prompting = false;
  1432. /** For internal use only. May be removed or replaced in the future. */
  1433. public int suggestionPopupMinWidth = 0;
  1434. public String suggestionPopupWidth = null;
  1435. private int popupWidth = -1;
  1436. /**
  1437. * Stores the last new item string to avoid double submissions. Cleared on
  1438. * uidl updates.
  1439. * <p>
  1440. * For internal use only. May be removed or replaced in the future.
  1441. */
  1442. public String lastNewItemString;
  1443. /** For internal use only. May be removed or replaced in the future. */
  1444. public boolean focused = false;
  1445. /**
  1446. * If set to false, the component should not allow entering text to the
  1447. * field even for filtering.
  1448. */
  1449. private boolean textInputEnabled = true;
  1450. private final DataReceivedHandler dataReceivedHandler = new DataReceivedHandler();
  1451. /**
  1452. * Default constructor.
  1453. */
  1454. public VFilterSelect() {
  1455. tb = createTextBox();
  1456. suggestionPopup = createSuggestionPopup();
  1457. popupOpener.sinkEvents(Event.ONMOUSEDOWN);
  1458. Roles.getButtonRole()
  1459. .setAriaHiddenState(popupOpener.getElement(), true);
  1460. Roles.getButtonRole().set(popupOpener.getElement());
  1461. panel.add(tb);
  1462. panel.add(popupOpener);
  1463. initWidget(panel);
  1464. Roles.getComboboxRole().set(panel.getElement());
  1465. tb.addKeyDownHandler(this);
  1466. tb.addKeyUpHandler(this);
  1467. tb.addFocusHandler(this);
  1468. tb.addBlurHandler(this);
  1469. tb.addClickHandler(this);
  1470. popupOpener.addClickHandler(this);
  1471. setStyleName(CLASSNAME);
  1472. sinkEvents(Event.ONPASTE);
  1473. }
  1474. private static double getMarginBorderPaddingWidth(Element element) {
  1475. final ComputedStyle s = new ComputedStyle(element);
  1476. return s.getMarginWidth() + s.getBorderWidth() + s.getPaddingWidth();
  1477. }
  1478. /*
  1479. * (non-Javadoc)
  1480. *
  1481. * @see
  1482. * com.google.gwt.user.client.ui.Composite#onBrowserEvent(com.google.gwt
  1483. * .user.client.Event)
  1484. */
  1485. @Override
  1486. public void onBrowserEvent(Event event) {
  1487. super.onBrowserEvent(event);
  1488. if (event.getTypeInt() == Event.ONPASTE) {
  1489. if (textInputEnabled) {
  1490. Scheduler.get().scheduleDeferred(new ScheduledCommand() {
  1491. @Override
  1492. public void execute() {
  1493. filterOptions(currentPage);
  1494. }
  1495. });
  1496. }
  1497. }
  1498. }
  1499. /**
  1500. * This method will create the TextBox used by the VFilterSelect instance.
  1501. * It is invoked during the Constructor and should only be overridden if a
  1502. * custom TextBox shall be used. The overriding method cannot use any
  1503. * instance variables.
  1504. *
  1505. * @since 7.1.5
  1506. * @return TextBox instance used by this VFilterSelect
  1507. */
  1508. protected TextBox createTextBox() {
  1509. return new FilterSelectTextBox();
  1510. }
  1511. /**
  1512. * This method will create the SuggestionPopup used by the VFilterSelect
  1513. * instance. It is invoked during the Constructor and should only be
  1514. * overridden if a custom SuggestionPopup shall be used. The overriding
  1515. * method cannot use any instance variables.
  1516. *
  1517. * @since 7.1.5
  1518. * @return SuggestionPopup instance used by this VFilterSelect
  1519. */
  1520. protected SuggestionPopup createSuggestionPopup() {
  1521. return new SuggestionPopup();
  1522. }
  1523. @Override
  1524. public void setStyleName(String style) {
  1525. super.setStyleName(style);
  1526. updateStyleNames();
  1527. }
  1528. @Override
  1529. public void setStylePrimaryName(String style) {
  1530. super.setStylePrimaryName(style);
  1531. updateStyleNames();
  1532. }
  1533. protected void updateStyleNames() {
  1534. tb.setStyleName(getStylePrimaryName() + "-input");
  1535. popupOpener.setStyleName(getStylePrimaryName() + "-button");
  1536. suggestionPopup.setStyleName(getStylePrimaryName() + "-suggestpopup");
  1537. }
  1538. /**
  1539. * Does the Select have more pages?
  1540. *
  1541. * @return true if a next page exists, else false if the current page is the
  1542. * last page
  1543. */
  1544. public boolean hasNextPage() {
  1545. if (pageLength > 0 && totalMatches > (currentPage + 1) * pageLength) {
  1546. return true;
  1547. } else {
  1548. return false;
  1549. }
  1550. }
  1551. /**
  1552. * Filters the options at a certain page. Uses the text box input as a
  1553. * filter
  1554. *
  1555. * @param page
  1556. * The page which items are to be filtered
  1557. */
  1558. public void filterOptions(int page) {
  1559. filterOptions(page, tb.getText());
  1560. }
  1561. /**
  1562. * Filters the options at certain page using the given filter
  1563. *
  1564. * @param page
  1565. * The page to filter
  1566. * @param filter
  1567. * The filter to apply to the components
  1568. */
  1569. public void filterOptions(int page, String filter) {
  1570. filterOptions(page, filter, true);
  1571. }
  1572. /**
  1573. * Filters the options at certain page using the given filter
  1574. *
  1575. * @param page
  1576. * The page to filter
  1577. * @param filter
  1578. * The filter to apply to the options
  1579. * @param immediate
  1580. * Whether to send the options request immediately
  1581. */
  1582. private void filterOptions(int page, String filter, boolean immediate) {
  1583. debug("VFS: filterOptions(" + page + ", " + filter + ", " + immediate
  1584. + ")");
  1585. if (filter.equals(lastFilter) && currentPage == page) {
  1586. if (!suggestionPopup.isAttached()) {
  1587. suggestionPopup.showSuggestions(currentSuggestions,
  1588. currentPage, totalMatches);
  1589. }
  1590. return;
  1591. }
  1592. if (!filter.equals(lastFilter)) {
  1593. // when filtering, let the server decide the page unless we've
  1594. // set the filter to empty and explicitly said that we want to see
  1595. // the results starting from page 0.
  1596. if ("".equals(filter) && page != 0) {
  1597. // let server decide
  1598. page = -1;
  1599. } else {
  1600. page = 0;
  1601. }
  1602. }
  1603. setWaitingForFilteringResponse(true);
  1604. connector.requestPage(filter, page);
  1605. lastFilter = filter;
  1606. currentPage = page;
  1607. }
  1608. /** For internal use only. May be removed or replaced in the future. */
  1609. public void updateReadOnly() {
  1610. debug("VFS: updateReadOnly()");
  1611. tb.setReadOnly(readonly || !textInputEnabled);
  1612. }
  1613. public void setTextInputEnabled(boolean textInputEnabled) {
  1614. debug("VFS: setTextInputEnabled()");
  1615. // Always update styles as they might have been overwritten
  1616. if (textInputEnabled) {
  1617. removeStyleDependentName(STYLE_NO_INPUT);
  1618. Roles.getTextboxRole().removeAriaReadonlyProperty(tb.getElement());
  1619. } else {
  1620. addStyleDependentName(STYLE_NO_INPUT);
  1621. Roles.getTextboxRole().setAriaReadonlyProperty(tb.getElement(),
  1622. true);
  1623. }
  1624. if (this.textInputEnabled == textInputEnabled) {
  1625. return;
  1626. }
  1627. this.textInputEnabled = textInputEnabled;
  1628. updateReadOnly();
  1629. }
  1630. /**
  1631. * Sets the text in the text box.
  1632. *
  1633. * @param text
  1634. * the text to set in the text box
  1635. */
  1636. public void setTextboxText(final String text) {
  1637. if (enableDebug) {
  1638. debug("VFS: setTextboxText(" + text + ")");
  1639. }
  1640. setText(text);
  1641. }
  1642. private void setText(final String text) {
  1643. /**
  1644. * To leave caret in the beginning of the line. SetSelectionRange
  1645. * wouldn't work on IE (see #13477)
  1646. */
  1647. Direction previousDirection = tb.getDirection();
  1648. tb.setDirection(Direction.RTL);
  1649. tb.setText(text);
  1650. tb.setDirection(previousDirection);
  1651. }
  1652. /**
  1653. * Turns prompting on. When prompting is turned on a command prompt is shown
  1654. * in the text box if nothing has been entered.
  1655. */
  1656. public void setPromptingOn() {
  1657. debug("VFS: setPromptingOn()");
  1658. if (!prompting) {
  1659. prompting = true;
  1660. addStyleDependentName(CLASSNAME_PROMPT);
  1661. }
  1662. setTextboxText(inputPrompt);
  1663. }
  1664. /**
  1665. * Turns prompting off. When prompting is turned on a command prompt is
  1666. * shown in the text box if nothing has been entered.
  1667. * <p>
  1668. * For internal use only. May be removed or replaced in the future.
  1669. *
  1670. * @param text
  1671. * The text the text box should contain.
  1672. */
  1673. public void setPromptingOff(String text) {
  1674. debug("VFS: setPromptingOff()");
  1675. setTextboxText(text);
  1676. if (prompting) {
  1677. prompting = false;
  1678. removeStyleDependentName(CLASSNAME_PROMPT);
  1679. }
  1680. }
  1681. /**
  1682. * Triggered when a suggestion is selected
  1683. *
  1684. * @param suggestion
  1685. * The suggestion that just got selected.
  1686. */
  1687. public void onSuggestionSelected(FilterSelectSuggestion suggestion) {
  1688. if (enableDebug) {
  1689. debug("VFS: onSuggestionSelected(" + suggestion.caption + ": "
  1690. + suggestion.key + ")");
  1691. }
  1692. dataReceivedHandler.setUpdateOnDataReceived(false);
  1693. currentSuggestion = suggestion;
  1694. String newKey;
  1695. if (suggestion.key.equals("")) {
  1696. // "nullselection"
  1697. newKey = "";
  1698. } else {
  1699. // normal selection
  1700. newKey = suggestion.getOptionKey();
  1701. }
  1702. String text = suggestion.getReplacementString();
  1703. if ("".equals(newKey) && !focused) {
  1704. setPromptingOn();
  1705. } else {
  1706. setPromptingOff(text);
  1707. }
  1708. setSelectedItemIcon(suggestion.getIconUri());
  1709. if (!(newKey.equals(selectedOptionKey) || ("".equals(newKey) && selectedOptionKey == null))) {
  1710. selectedOptionKey = newKey;
  1711. connector.sendSelection(selectedOptionKey);
  1712. // currentPage = -1; // forget the page
  1713. }
  1714. suggestionPopup.hide();
  1715. }
  1716. /**
  1717. * Sets the icon URI of the selected item. The icon is shown on the left
  1718. * side of the item caption text. Set the URI to null to remove the icon.
  1719. *
  1720. * @param iconUri
  1721. * The URI of the icon
  1722. */
  1723. public void setSelectedItemIcon(String iconUri) {
  1724. if (iconUri == null || iconUri.length() == 0) {
  1725. if (selectedItemIcon != null) {
  1726. panel.remove(selectedItemIcon);
  1727. selectedItemIcon = null;
  1728. afterSelectedItemIconChange();
  1729. }
  1730. } else {
  1731. if (selectedItemIcon != null) {
  1732. panel.remove(selectedItemIcon);
  1733. }
  1734. selectedItemIcon = new IconWidget(connector.getConnection()
  1735. .getIcon(iconUri));
  1736. // Older IE versions don't scale icon correctly if DOM
  1737. // contains height and width attributes.
  1738. selectedItemIcon.getElement().removeAttribute("height");
  1739. selectedItemIcon.getElement().removeAttribute("width");
  1740. selectedItemIcon.addDomHandler(new LoadHandler() {
  1741. @Override
  1742. public void onLoad(LoadEvent event) {
  1743. afterSelectedItemIconChange();
  1744. }
  1745. }, LoadEvent.getType());
  1746. panel.insert(selectedItemIcon, 0);
  1747. afterSelectedItemIconChange();
  1748. }
  1749. }
  1750. private void afterSelectedItemIconChange() {
  1751. if (BrowserInfo.get().isWebkit() || BrowserInfo.get().isIE8()) {
  1752. // Some browsers need a nudge to reposition the text field
  1753. forceReflow();
  1754. }
  1755. updateRootWidth();
  1756. if (selectedItemIcon != null) {
  1757. updateSelectedIconPosition();
  1758. }
  1759. }
  1760. private void forceReflow() {
  1761. WidgetUtil.setStyleTemporarily(tb.getElement(), "zoom", "1");
  1762. }
  1763. /**
  1764. * Positions the icon vertically in the middle. Should be called after the
  1765. * icon has loaded
  1766. */
  1767. private void updateSelectedIconPosition() {
  1768. // Position icon vertically to middle
  1769. int availableHeight = 0;
  1770. availableHeight = getOffsetHeight();
  1771. int iconHeight = WidgetUtil.getRequiredHeight(selectedItemIcon);
  1772. int marginTop = (availableHeight - iconHeight) / 2;
  1773. selectedItemIcon.getElement().getStyle()
  1774. .setMarginTop(marginTop, Unit.PX);
  1775. }
  1776. private static Set<Integer> navigationKeyCodes = new HashSet<Integer>();
  1777. static {
  1778. navigationKeyCodes.add(KeyCodes.KEY_DOWN);
  1779. navigationKeyCodes.add(KeyCodes.KEY_UP);
  1780. navigationKeyCodes.add(KeyCodes.KEY_PAGEDOWN);
  1781. navigationKeyCodes.add(KeyCodes.KEY_PAGEUP);
  1782. navigationKeyCodes.add(KeyCodes.KEY_ENTER);
  1783. }
  1784. /*
  1785. * (non-Javadoc)
  1786. *
  1787. * @see
  1788. * com.google.gwt.event.dom.client.KeyDownHandler#onKeyDown(com.google.gwt
  1789. * .event.dom.client.KeyDownEvent)
  1790. */
  1791. @Override
  1792. public void onKeyDown(KeyDownEvent event) {
  1793. if (enabled && !readonly) {
  1794. int keyCode = event.getNativeKeyCode();
  1795. if (enableDebug) {
  1796. debug("VFS: key down: " + keyCode);
  1797. }
  1798. if (isWaitingForFilteringResponse()
  1799. && navigationKeyCodes.contains(keyCode)) {
  1800. /*
  1801. * Keyboard navigation events should not be handled while we are
  1802. * waiting for a response. This avoids flickering, disappearing
  1803. * items, wrongly interpreted responses and more.
  1804. */
  1805. if (enableDebug) {
  1806. debug("Ignoring "
  1807. + keyCode
  1808. + " because we are waiting for a filtering response");
  1809. }
  1810. DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
  1811. event.stopPropagation();
  1812. return;
  1813. }
  1814. if (suggestionPopup.isAttached()) {
  1815. if (enableDebug) {
  1816. debug("Keycode " + keyCode + " target is popup");
  1817. }
  1818. popupKeyDown(event);
  1819. } else {
  1820. if (enableDebug) {
  1821. debug("Keycode " + keyCode + " target is text field");
  1822. }
  1823. inputFieldKeyDown(event);
  1824. }
  1825. }
  1826. }
  1827. private void debug(String string) {
  1828. if (enableDebug) {
  1829. VConsole.error(string);
  1830. }
  1831. }
  1832. /**
  1833. * Triggered when a key is pressed in the text box
  1834. *
  1835. * @param event
  1836. * The KeyDownEvent
  1837. */
  1838. private void inputFieldKeyDown(KeyDownEvent event) {
  1839. if (enableDebug) {
  1840. debug("VFS: inputFieldKeyDown(" + event.getNativeKeyCode() + ")");
  1841. }
  1842. switch (event.getNativeKeyCode()) {
  1843. case KeyCodes.KEY_DOWN:
  1844. case KeyCodes.KEY_UP:
  1845. case KeyCodes.KEY_PAGEDOWN:
  1846. case KeyCodes.KEY_PAGEUP:
  1847. // open popup as from gadget
  1848. filterOptions(-1, "");
  1849. lastFilter = "";
  1850. tb.selectAll();
  1851. break;
  1852. case KeyCodes.KEY_ENTER:
  1853. /*
  1854. * This only handles the case when new items is allowed, a text is
  1855. * entered, the popup opener button is clicked to close the popup
  1856. * and enter is then pressed (see #7560).
  1857. */
  1858. if (!allowNewItem) {
  1859. return;
  1860. }
  1861. if (currentSuggestion != null
  1862. && tb.getText().equals(
  1863. currentSuggestion.getReplacementString())) {
  1864. // Retain behavior from #6686 by returning without stopping
  1865. // propagation if there's nothing to do
  1866. return;
  1867. }
  1868. suggestionPopup.menu.doSelectedItemAction();
  1869. event.stopPropagation();
  1870. break;
  1871. }
  1872. }
  1873. /**
  1874. * Triggered when a key was pressed in the suggestion popup.
  1875. *
  1876. * @param event
  1877. * The KeyDownEvent of the key
  1878. */
  1879. private void popupKeyDown(KeyDownEvent event) {
  1880. if (enableDebug) {
  1881. debug("VFS: popupKeyDown(" + event.getNativeKeyCode() + ")");
  1882. }
  1883. // Propagation of handled events is stopped so other handlers such as
  1884. // shortcut key handlers do not also handle the same events.
  1885. switch (event.getNativeKeyCode()) {
  1886. case KeyCodes.KEY_DOWN:
  1887. suggestionPopup.selectNextItem();
  1888. DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
  1889. event.stopPropagation();
  1890. break;
  1891. case KeyCodes.KEY_UP:
  1892. suggestionPopup.selectPrevItem();
  1893. DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
  1894. event.stopPropagation();
  1895. break;
  1896. case KeyCodes.KEY_PAGEDOWN:
  1897. selectNextPage();
  1898. event.stopPropagation();
  1899. break;
  1900. case KeyCodes.KEY_PAGEUP:
  1901. selectPrevPage();
  1902. event.stopPropagation();
  1903. break;
  1904. case KeyCodes.KEY_ESCAPE:
  1905. reset();
  1906. DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
  1907. event.stopPropagation();
  1908. break;
  1909. case KeyCodes.KEY_TAB:
  1910. case KeyCodes.KEY_ENTER:
  1911. if (!allowNewItem) {
  1912. int selected = suggestionPopup.menu.getSelectedIndex();
  1913. if (selected != -1) {
  1914. onSuggestionSelected(currentSuggestions.get(selected));
  1915. } else {
  1916. // The way VFilterSelect is done, it handles enter and tab
  1917. // in exactly the same way so we close the popup in both
  1918. // cases even though we could leave it open when pressing
  1919. // enter
  1920. suggestionPopup.hide();
  1921. }
  1922. } else {
  1923. // Handle addition of new items.
  1924. suggestionPopup.menu.doSelectedItemAction();
  1925. }
  1926. event.stopPropagation();
  1927. break;
  1928. }
  1929. }
  1930. /*
  1931. * Show the prev page.
  1932. */
  1933. private void selectPrevPage() {
  1934. if (currentPage > 0) {
  1935. filterOptions(currentPage - 1, lastFilter);
  1936. dataReceivedHandler.setNavigationCallback(new Runnable() {
  1937. @Override
  1938. public void run() {
  1939. suggestionPopup.selectLastItem();
  1940. }
  1941. });
  1942. }
  1943. }
  1944. /*
  1945. * Show the next page.
  1946. */
  1947. private void selectNextPage() {
  1948. if (hasNextPage()) {
  1949. filterOptions(currentPage + 1, lastFilter);
  1950. dataReceivedHandler.setNavigationCallback(new Runnable() {
  1951. @Override
  1952. public void run() {
  1953. suggestionPopup.selectFirstItem();
  1954. }
  1955. });
  1956. }
  1957. }
  1958. /**
  1959. * Triggered when a key was depressed
  1960. *
  1961. * @param event
  1962. * The KeyUpEvent of the key depressed
  1963. */
  1964. @Override
  1965. public void onKeyUp(KeyUpEvent event) {
  1966. if (enableDebug) {
  1967. debug("VFS: onKeyUp(" + event.getNativeKeyCode() + ")");
  1968. }
  1969. if (enabled && !readonly) {
  1970. switch (event.getNativeKeyCode()) {
  1971. case KeyCodes.KEY_ENTER:
  1972. case KeyCodes.KEY_TAB:
  1973. case KeyCodes.KEY_SHIFT:
  1974. case KeyCodes.KEY_CTRL:
  1975. case KeyCodes.KEY_ALT:
  1976. case KeyCodes.KEY_DOWN:
  1977. case KeyCodes.KEY_UP:
  1978. case KeyCodes.KEY_PAGEDOWN:
  1979. case KeyCodes.KEY_PAGEUP:
  1980. case KeyCodes.KEY_ESCAPE:
  1981. // NOP
  1982. break;
  1983. default:
  1984. if (textInputEnabled) {
  1985. // when filtering, we always want to see the results on the
  1986. // first page first.
  1987. filterOptions(0);
  1988. }
  1989. break;
  1990. }
  1991. }
  1992. }
  1993. /**
  1994. * Resets the Select to its initial state
  1995. */
  1996. private void reset() {
  1997. debug("VFS: reset()");
  1998. if (currentSuggestion != null) {
  1999. String text = currentSuggestion.getReplacementString();
  2000. setPromptingOff(text);
  2001. setSelectedItemIcon(currentSuggestion.getIconUri());
  2002. selectedOptionKey = currentSuggestion.key;
  2003. } else {
  2004. if (focused || readonly || !enabled) {
  2005. setPromptingOff("");
  2006. } else {
  2007. setPromptingOn();
  2008. }
  2009. setSelectedItemIcon(null);
  2010. selectedOptionKey = null;
  2011. }
  2012. lastFilter = "";
  2013. suggestionPopup.hide();
  2014. }
  2015. /**
  2016. * Listener for popupopener
  2017. */
  2018. @Override
  2019. public void onClick(ClickEvent event) {
  2020. debug("VFS: onClick()");
  2021. if (textInputEnabled
  2022. && event.getNativeEvent().getEventTarget().cast() == tb
  2023. .getElement()) {
  2024. // Don't process clicks on the text field if text input is enabled
  2025. return;
  2026. }
  2027. if (enabled && !readonly) {
  2028. // ask suggestionPopup if it was just closed, we are using GWT
  2029. // Popup's auto close feature
  2030. if (!suggestionPopup.isJustClosed()) {
  2031. // If a focus event is not going to be sent, send the options
  2032. // request immediately; otherwise queue in the same burst as the
  2033. // focus event. Fixes #8321.
  2034. boolean immediate = focused
  2035. || !connector.hasEventListener(EventId.FOCUS);
  2036. filterOptions(-1, "", immediate);
  2037. dataReceivedHandler.popupOpenerClicked();
  2038. lastFilter = "";
  2039. }
  2040. DOM.eventPreventDefault(DOM.eventGetCurrentEvent());
  2041. focus();
  2042. tb.selectAll();
  2043. }
  2044. }
  2045. /**
  2046. * Update minimum width for FilterSelect textarea based on input prompt and
  2047. * suggestions.
  2048. * <p>
  2049. * For internal use only. May be removed or replaced in the future.
  2050. */
  2051. public void updateSuggestionPopupMinWidth() {
  2052. // used only to calculate minimum width
  2053. String captions = WidgetUtil.escapeHTML(inputPrompt);
  2054. for (FilterSelectSuggestion suggestion : currentSuggestions) {
  2055. // Collect captions so we can calculate minimum width for
  2056. // textarea
  2057. if (captions.length() > 0) {
  2058. captions += "|";
  2059. }
  2060. captions += WidgetUtil
  2061. .escapeHTML(suggestion.getReplacementString());
  2062. }
  2063. // Calculate minimum textarea width
  2064. suggestionPopupMinWidth = minWidth(captions);
  2065. }
  2066. /**
  2067. * Calculate minimum width for FilterSelect textarea.
  2068. * <p>
  2069. * For internal use only. May be removed or replaced in the future.
  2070. */
  2071. public native int minWidth(String captions)
  2072. /*-{
  2073. if(!captions || captions.length <= 0)
  2074. return 0;
  2075. captions = captions.split("|");
  2076. var d = $wnd.document.createElement("div");
  2077. var html = "";
  2078. for(var i=0; i < captions.length; i++) {
  2079. html += "<div>" + captions[i] + "</div>";
  2080. // TODO apply same CSS classname as in suggestionmenu
  2081. }
  2082. d.style.position = "absolute";
  2083. d.style.top = "0";
  2084. d.style.left = "0";
  2085. d.style.visibility = "hidden";
  2086. d.innerHTML = html;
  2087. $wnd.document.body.appendChild(d);
  2088. var w = d.offsetWidth;
  2089. $wnd.document.body.removeChild(d);
  2090. return w;
  2091. }-*/;
  2092. /**
  2093. * A flag which prevents a focus event from taking place
  2094. */
  2095. boolean iePreventNextFocus = false;
  2096. /*
  2097. * (non-Javadoc)
  2098. *
  2099. * @see
  2100. * com.google.gwt.event.dom.client.FocusHandler#onFocus(com.google.gwt.event
  2101. * .dom.client.FocusEvent)
  2102. */
  2103. @Override
  2104. public void onFocus(FocusEvent event) {
  2105. debug("VFS: onFocus()");
  2106. /*
  2107. * When we disable a blur event in ie we need to refocus the textfield.
  2108. * This will cause a focus event we do not want to process, so in that
  2109. * case we just ignore it.
  2110. */
  2111. if (BrowserInfo.get().isIE() && iePreventNextFocus) {
  2112. iePreventNextFocus = false;
  2113. return;
  2114. }
  2115. focused = true;
  2116. if (prompting && !readonly) {
  2117. setPromptingOff("");
  2118. }
  2119. addStyleDependentName("focus");
  2120. connector.sendFocusEvent();
  2121. connector.getConnection().getVTooltip()
  2122. .showAssistive(connector.getTooltipInfo(getElement()));
  2123. }
  2124. /**
  2125. * A flag which cancels the blur event and sets the focus back to the
  2126. * textfield if the Browser is IE
  2127. */
  2128. boolean preventNextBlurEventInIE = false;
  2129. /*
  2130. * (non-Javadoc)
  2131. *
  2132. * @see
  2133. * com.google.gwt.event.dom.client.BlurHandler#onBlur(com.google.gwt.event
  2134. * .dom.client.BlurEvent)
  2135. */
  2136. @Override
  2137. public void onBlur(BlurEvent event) {
  2138. debug("VFS: onBlur()");
  2139. if (BrowserInfo.get().isIE() && preventNextBlurEventInIE) {
  2140. /*
  2141. * Clicking in the suggestion popup or on the popup button in IE
  2142. * causes a blur event to be sent for the field. In other browsers
  2143. * this is prevented by canceling/preventing default behavior for
  2144. * the focus event, in IE we handle it here by refocusing the text
  2145. * field and ignoring the resulting focus event for the textfield
  2146. * (in onFocus).
  2147. */
  2148. preventNextBlurEventInIE = false;
  2149. Element focusedElement = WidgetUtil.getFocusedElement();
  2150. if (getElement().isOrHasChild(focusedElement)
  2151. || suggestionPopup.getElement()
  2152. .isOrHasChild(focusedElement)) {
  2153. // IF the suggestion popup or another part of the VFilterSelect
  2154. // was focused, move the focus back to the textfield and prevent
  2155. // the triggered focus event (in onFocus).
  2156. iePreventNextFocus = true;
  2157. tb.setFocus(true);
  2158. return;
  2159. }
  2160. }
  2161. focused = false;
  2162. if (!readonly) {
  2163. if (selectedOptionKey == null) {
  2164. setPromptingOn();
  2165. } else if (currentSuggestion != null) {
  2166. setPromptingOff(currentSuggestion.caption);
  2167. }
  2168. }
  2169. removeStyleDependentName("focus");
  2170. connector.sendBlurEvent();
  2171. }
  2172. /*
  2173. * (non-Javadoc)
  2174. *
  2175. * @see com.vaadin.client.Focusable#focus()
  2176. */
  2177. @Override
  2178. public void focus() {
  2179. debug("VFS: focus()");
  2180. focused = true;
  2181. if (prompting && !readonly) {
  2182. setPromptingOff("");
  2183. }
  2184. tb.setFocus(true);
  2185. }
  2186. /**
  2187. * Calculates the width of the select if the select has undefined width.
  2188. * Should be called when the width changes or when the icon changes.
  2189. * <p>
  2190. * For internal use only. May be removed or replaced in the future.
  2191. */
  2192. public void updateRootWidth() {
  2193. if (connector.isUndefinedWidth()) {
  2194. /*
  2195. * When the select has a undefined with we need to check that we are
  2196. * only setting the text box width relative to the first page width
  2197. * of the items. If this is not done the text box width will change
  2198. * when the popup is used to view longer items than the text box is
  2199. * wide.
  2200. */
  2201. int w = WidgetUtil.getRequiredWidth(this);
  2202. if ((!initDone || currentPage + 1 < 0)
  2203. && suggestionPopupMinWidth > w) {
  2204. /*
  2205. * We want to compensate for the paddings just to preserve the
  2206. * exact size as in Vaadin 6.x, but we get here before
  2207. * MeasuredSize has been initialized.
  2208. * Util.measureHorizontalPaddingAndBorder does not work with
  2209. * border-box, so we must do this the hard way.
  2210. */
  2211. Style style = getElement().getStyle();
  2212. String originalPadding = style.getPadding();
  2213. String originalBorder = style.getBorderWidth();
  2214. style.setPaddingLeft(0, Unit.PX);
  2215. style.setBorderWidth(0, Unit.PX);
  2216. style.setProperty("padding", originalPadding);
  2217. style.setProperty("borderWidth", originalBorder);
  2218. // Use util.getRequiredWidth instead of getOffsetWidth here
  2219. int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil
  2220. .getRequiredWidth(selectedItemIcon);
  2221. int buttonWidth = popupOpener == null ? 0 : WidgetUtil
  2222. .getRequiredWidth(popupOpener);
  2223. /*
  2224. * Instead of setting the width of the wrapper, set the width of
  2225. * the combobox. Subtract the width of the icon and the
  2226. * popupopener
  2227. */
  2228. tb.setWidth((suggestionPopupMinWidth - iconWidth - buttonWidth)
  2229. + "px");
  2230. }
  2231. /*
  2232. * Lock the textbox width to its current value if it's not already
  2233. * locked
  2234. */
  2235. if (!tb.getElement().getStyle().getWidth().endsWith("px")) {
  2236. int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon
  2237. .getOffsetWidth();
  2238. tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px");
  2239. }
  2240. }
  2241. }
  2242. /**
  2243. * Get the width of the select in pixels where the text area and icon has
  2244. * been included.
  2245. *
  2246. * @return The width in pixels
  2247. */
  2248. private int getMainWidth() {
  2249. return getOffsetWidth();
  2250. }
  2251. @Override
  2252. public void setWidth(String width) {
  2253. super.setWidth(width);
  2254. if (width.length() != 0) {
  2255. tb.setWidth("100%");
  2256. }
  2257. }
  2258. /**
  2259. * Handles special behavior of the mouse down event
  2260. *
  2261. * @param event
  2262. */
  2263. private void handleMouseDownEvent(Event event) {
  2264. /*
  2265. * Prevent the keyboard focus from leaving the textfield by preventing
  2266. * the default behaviour of the browser. Fixes #4285.
  2267. */
  2268. if (event.getTypeInt() == Event.ONMOUSEDOWN) {
  2269. event.preventDefault();
  2270. event.stopPropagation();
  2271. /*
  2272. * In IE the above wont work, the blur event will still trigger. So,
  2273. * we set a flag here to prevent the next blur event from happening.
  2274. * This is not needed if do not already have focus, in that case
  2275. * there will not be any blur event and we should not cancel the
  2276. * next blur.
  2277. */
  2278. if (BrowserInfo.get().isIE() && focused) {
  2279. preventNextBlurEventInIE = true;
  2280. debug("VFS: Going to prevent next blur event on IE");
  2281. }
  2282. }
  2283. }
  2284. @Override
  2285. protected void onDetach() {
  2286. super.onDetach();
  2287. suggestionPopup.hide();
  2288. }
  2289. @Override
  2290. public com.google.gwt.user.client.Element getSubPartElement(String subPart) {
  2291. String[] parts = subPart.split("/");
  2292. if ("textbox".equals(parts[0])) {
  2293. return tb.getElement();
  2294. } else if ("button".equals(parts[0])) {
  2295. return popupOpener.getElement();
  2296. } else if ("popup".equals(parts[0]) && suggestionPopup.isAttached()) {
  2297. if (parts.length == 2) {
  2298. return suggestionPopup.menu.getSubPartElement(parts[1]);
  2299. }
  2300. return suggestionPopup.getElement();
  2301. }
  2302. return null;
  2303. }
  2304. @Override
  2305. public String getSubPartName(com.google.gwt.user.client.Element subElement) {
  2306. if (tb.getElement().isOrHasChild(subElement)) {
  2307. return "textbox";
  2308. } else if (popupOpener.getElement().isOrHasChild(subElement)) {
  2309. return "button";
  2310. } else if (suggestionPopup.getElement().isOrHasChild(subElement)) {
  2311. return "popup";
  2312. }
  2313. return null;
  2314. }
  2315. @Override
  2316. public void setAriaRequired(boolean required) {
  2317. AriaHelper.handleInputRequired(tb, required);
  2318. }
  2319. @Override
  2320. public void setAriaInvalid(boolean invalid) {
  2321. AriaHelper.handleInputInvalid(tb, invalid);
  2322. }
  2323. @Override
  2324. public void bindAriaCaption(
  2325. com.google.gwt.user.client.Element captionElement) {
  2326. AriaHelper.bindCaption(tb, captionElement);
  2327. }
  2328. @Override
  2329. public boolean isWorkPending() {
  2330. return isWaitingForFilteringResponse()
  2331. || suggestionPopup.lazyPageScroller.isRunning();
  2332. }
  2333. /**
  2334. * For internal use only - this method will be removed in the future.
  2335. *
  2336. * @return true if the combo box is waiting for a reply from the server with
  2337. * a new page of data, false otherwise
  2338. */
  2339. public boolean isWaitingForFilteringResponse() {
  2340. return waitingForFilteringResponse;
  2341. }
  2342. /**
  2343. * For internal use only - this method will be removed in the future.
  2344. *
  2345. * @param waitingForFilteringResponse
  2346. * true to indicate that the combo box is waiting for a new page
  2347. * of items from the server
  2348. */
  2349. public void setWaitingForFilteringResponse(
  2350. boolean waitingForFilteringResponse) {
  2351. this.waitingForFilteringResponse = waitingForFilteringResponse;
  2352. }
  2353. /**
  2354. * Returns a handler receiving notifications from the connector about
  2355. * communications.
  2356. *
  2357. * @return the dataReceivedHandler
  2358. */
  2359. public DataReceivedHandler getDataReceivedHandler() {
  2360. return dataReceivedHandler;
  2361. }
  2362. }