@PostConstruct private void setupSuggestions() { MultiWordSuggestOracle iso = (MultiWordSuggestOracle) name.getSuggestOracle(); for (Item i : em.createNamedQuery("allItemsByName", Item.class).getResultList()) { iso.add(i.getName()); } MultiWordSuggestOracle dso = (MultiWordSuggestOracle) department.getSuggestOracle(); for (Department d : em.createNamedQuery("allDepartments", Department.class).getResultList()) { dso.add(d.getName()); } }
/** @param jobs */ public void initUI(JsArray<JsJob> jobs) { if (jobs != null) { for (int i = 0; i < jobs.length(); i++) { resourceOracle.add(jobs.get(i).getShortResourceName()); } } resourceSuggestBox.setWidth("240px"); userListBox.setWidth("200px"); userListBox.getElement().getStyle().setTextTransform(Style.TextTransform.CAPITALIZE); scheduleStateListBox.setWidth("200px"); scheduleTypeListBox.setWidth("200px"); // next execution filter CaptionPanel executionFilterCaptionPanel = new CaptionPanel(Messages.getString("executionTime")); FlexTable executionFilterPanel = new FlexTable(); executionFilterPanel.setWidget(0, 0, beforeCheckBox); executionFilterPanel.setWidget(0, 1, beforeDateBox); executionFilterPanel.setWidget(1, 0, afterCheckBox); executionFilterPanel.setWidget(1, 1, afterDateBox); executionFilterCaptionPanel.add(executionFilterPanel); afterCheckBox.addValueChangeHandler( new ValueChangeHandler<Boolean>() { public void onValueChange(ValueChangeEvent<Boolean> event) { afterDateBox.setEnabled(event.getValue()); } }); beforeCheckBox.addValueChangeHandler( new ValueChangeHandler<Boolean>() { public void onValueChange(ValueChangeEvent<Boolean> event) { beforeDateBox.setEnabled(event.getValue()); } }); beforeDateBox.setEnabled(beforeCheckBox.getValue()); afterDateBox.setEnabled(afterCheckBox.getValue()); final String showAll = Messages.getString("showAll"); // user filter int selectedIndex = getSelectedIndex(userListBox); userListBox.clear(); userListBox.addItem(showAll); HashSet<String> uniqueUsers = new HashSet<String>(); if (jobs != null) { for (int i = 0; i < jobs.length(); i++) { uniqueUsers.add(jobs.get(i).getUserName()); } } for (String user : uniqueUsers) { userListBox.addItem(user); } userListBox.setSelectedIndex(selectedIndex); // state filter scheduleStateListBox.setVisibleItemCount(1); selectedIndex = getSelectedIndex(scheduleStateListBox); scheduleStateListBox.clear(); // NORMAL, PAUSED, COMPLETE, ERROR, BLOCKED, UNKNOWN scheduleStateListBox.addItem(showAll, ScheduleStateEnum.SHOWALL.getValue()); scheduleStateListBox.addItem(Messages.getString("normal"), ScheduleStateEnum.NORMAL.getValue()); scheduleStateListBox.addItem(Messages.getString("paused"), ScheduleStateEnum.PAUSED.getValue()); scheduleStateListBox.addItem( Messages.getString("complete"), ScheduleStateEnum.COMPLETE.getValue()); scheduleStateListBox.addItem(Messages.getString("error"), ScheduleStateEnum.ERROR.getValue()); scheduleStateListBox.addItem( Messages.getString("blocked"), ScheduleStateEnum.BLOCKED.getValue()); scheduleStateListBox.addItem( Messages.getString("unknown"), ScheduleStateEnum.UNKNOWN.getValue()); scheduleStateListBox.setSelectedIndex(selectedIndex); // state filter scheduleTypeListBox.setVisibleItemCount(1); selectedIndex = getSelectedIndex(scheduleTypeListBox); scheduleTypeListBox.clear(); // DAILY, WEEKLY, MONTHLY, YEARLY scheduleTypeListBox.addItem(showAll, ScheduleStateEnum.SHOWALL.getValue()); scheduleTypeListBox.addItem( Messages.getString("schedule.daily"), ScheduleTypeEnum.DAILY.getValue()); scheduleTypeListBox.addItem( Messages.getString("schedule.weekly"), ScheduleTypeEnum.WEEKLY.getValue()); scheduleTypeListBox.addItem( Messages.getString("schedule.monthly"), ScheduleTypeEnum.MONTHLY.getValue()); scheduleTypeListBox.addItem( Messages.getString("schedule.yearly"), ScheduleTypeEnum.YEARLY.getValue()); scheduleTypeListBox.setSelectedIndex(selectedIndex); FlexTable filterPanel = new FlexTable(); filterPanel.setWidget(0, 0, new Label(Messages.getString("scheduledResource"))); filterPanel.setWidget(1, 0, resourceSuggestBox); filterPanel.setWidget(2, 0, new Label(Messages.getString("_user"))); filterPanel.setWidget(3, 0, userListBox); filterPanel.setWidget(4, 0, new Label(Messages.getString("scheduleState"))); filterPanel.setWidget(5, 0, scheduleStateListBox); filterPanel.setWidget(6, 0, new Label(Messages.getString("scheduleType"))); filterPanel.setWidget(7, 0, scheduleTypeListBox); filterPanel.setWidget(8, 0, executionFilterCaptionPanel); setContent(filterPanel); }
@Override public void requestSuggestions(final Request request, final Callback callback) { if (current != null) { pending_req = request; pending_cb = callback; return; } current = callback; { final String this_query = request.getQuery(); // Check if we can serve this from our local cache, without even talking // to the server. This is possible if either of those is true: // 1. We've already seen this query recently. // 2. This new query precedes another one and the user basically just // typed another letter, so if the new query is "less than" the last // result we got from the server, we know we already cached the full // range of results covering the new request. if ((last_query != null && last_query.compareTo(this_query) <= 0 && this_query.compareTo(last_suggestion) < 0) || queries_seen.check(this_query)) { current = null; cache.requestSuggestions(request, callback); return; } last_query = this_query; } final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, SUGGEST_URL + type + "&q=" + last_query); try { builder.sendRequest( null, new RequestCallback() { public void onError(final com.google.gwt.http.client.Request r, final Throwable e) { current = null; // Something bad happened, drop the current request. if (pending_req != null) { // But if we have another waiting... requestSuggestions(pending_req, pending_cb); // ... try it now. } } // Need to use fully-qualified names as this class inherits already // from a pair of inner classes called Request / Response :-/ public void onResponseReceived( final com.google.gwt.http.client.Request r, final com.google.gwt.http.client.Response response) { if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK) { final JSONValue json = JSONParser.parse(response.getText()); // In case this request returned nothing, we pretend the last // suggestion ended with the largest character possible, so we // won't send more requests to the server if the user keeps // adding extra characters. last_suggestion = last_query + "\377"; if (json != null && json.isArray() != null) { final JSONArray results = json.isArray(); final int n = Math.min(request.getLimit(), results.size()); for (int i = 0; i < n; i++) { final JSONValue suggestion = results.get(i); if (suggestion == null || suggestion.isString() == null) { continue; } final String suggestionstr = suggestion.isString().stringValue(); last_suggestion = suggestionstr; cache.add(suggestionstr); } // Is this response still relevant to what the requester wants? if (requester.getText().startsWith(last_query)) { cache.requestSuggestions(request, callback); pending_req = null; pending_cb = null; } } } current = null; // Regardless of what happened above, this is done. if (pending_req != null) { final Request req = pending_req; final Callback cb = pending_cb; pending_req = null; pending_cb = null; requestSuggestions(req, cb); } } }); } catch (RequestException ignore) { } }
@Override public void clearVariableNameSuggestions() { suggestions.clear(); }
@Override public void addVariableNameSuggestion(String name) { suggestions.add(name); }
MultiWordSuggestOracle createCountriesOracle() { MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); oracle.add("Afghanistan"); oracle.add("Albania"); oracle.add("Algeria"); oracle.add("American Samoa"); oracle.add("Andorra"); oracle.add("Angola"); oracle.add("Anguilla"); oracle.add("Antarctica"); oracle.add("Antigua And Barbuda"); oracle.add("Argentina"); oracle.add("Armenia"); oracle.add("Aruba"); oracle.add("Australia"); oracle.add("Austria"); oracle.add("Azerbaijan"); oracle.add("Bahamas"); oracle.add("Bahrain"); oracle.add("Bangladesh"); oracle.add("Barbados"); oracle.add("Belarus"); oracle.add("Belgium"); oracle.add("Belize"); oracle.add("Benin"); oracle.add("Bermuda"); oracle.add("Bhutan"); oracle.add("Bolivia"); oracle.add("Bosnia And Herzegovina"); oracle.add("Botswana"); oracle.add("Bouvet Island"); oracle.add("Brazil"); oracle.add("British Indian Ocean Territory"); oracle.add("Brunei Darussalam"); oracle.add("Bulgaria"); oracle.add("Burkina Faso"); oracle.add("Burundi"); oracle.add("Cambodia"); oracle.add("Cameroon"); oracle.add("Canada"); oracle.add("Cape Verde"); oracle.add("Cayman Islands"); oracle.add("Central African Republic"); oracle.add("Chad"); oracle.add("Chile"); oracle.add("China"); oracle.add("Christmas Island"); oracle.add("Cocos (Keeling) Islands"); oracle.add("Colombia"); oracle.add("Comoros"); oracle.add("Congo, The Democratic Republic Of The"); oracle.add("Congo"); oracle.add("Cook Islands"); oracle.add("Costa Rica"); oracle.add("Cote D''ivoire"); oracle.add("Croatia"); oracle.add("Cuba"); oracle.add("Cyprus"); oracle.add("Czech Republic"); oracle.add("Denmark"); oracle.add("Djibouti"); oracle.add("Dominica"); oracle.add("Dominican Republic"); oracle.add("East Timor"); oracle.add("Ecuador"); oracle.add("Egypt"); oracle.add("El Salvador"); oracle.add("Equatorial Guinea"); oracle.add("Eritrea"); oracle.add("Estonia"); oracle.add("Ethiopia"); oracle.add("Falkland Islands (Malvinas)"); oracle.add("Faroe Islands"); oracle.add("Fiji"); oracle.add("Finland"); oracle.add("France"); oracle.add("French Guiana"); oracle.add("French Polynesia"); oracle.add("French Southern Territories"); oracle.add("Gabon"); oracle.add("Gambia"); oracle.add("Georgia"); oracle.add("Germany"); oracle.add("Ghana"); oracle.add("Gibraltar"); oracle.add("Greece"); oracle.add("Greenland"); oracle.add("Grenada"); oracle.add("Guadeloupe"); oracle.add("Guam"); oracle.add("Guatemala"); oracle.add("Guinea-Bissau"); oracle.add("Guinea"); oracle.add("Guyana"); oracle.add("Haiti"); oracle.add("Heard Island And Mcdonald Islands"); oracle.add("Holy See (Vatican City State)"); oracle.add("Honduras"); oracle.add("Hong Kong"); oracle.add("Hungary"); oracle.add("Iceland"); oracle.add("India"); oracle.add("Indonesia"); oracle.add("Iran, Islamic Republic Of"); oracle.add("Iraq"); oracle.add("Ireland"); oracle.add("Israel"); oracle.add("Italy"); oracle.add("Jamaica"); oracle.add("Japan"); oracle.add("Jordan"); oracle.add("Kazakstan"); oracle.add("Kenya"); oracle.add("Kiribati"); oracle.add("Korea, Democratic People''s Republic Of"); oracle.add("Korea, Republic Of"); oracle.add("Kuwait"); oracle.add("Kyrgyzstan"); oracle.add("Lao People''s Democratic Republic"); oracle.add("Latvia"); oracle.add("Lebanon"); oracle.add("Lesotho"); oracle.add("Liberia"); oracle.add("Libyan Arab Jamahiriya"); oracle.add("Liechtenstein"); oracle.add("Lithuania"); oracle.add("Luxembourg"); oracle.add("Macau"); oracle.add("Macedonia, The Former Yugoslav Republic Of"); oracle.add("Madagascar"); oracle.add("Malawi"); oracle.add("Malaysia"); oracle.add("Maldives"); oracle.add("Mali"); oracle.add("Malta"); oracle.add("Marshall Islands"); oracle.add("Martinique"); oracle.add("Mauritania"); oracle.add("Mauritius"); oracle.add("Mayotte"); oracle.add("Mexico"); oracle.add("Micronesia, Federated States Of"); oracle.add("Moldova, Republic Of"); oracle.add("Monaco"); oracle.add("Mongolia"); oracle.add("Montserrat"); oracle.add("Morocco"); oracle.add("Mozambique"); oracle.add("Myanmar"); oracle.add("Namibia"); oracle.add("Nauru"); oracle.add("Nepal"); oracle.add("Netherlands Antilles"); oracle.add("Netherlands"); oracle.add("New Caledonia"); oracle.add("New Zealand"); oracle.add("Nicaragua"); oracle.add("Niger"); oracle.add("Nigeria"); oracle.add("Niue"); oracle.add("Norfolk Island"); oracle.add("Northern Mariana Islands"); oracle.add("Norway"); oracle.add("Oman"); oracle.add("Pakistan"); oracle.add("Palau"); oracle.add("Palestinian Territory, Occupied"); oracle.add("Panama"); oracle.add("Papua New Guinea"); oracle.add("Paraguay"); oracle.add("Peru"); oracle.add("Philippines"); oracle.add("Pitcairn"); oracle.add("Poland"); oracle.add("Portugal"); oracle.add("Puerto Rico"); oracle.add("Qatar"); oracle.add("Reunion"); oracle.add("Romania"); oracle.add("Russian Federation"); oracle.add("Rwanda"); oracle.add("Saint Helena"); oracle.add("Saint Kitts And Nevis"); oracle.add("Saint Lucia"); oracle.add("Saint Pierre And Miquelon"); oracle.add("Saint Vincent And The Grenadines"); oracle.add("Samoa"); oracle.add("San Marino"); oracle.add("Sao Tome And Principe"); oracle.add("Saudi Arabia"); oracle.add("Senegal"); oracle.add("Seychelles"); oracle.add("Sierra Leone"); oracle.add("Singapore"); oracle.add("Slovakia"); oracle.add("Slovenia"); oracle.add("Solomon Islands"); oracle.add("Somalia"); oracle.add("South Africa"); oracle.add("South Georgia And The South Sandwich Islands"); oracle.add("Spain"); oracle.add("Sri Lanka"); oracle.add("Sudan"); oracle.add("Suriname"); oracle.add("Svalbard And Jan Mayen"); oracle.add("Swaziland"); oracle.add("Sweden"); oracle.add("Switzerland"); oracle.add("Syrian Arab Republic"); oracle.add("Taiwan, Province Of China"); oracle.add("Tajikistan"); oracle.add("Tanzania, United Republic Of"); oracle.add("Thailand"); oracle.add("Togo"); oracle.add("Tokelau"); oracle.add("Tonga"); oracle.add("Trinidad And Tobago"); oracle.add("Tunisia"); oracle.add("Turkey"); oracle.add("Turkmenistan"); oracle.add("Turks And Caicos Islands"); oracle.add("Tuvalu"); oracle.add("Uganda"); oracle.add("Ukraine"); oracle.add("United Arab Emirates"); oracle.add("United Kingdom"); oracle.add("United States Minor Outlying Islands"); oracle.add("United States"); oracle.add("Uruguay"); oracle.add("Uzbekistan"); oracle.add("Vanuatu"); oracle.add("Venezuela"); oracle.add("Viet Nam"); oracle.add("Virgin Islands, British"); oracle.add("Virgin Islands, U.S."); oracle.add("Wallis And Futuna"); oracle.add("Western Sahara"); oracle.add("Yemen"); oracle.add("Yugoslavia"); oracle.add("Zambia"); oracle.add("Zimbabwe"); return oracle; }