blob: cdf9e4c5ac0559d1714a56875c7c80f783705777 [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.io.Serializable;
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;
}
public void resetCurrentHandle() {
currentHandle = Long.toHexString(new Date().getTime());
}
/**
* Request suggestions.
*
* @param request
* the request
* @param callback
* the callback
*/
protected void requestSuggestions(Request request, FutureCallback callback) {
// dismiss older callbacks
resetCurrentHandle();
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 implements Serializable {
private static final long serialVersionUID = 166123789723L;
/** The uuid. */
public String uuid;
/** The display text. */
public String displayText;
public String handleId;
public SuggestionResult(){
}
/**
* Instantiates a new suggestion result.
*
* @param uuid
* the uuid
* @param displayText
* the display text
*/
public SuggestionResult(String uuid, String displayText, String handleId) {
super();
this.uuid = uuid;
this.displayText = displayText;
this.handleId = handleId;
}
}
}