blob: 50c9a0f4eced02904479067235f2007733f11760 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Florian Pirchner <florian.pirchner@gmail.com> - Initial implementation
*/
package org.eclipse.osbp.vaadin.addons.suggesttext.client;
import java.util.Date;
import java.util.List;
import com.google.gwt.user.client.ui.SuggestOracle.Request;
// TODO: Auto-generated Javadoc
/**
* This class is responsible to delegate the query for suggestions to the serverside rpc.
*/
public class OQueryDelegate {
/** The server rpc. */
// instance
private final SuggestTextFieldServerRpc serverRpc;
/** The current handle. */
private String currentHandle;
/** The current callback. */
private FutureCallback currentCallback;
/**
* Instantiates a new o query delegate.
*
* @param serverRpc the server rpc
*/
public OQueryDelegate(SuggestTextFieldServerRpc serverRpc) {
this.serverRpc = serverRpc;
}
/**
* Request suggestions.
*
* @param request the request
* @param callback the callback
*/
protected void requestSuggestions(Request request, FutureCallback callback) {
// dismiss older callbacks
currentHandle = Long.toHexString(new Date().getTime());
currentCallback = callback;
serverRpc.requestSuggestions(currentHandle, request.getQuery(), request.getLimit());
}
/**
* Respond.
*
* @param handle the handle
* @param response the response
*/
public void respond(String handle, List<SuggestionResult> response) {
if (currentHandle.equals(handle)) {
currentCallback.respondSuggestions(response);
}
}
/**
* A future to wait for responds from serverside.
*/
public interface FutureCallback {
/**
* Respond suggestions.
*
* @param suggestions the suggestions
*/
void respondSuggestions(List<SuggestionResult> suggestions);
}
/**
* The Class SuggestionResult.
*/
public static class SuggestionResult {
/** The uuid. */
public String uuid;
/** The display text. */
public String displayText;
/**
* Instantiates a new suggestion result.
*/
public SuggestionResult() {
}
/**
* Instantiates a new suggestion result.
*
* @param uuid the uuid
* @param displayText the display text
*/
public SuggestionResult(String uuid, String displayText) {
super();
this.uuid = uuid;
this.displayText = displayText;
}
}
}