http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/common/communication/interchange/StatusCode.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/common/communication/interchange/StatusCode.java b/wave/src/main/java/org/waveprotocol/box/webclient/common/communication/interchange/StatusCode.java deleted file mode 100644 index 89564d9..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/common/communication/interchange/StatusCode.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.common.communication.interchange; - -/** - * Holds status codes used by the client and set by WFE server or the client to - * communicate success or reasons for failure of various remote calls issued - * from the client. - * - * @author [email protected] (Bo Majewski) - */ -//TODO(shanestephens, majewski): consider grouping errors in a manner similar -// to HTTP error codes -public enum StatusCode { - /** - * Indicates that the response was successful. - */ - SUCCESS(0, "Success"), - - /** - * Indicates that the request timed out before it was answered. - */ - TIMEOUT(1, "Request timed out"), - - /** - * Indicates that the request has been canceled. - */ - CANCELLED(2, "Request canceled"), - - /** - * Indicates that the client is not connected to the server. - */ - DISCONNECTED(3, "Not connected"), - - /** - * Indicates that one of the wave server is not responding. - */ - WAVE_SERVER_ERROR(4, "Wave server not responding"), - - /** - * Indicates that the JSON response does not parse correctly. Errors with - * this code are generated client side. - */ - INVALID_JSON(5, "Invalid JSON response"), - - /** - * Indicates that the request could not be completed due to some other error. - */ - OTHER_ERROR(1000, "Unknown error"); - - private final int value; - private final String description; - - StatusCode(int value, String description) { - this.value = value; - this.description = description; - } - - /** - * Returns the numeric value assigned to this status code. - * - * @return Numeric value of this status code. - */ - public int getValue() { - return this.value; - } - - /** - * @return A description of this status code. - */ - public String getDescription() { - return this.description; - } - - /** - * Converts a given value to a status code. If no status code with a matching - * value is found, this method returns OTHER_ERROR. - * - * @return The status code corresponding to the given value. - */ - public static StatusCode fromValue(int value) { - for (StatusCode type : StatusCode.values()) { - if (type.value == value) { - return type; - } - } - return OTHER_ERROR; - } - - @Override - public String toString() { - return value + " " + description; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesBuilder.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesBuilder.java b/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesBuilder.java deleted file mode 100644 index 2eeb4f1..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesBuilder.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.profile; - -import com.google.common.base.Joiner; -import com.google.common.base.Preconditions; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.http.client.URL; - -import org.waveprotocol.box.profile.ProfileRequest; -import org.waveprotocol.box.profile.jso.ProfileRequestJsoImpl; -import org.waveprotocol.box.profile.jso.ProfileResponseJsoImpl; -import org.waveprotocol.box.webclient.profile.FetchProfilesService.Callback; -import org.waveprotocol.wave.client.account.impl.AbstractProfileManager; -import org.waveprotocol.wave.client.account.impl.ProfileImpl; -import org.waveprotocol.wave.client.debug.logger.DomLogger; -import org.waveprotocol.wave.common.logging.LoggerBundle; -import org.waveprotocol.wave.communication.gwt.JsonMessage; -import org.waveprotocol.wave.communication.json.JsonException; - -import java.util.Arrays; - -/** - * Helper class to fetch profiles. - * - * @author [email protected] (Yuri Zelikov) - */ -public final class FetchProfilesBuilder { - private static final LoggerBundle LOG = new DomLogger("FetchProfilesBuilder"); - - /** The base profile URL. */ - private static final String SEARCH_URL_BASE = "/profile"; - - /** Holds profile request data. */ - private ProfileRequest profileRequest; - - private FetchProfilesBuilder() { - } - - /** Static factory method */ - public static FetchProfilesBuilder create() { - return new FetchProfilesBuilder(); - } - - public FetchProfilesBuilder newFetchProfilesRequest() { - profileRequest = ProfileRequestJsoImpl.create(); - return this; - } - - public FetchProfilesBuilder setAddresses(String... addresses) { - profileRequest.addAllAddresses(Arrays.asList(addresses)); - return this; - } - - public FetchProfilesBuilder setProfilesManager( - AbstractProfileManager<ProfileImpl> profileManager) { - return this; - } - - public void fetchProfiles(final Callback callback) { - Preconditions.checkState(profileRequest != null); - Preconditions.checkState(profileRequest.getAddresses() != null); - - String url = getUrl(profileRequest); - LOG.trace().log( - "Fetching profiles for: [" + Joiner.on(",").join(profileRequest.getAddresses()) + "]"); - - RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); - requestBuilder.setCallback(new RequestCallback() { - @Override - public void onResponseReceived(Request request, Response response) { - LOG.trace().log("Profile response received: ", response.getText()); - if (response.getStatusCode() != Response.SC_OK) { - callback.onFailure("Got back status code " + response.getStatusCode()); - } else if (!response.getHeader("Content-Type").startsWith("application/json")) { - callback.onFailure("Profile service did not return json"); - } else { - ProfileResponseJsoImpl profileResponse; - try { - profileResponse = JsonMessage.parse(response.getText()); - } catch (JsonException e) { - callback.onFailure(e.getMessage()); - return; - } - callback.onSuccess(profileResponse); - } - } - - @Override - public void onError(Request request, Throwable e) { - callback.onFailure(e.getMessage()); - } - }); - - try { - requestBuilder.send(); - } catch (RequestException e) { - LOG.error().log(e.getMessage()); - } - } - - private static String getUrl(ProfileRequest profileRequest) { - String params = "?addresses=" + Joiner.on(",").join(profileRequest.getAddresses()); - return SEARCH_URL_BASE + "/" + URL.encode(params); - } - - @Override - public String toString() { - return "[Fetch profiles: " + Joiner.on(",").join(profileRequest.getAddresses()) + "]"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesService.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesService.java b/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesService.java deleted file mode 100644 index 13a24fd..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesService.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.profile; - -import org.waveprotocol.box.profile.ProfileResponse; - -/** - * Interface that exposes the fetch profile services to the client. - * - * @author [email protected] (Yuri Zelikov) - */ -public interface FetchProfilesService { - - public interface Callback { - void onFailure(String message); - - /** - * Notifies this callback of a successful fetch profiles response. - * - * @param profileResponse the response from the server. - */ - void onSuccess(ProfileResponse profileResponse); - } - - /** - * Fetches profiles. - * - * @param callback the callback. - * @param addresses the profiles to fetch. - */ - void fetch(Callback callback, String... addresses); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesServiceImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesServiceImpl.java b/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesServiceImpl.java deleted file mode 100644 index f58ba21..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/profile/FetchProfilesServiceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.profile; - - -/** - * Implementation of {@link FetchProfilesService}. - * - * @author [email protected] (Yuri Zelikov) - */ -public class FetchProfilesServiceImpl implements FetchProfilesService { - - private static final FetchProfilesBuilder DEFAULT_BUILDER = FetchProfilesBuilder.create(); - private final FetchProfilesBuilder builder; - - FetchProfilesServiceImpl(FetchProfilesBuilder builder) { - this.builder = builder; - } - - public static FetchProfilesServiceImpl create() { - return new FetchProfilesServiceImpl(DEFAULT_BUILDER); - } - - @Override - public void fetch(Callback callback, String... addresses) { - builder.newFetchProfilesRequest().setAddresses(addresses).fetchProfiles(callback); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/profile/RemoteProfileManagerImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/profile/RemoteProfileManagerImpl.java b/wave/src/main/java/org/waveprotocol/box/webclient/profile/RemoteProfileManagerImpl.java deleted file mode 100644 index f4444e1..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/profile/RemoteProfileManagerImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.profile; - -import org.waveprotocol.box.profile.ProfileResponse; -import org.waveprotocol.box.profile.ProfileResponse.FetchedProfile; -import org.waveprotocol.wave.client.account.ProfileManager; -import org.waveprotocol.wave.client.account.impl.AbstractProfileManager; -import org.waveprotocol.wave.client.account.impl.ProfileImpl; -import org.waveprotocol.wave.client.debug.logger.DomLogger; -import org.waveprotocol.wave.common.logging.LoggerBundle; -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * A {@link ProfileManager} that returns profiles fetched from the server. - * - * @author [email protected] (Yuri Zelikov) - */ -public final class RemoteProfileManagerImpl extends AbstractProfileManager<ProfileImpl> implements - FetchProfilesService.Callback { - - private final static LoggerBundle LOG = new DomLogger("fetchProfiles"); - private final FetchProfilesServiceImpl fetchProfilesService; - - /** - * Deserializes {@link ProfileResponse} and updates the profiles. - */ - static void deserializeResponseAndUpdateProfiles(RemoteProfileManagerImpl manager, - ProfileResponse profileResponse) { - int i = 0; - for (FetchedProfile fetchedProfile : profileResponse.getProfiles()) { - deserializeAndUpdateProfile(manager, fetchedProfile); - i++; - } - } - - static private void deserializeAndUpdateProfile(RemoteProfileManagerImpl manager, - FetchedProfile fetchedProfile) { - ParticipantId participantId = ParticipantId.ofUnsafe(fetchedProfile.getAddress()); - ProfileImpl profile = manager.getProfile(participantId); - // Profiles already exist for all profiles that have been requested. - assert profile != null; - // Updates profiles - this also notifies listeners. - profile - .update(fetchedProfile.getName(), fetchedProfile.getName(), fetchedProfile.getImageUrl()); - } - - public RemoteProfileManagerImpl() { - fetchProfilesService = FetchProfilesServiceImpl.create(); - } - - @Override - public ProfileImpl getProfile(ParticipantId participantId) { - String address = participantId.getAddress(); - ProfileImpl profile = profiles.get(address); - if (profile == null) { - profile = new ProfileImpl(this, participantId); - profiles.put(address, profile); - LOG.trace().log("Fetching profile: " + address); - fetchProfilesService.fetch(this, address); - } - return profile; - } - - @Override - public void onFailure(String message) { - LOG.error().log(message); - // TODO (user) Try to re-fetch the profile. - } - - @Override - public void onSuccess(ProfileResponse profileResponse) { - deserializeResponseAndUpdateProfiles(this, profileResponse); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/Digest.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/Digest.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/Digest.java deleted file mode 100644 index b41419a..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/Digest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.util.List; - -/** - * A wave digest. - * - * @author [email protected] (David Hearnden) - */ -public interface Digest { - - /** @return the wave represented by this digest. Never null. */ - WaveId getWaveId(); - - /** @return the identity of the wave's author. May be null. */ - ParticipantId getAuthor(); - - /** @return the identities of some other participants on this wave. Never null. */ - List<ParticipantId> getParticipantsSnippet(); - - /** @return the title of this wave. May be null. */ - String getTitle(); - - /** @return a snippet for this wave. May be null. */ - String getSnippet(); - - /** @return the number of messages in this wave. */ - int getBlipCount(); - - /** @return the number of unread messages in this wave. */ - int getUnreadCount(); - - /** @return the epoch time of the last modification of this wave. */ - double getLastModifiedTime(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestDomImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestDomImpl.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestDomImpl.java deleted file mode 100644 index ba5c045..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestDomImpl.java +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Element; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.CssResource; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import org.waveprotocol.box.webclient.search.i18n.DigestDomMessages; - -import org.waveprotocol.wave.client.account.Profile; -import org.waveprotocol.wave.client.common.safehtml.SafeHtml; -import org.waveprotocol.wave.client.common.safehtml.SafeHtmlBuilder; -import org.waveprotocol.wave.client.uibuilder.BuilderHelper; - -/** - * DOM implementation of a digest view. - * - * @author [email protected] (David Hearnden) - */ -public final class DigestDomImpl implements DigestView { - private static final DigestDomMessages messages = GWT.create(DigestDomMessages.class); - - /** HTML attribute used to hold an id unique within digest widgets. */ - static String DIGEST_ID_ATTRIBUTE = "di"; - - /** Resources used by this widget. */ - interface Resources extends ClientBundle { - /** CSS */ - @Source("mock/digest.css") - Css css(); - } - - interface Css extends CssResource { - String digest(); - - String inner(); - - String avatars(); - - String avatar(); - - String info(); - - String unread(); - - String unreadCount(); - - String selected(); - } - - @UiField(provided = true) - final static Css css = SearchPanelResourceLoader.getDigest().css(); - - interface Binder extends UiBinder<Element, DigestDomImpl> { - } - - private final static Binder BINDER = GWT.create(Binder.class); - private static int idCounter; - - private final SearchPanelWidget container; - private final Element self; - @UiField - Element avatars; - @UiField - Element title; - @UiField - Element snippet; - @UiField - Element time; - @UiField - Element msgs; - - DigestDomImpl(SearchPanelWidget container) { - this.container = container; - this.self = BINDER.createAndBindUi(this); - self.setAttribute(BuilderHelper.KIND_ATTRIBUTE, "digest"); - self.setAttribute(DIGEST_ID_ATTRIBUTE, "D" + idCounter++); - } - - @Override - public void remove() { - self.removeFromParent(); - container.onDigestRemoved(this); - } - - /** @return an id of this widget, unique within the space of digest widgets. */ - String getId() { - return self.getAttribute(DIGEST_ID_ATTRIBUTE); - } - - /** Restores this object to a post-constructor state. */ - void reset() { - avatars.setInnerHTML(""); - title.setInnerText(""); - snippet.setInnerText(""); - time.setInnerText(""); - msgs.setInnerHTML(""); - self.removeClassName(css.selected()); - } - - @Override - public void setAvatars(Iterable<Profile> profiles) { - SafeHtmlBuilder html = new SafeHtmlBuilder(); - for (Profile profile : profiles) { - renderAvatar(html, profile); - } - avatars.setInnerHTML(html.toSafeHtml().asString()); - } - - @Override - public void setTitleText(String title) { - this.title.setInnerText(title); - } - - @Override - public void setSnippet(String snippet) { - this.snippet.setInnerText(snippet); - } - - @Override - public void setTimestamp(String time) { - this.time.setInnerText(time); - } - - @Override - public void setMessageCounts(int unread, int total) { - if (unread == 0) { - msgs.setInnerHTML(renderReadMessages(total).asString()); - title.removeClassName(css.unread()); - time.removeClassName(css.unread()); - } else { - msgs.setInnerHTML(renderUnreadMessages(unread, total).asString()); - title.addClassName(css.unread()); - time.addClassName(css.unread()); - } - } - - private SafeHtml renderUnreadMessages(int unread, int total) { - SafeHtmlBuilder html = new SafeHtmlBuilder(); - html.appendHtmlConstant("<span class='" + css.unreadCount() + "'>"); - html.appendHtmlConstant(String.valueOf(unread)); - html.appendHtmlConstant("</span>"); - html.appendHtmlConstant(" " + messages.of(total)); - return html.toSafeHtml(); - } - - private SafeHtml renderReadMessages(int total) { - SafeHtmlBuilder html = new SafeHtmlBuilder(); - html.appendHtmlConstant(String.valueOf(total)); - html.appendHtmlConstant(" " + messages.msgs()); - return html.toSafeHtml(); - } - - private void renderAvatar(SafeHtmlBuilder html, Profile profile) { - // URL is trusted to be attribute safe (i.e., no ' or ") - String url = profile.getImageUrl(); - String name = profile.getFullName(); - html.appendHtmlConstant("<img class='" + css.avatar() + "' src='"); - html.appendHtmlConstant(url); - html.appendHtmlConstant("' alt='"); - html.appendEscaped(name); - html.appendHtmlConstant("' title='"); - html.appendEscaped(name); - html.appendHtmlConstant("'>"); - } - - @Override - public void select() { - self.addClassName(css.selected()); - } - - @Override - public void deselect() { - self.removeClassName(css.selected()); - } - - Element getElement() { - return self; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestView.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestView.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestView.java deleted file mode 100644 index 9939514..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/DigestView.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import org.waveprotocol.wave.client.account.Profile; - -/** - * View interface for a digest. - * - * @author [email protected] (David Hearnden) - */ -public interface DigestView { - /** Removes this view from the UI. */ - void remove(); - - void setAvatars(Iterable<Profile> urls); - - void setTimestamp(String time); - - // Note: setTitle is a widget method. - void setTitleText(String text); - - void setSnippet(String snippet); - - void setMessageCounts(int unread, int total); - - /** Renders this view in the selected state. */ - void select(); - - /** Renders this view in the de-selected state. */ - void deselect(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/JsoSearchBuilderImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/JsoSearchBuilderImpl.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/JsoSearchBuilderImpl.java deleted file mode 100644 index d8c63df..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/JsoSearchBuilderImpl.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.common.base.Preconditions; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.http.client.URL; - -import org.waveprotocol.box.search.SearchRequest; -import org.waveprotocol.box.search.SearchResponse; -import org.waveprotocol.box.search.SearchResponse.Digest; -import org.waveprotocol.box.search.jso.SearchRequestJsoImpl; -import org.waveprotocol.box.search.jso.SearchResponseJsoImpl; -import org.waveprotocol.box.webclient.search.SearchService.Callback; -import org.waveprotocol.box.webclient.search.SearchService.DigestSnapshot; -import org.waveprotocol.wave.client.debug.logger.DomLogger; -import org.waveprotocol.wave.common.logging.LoggerBundle; -import org.waveprotocol.wave.communication.gwt.JsonMessage; -import org.waveprotocol.wave.communication.json.JsonException; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.util.List; - -/** - * Helper class to perform searches. - * - * @author [email protected] (Yuri Z.) - */ -public final class JsoSearchBuilderImpl implements SearchBuilder { - private static final LoggerBundle LOG = new DomLogger("SearchBuilder"); - - /** The base search URL. */ - private static final String SEARCH_URL_BASE = "/search"; - - /** Holds search request data. */ - private SearchRequest searchRequest; - - private JsoSearchBuilderImpl() { - } - - /** Static factory method */ - public static SearchBuilder create() { - return new JsoSearchBuilderImpl(); - } - - @Override - public SearchBuilder newSearch() { - searchRequest = SearchRequestJsoImpl.create(); - return this; - } - - @Override - public SearchBuilder setQuery(String query) { - searchRequest.setQuery(query); - return this; - } - - @Override - public SearchBuilder setIndex(int index) { - searchRequest.setIndex(index); - return this; - } - - @Override - public SearchBuilder setNumResults(int numResults) { - searchRequest.setNumResults(numResults); - return this; - } - - @Override - public Request search(final Callback callback) { - Preconditions.checkArgument(searchRequest != null, - "call SearchBuilder.newSearch method to construct a new query"); - Preconditions.checkArgument(searchRequest.getQuery() != null, "new query should be set"); - - String url = getUrl(searchRequest); - LOG.trace().log("Performing a search query: [Query: ", searchRequest.getQuery(), ", Index: ", - searchRequest.getIndex(), ", NumResults: ", searchRequest.getNumResults(), "]"); - - RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); - - requestBuilder.setCallback(new RequestCallback() { - @Override - public void onResponseReceived(Request request, Response response) { - LOG.trace().log("Search response received: ", response.getText()); - if (response.getStatusCode() != Response.SC_OK) { - callback.onFailure("Got back status code " + response.getStatusCode()); - } else if (!response.getHeader("Content-Type").startsWith("application/json")) { - callback.onFailure("Search service did not return json"); - } else { - SearchResponseJsoImpl searchResponse; - try { - searchResponse = JsonMessage.parse(response.getText()); - } catch (JsonException e) { - callback.onFailure(e.getMessage()); - return; - } - List<DigestSnapshot> digestSnapshots = - SearchBuilderUtils.deserializeSearchResponse(searchResponse); - callback.onSuccess(searchResponse.getTotalResults(), digestSnapshots); - } - } - - @Override - public void onError(Request request, Throwable exception) { - LOG.error().log("Search error: ", exception); - callback.onFailure(exception.getMessage()); - } - }); - - try { - return requestBuilder.send(); - } catch (RequestException e) { - callback.onFailure(e.getMessage()); - return null; - } - } - - private static class SearchBuilderUtils { - /** - * Constructs a list of {@link org.waveprotocol.box.webclient.search.Digest} - * from {@link SearchResponse}. - */ - private static List<DigestSnapshot> deserializeSearchResponse( - SearchResponse searchResponse) { - List<DigestSnapshot> digestSnapshots = - CollectionUtils.newArrayList(); - int i = 0; - for (SearchResponse.Digest digest : searchResponse.getDigests()) { - DigestSnapshot digestSnapshot = deserializeDigest(digest); - digestSnapshots.add(i, digestSnapshot); - i++; - } - return digestSnapshots; - } - - private static DigestSnapshot deserializeDigest(Digest digest) { - List<ParticipantId> participantIds = CollectionUtils.newArrayList(); - for (String participant : digest.getParticipants()) { - participantIds.add(ParticipantId.ofUnsafe(participant)); - } - DigestSnapshot digestSnapshot = - new DigestSnapshot(digest.getTitle(), digest.getSnippet(), WaveId.deserialise(digest - .getWaveId()), ParticipantId.ofUnsafe(digest.getAuthor()), participantIds, - digest.getLastModified(), digest.getUnreadCount(), digest.getBlipCount()); - return digestSnapshot; - } - } - - private static String getUrl(SearchRequest searchRequest) { - String query = URL.encodeQueryString(searchRequest.getQuery()); - String params = - "?query=" + query + - "&index=" + searchRequest.getIndex() + - "&numResults=" + searchRequest.getNumResults(); - return SEARCH_URL_BASE + "/" + params; - } - - @Override - public String toString() { - return "[Query: " + searchRequest.getQuery() + ", Index: " + searchRequest.getIndex() - + ", NumResults: " + searchRequest.getNumResults() + "]"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/Pool.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/Pool.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/Pool.java deleted file mode 100644 index e076ce1..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/Pool.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -/** - * A pool of objects with recycling. - * - * @author [email protected] (David Hearnden) - */ -public interface Pool<T> { - /** - * Retrieves an item, either from the free pool or by creating a new one. - * - * @return an item ready to use. - */ - T get(); - - /** - * Recycles an item. The item is returned to the free pool, potentially - * asynchronously, after it has been recycled. - * - * @param item item to recycle - */ - void recycle(T item); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/RemoteSearchService.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/RemoteSearchService.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/RemoteSearchService.java deleted file mode 100644 index 465d780..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/RemoteSearchService.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.http.client.Request; - -/** - * Implementation of {@link SearchService}. - * - * @author [email protected] (Yuri Z.) - */ -public final class RemoteSearchService implements SearchService { - private static final SearchBuilder DEFAULT_SEARCHER = JsoSearchBuilderImpl.create(); - private final SearchBuilder searcher; - - RemoteSearchService(SearchBuilder searcher) { - this.searcher = searcher; - } - - public static RemoteSearchService create() { - return new RemoteSearchService(DEFAULT_SEARCHER); - } - - @Override - public Request search(String query, int index, int numResults, Callback callback) { - return searcher.newSearch().setQuery(query).setIndex(index).setNumResults(numResults) - .search(callback); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/Search.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/Search.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/Search.java deleted file mode 100644 index 59bf52b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/Search.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import org.waveprotocol.wave.model.wave.SourcesEvents; - -/** - * An ordered collection of asynchronously-loaded digests. - * <p> - * A search result is a fixed-size list of digests, any of which may be null. - * Each transition from {@link Search.State#SEARCHING} to {@link Search.State#READY} indicates - * a fresh, new search result. A search result may evolve in three ways: - * <ul> - * <li>a digest entry become populated ( - * {@link Search.Listener#onDigestReady});</li> - * <li>a new digest entry is inserted into the result, increasing its size ( - * {@link Search.Listener#onDigestAdded}); and</li> - * <li>a digest entry is removed from the result, decreasing its size ( - * {@link Search.Listener#onDigestRemoved}).</li> - * </ul> - * - * @author [email protected] (David Hearnden) - */ -public interface Search extends SourcesEvents<Search.Listener> { - - /** - * Observes changes to the search result. - */ - public interface Listener { - /** - * Notifies this listener that the search's {@link #getState state} has - * changed. - */ - void onStateChanged(); - - // - // The following events are not currently provided by any search - // implementation. - // - - /** - * Notifies this listener of a position in the search where data is now - * available. - */ - void onDigestReady(int index, Digest digest); - - /** - * Notifies this listener that a new entry has been inserted into the results. - */ - void onDigestAdded(int index, Digest digest); - - /** - * Notifies this listener that a digest has been removed from the results. - */ - void onDigestRemoved(int index, Digest digest); - - /** - * Notifies this listener that the size of the search has changed. - */ - void onTotalChanged(int total); - } - - enum State { - /** - * Search is ready for queries. - */ - READY, - /** - * A search is underway. - */ - SEARCHING, - } - - /** - * Symbolic constant to indicate that the total size of the search result is - * unknown. - */ - int UNKNOWN_SIZE = -1; - - /** - * @return the current search state. - */ - State getState(); - - /** - * Performs a search. This search's state will become {@link State#SEARCHING}, - * and then {@link State#READY} once some results are ready. - * - * @param query search query - * @param size maximum number of results to return - */ - void find(String query, int size); - - /** - * Stops the current search if there is one. - */ - void cancel(); - - /** - * @return the total number of results in this search, or {@link #UNKNOWN_SIZE}. - */ - int getTotal(); - - // Temporary hack to make up for Data API deficiencies. - /** - * @return a minimum known size of the search result. - */ - int getMinimumTotal(); - - - /** - * @return the digest at position {@code index} in the search result. This may - * return null, indicating that the digest at that location has not - * yet been loaded. - */ - Digest getDigest(int index); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchBuilder.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchBuilder.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchBuilder.java deleted file mode 100644 index 0294691..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.http.client.Request; - -import org.waveprotocol.box.webclient.search.SearchService.Callback; - -/** - * Interface for a search builder. - * - * @author [email protected] (Yuri Z.) - */ -public interface SearchBuilder { - - /** - * Initializes the {@link SearchBuilder} for a new search. - * - * @return the {@link SearchBuilder} to allow chaining. - */ - SearchBuilder newSearch(); - - /** - * @param query the query to execute. - */ - SearchBuilder setQuery(String query); - - /** - * @param index the index from which to return results. - */ - SearchBuilder setIndex(int index); - - /** - * @param numResults the maximum number of results to return. - */ - SearchBuilder setNumResults(int numResults); - - /** - * Performs a full text search on the waves. - * - * @param callback the callback through which the search query results are returned. - * @return the http request - */ - Request search(final Callback callback); - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelRenderer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelRenderer.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelRenderer.java deleted file mode 100644 index 7143d36..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelRenderer.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import org.waveprotocol.wave.client.account.Profile; -import org.waveprotocol.wave.client.account.ProfileManager; -import org.waveprotocol.wave.client.common.util.DateUtils; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.util.Collection; - -/** - * Renders a digest model into a digest view. - * - * @author [email protected] (David Hearnden) - */ -public final class SearchPanelRenderer { - private final static int MAX_AVATARS = 3; - - /** Profile provider, for avatars. */ - private final ProfileManager profiles; - - public SearchPanelRenderer(ProfileManager profiles) { - this.profiles = profiles; - } - - /** - * Renders a digest model into a digest view. - */ - public void render(Digest digest, DigestView digestUi) { - Collection<Profile> avatars = CollectionUtils.createQueue(); - if (digest.getAuthor() != null) { - avatars.add(profiles.getProfile(digest.getAuthor())); - } - for (ParticipantId other : digest.getParticipantsSnippet()) { - if (avatars.size() < MAX_AVATARS) { - avatars.add(profiles.getProfile(other)); - } else { - break; - } - } - - digestUi.setAvatars(avatars); - digestUi.setTitleText(digest.getTitle()); - digestUi.setSnippet(digest.getSnippet()); - digestUi.setMessageCounts(digest.getUnreadCount(), digest.getBlipCount()); - digestUi.setTimestamp( - DateUtils.getInstance().formatPastDate((long) digest.getLastModifiedTime())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelResourceLoader.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelResourceLoader.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelResourceLoader.java deleted file mode 100644 index 1784708..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelResourceLoader.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.StyleInjector; - -/** - * Loads all the Css resources needed by the search panel. The necessity of this - * loader is due to the unfortunate asynchrony with GWT's style injection. - * - * @author [email protected] (David Hearnden) - */ -public final class SearchPanelResourceLoader { - - private final static SearchWidget.Resources search = GWT.create(SearchWidget.Resources.class); - private final static SearchPanelWidget.Resources panel = GWT.create(SearchPanelWidget.Resources.class); - private final static DigestDomImpl.Resources digest = GWT.create(DigestDomImpl.Resources.class); - - static { - // Inject all CSS synchronously. CSS must be injected synchronously, so that - // any layout queries, that may happen to occur in the same event cycle, - // operate on the correct state (GWT's default injection mode is - // asynchronous). CSS is injected together in one bundle to minimize layout - // invalidation, and to leave open the possibility of merging stylesheets - // together for efficiency. - boolean isSynchronous = true; - StyleInjector.inject(search.css().getText(), isSynchronous); - StyleInjector.inject(panel.css().getText(), isSynchronous); - StyleInjector.inject(digest.css().getText(), isSynchronous); - } - - private SearchPanelResourceLoader() { - } - - public static SearchWidget.Resources getSearch() { - return search; - } - - public static SearchPanelWidget.Resources getPanel() { - return panel; - } - - public static DigestDomImpl.Resources getDigest() { - return digest; - } - - /** - * Loads all the CSS required by the search panel. - */ - public static void loadCss() { - // Static initializer does the work. - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelView.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelView.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelView.java deleted file mode 100644 index 2e60089..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelView.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import org.waveprotocol.wave.client.widget.toolbar.GroupingToolbar; - -/** - * View interface for the search panel. - * - * @author [email protected] (David Hearnden) - */ -public interface SearchPanelView { - - /** - * Receives gesture UI events. - */ - interface Listener { - /** - * Notifies this listener that a digest has been clicked. - */ - void onClicked(DigestView digestUi); - - /** - * Notifies this listener that the more-results button has been clicked. - */ - void onShowMoreClicked(); - } - - /** Binds this view to a listener to handle UI gestures. */ - void init(Listener listener); - - /** Releases this view from its listener. */ - void reset(); - - /** Sets the title bar text. */ - void setTitleText(String text); - - /** @return the search area. */ - SearchView getSearch(); - - /** @return the search toolbar. */ - GroupingToolbar.View getToolbar(); - - /** @return the first digest. */ - DigestView getFirst(); - - /** @return the last digest. */ - DigestView getLast(); - - /** @return the digest view after another. */ - DigestView getNext(DigestView ref); - - /** @return the digest view before another. */ - DigestView getPrevious(DigestView ref); - - /** @return a rendering of {@code digest}. */ - DigestView insertBefore(DigestView ref, Digest digest); - - /** @return a rendering of {@code digest}. */ - DigestView insertAfter(DigestView ref, Digest digest); - - /** Removes all digest views. */ - void clearDigests(); - - /** - * Sets whether the show-more button is visible. - */ - void setShowMoreVisible(boolean visible); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelWidget.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelWidget.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelWidget.java deleted file mode 100644 index b1486b0..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPanelWidget.java +++ /dev/null @@ -1,271 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.common.base.Preconditions; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.Style.Visibility; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.CssResource; -import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.resources.client.ImageResource.ImageOptions; -import com.google.gwt.resources.client.ImageResource.RepeatStyle; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.ui.Composite; - -import org.waveprotocol.box.webclient.widget.frame.FramedPanel; -import org.waveprotocol.wave.client.common.util.LinkedSequence; -import org.waveprotocol.wave.client.uibuilder.BuilderHelper; -import org.waveprotocol.wave.client.widget.common.ImplPanel; -import org.waveprotocol.wave.client.widget.toolbar.ToplevelToolbarWidget; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.StringMap; - -/** - * View interface for the search panel. - * - * @author [email protected] (David Hearnden) - */ -public class SearchPanelWidget extends Composite implements SearchPanelView { - - /** Resources used by this widget. */ - interface Resources extends ClientBundle { - @Source("images/toolbar_empty.png") - @ImageOptions(repeatStyle = RepeatStyle.Horizontal) - ImageResource emptyToolbar(); - - /** CSS */ - @Source("SearchPanel.css") - Css css(); - } - - interface Css extends CssResource { - String self(); - - String search(); - - String toolbar(); - - String list(); - - String showMore(); - } - - /** - * Positioning constants for components of this panel. - */ - static class CssConstants { - private static int SEARCH_HEIGHT_PX = 51; // To match wave panel. - private static int TOOLBAR_HEIGHT_PX = - SearchPanelResourceLoader.getPanel().emptyToolbar().getHeight(); - private static int TOOLBAR_TOP_PX = 0 + SEARCH_HEIGHT_PX; - private static int LIST_TOP_PX = TOOLBAR_TOP_PX + TOOLBAR_HEIGHT_PX; - - // CSS constants exported to .css files - static String SEARCH_HEIGHT = SEARCH_HEIGHT_PX + "px"; - static String TOOLBAR_TOP = TOOLBAR_TOP_PX + "px"; - static String LIST_TOP = LIST_TOP_PX + "px"; - } - - @UiField(provided = true) - static Css css = SearchPanelResourceLoader.getPanel().css(); - - interface Binder extends UiBinder<FramedPanel, SearchPanelWidget> { - } - - private final static Binder BINDER = GWT.create(Binder.class); - - private final FramedPanel frame; - @UiField - SearchWidget search; - @UiField - ToplevelToolbarWidget toolbar; - @UiField - Element list; - @UiField - Element showMore; - @UiField - ImplPanel self; - private final LinkedSequence<DigestDomImpl> digests = LinkedSequence.create(); - private final StringMap<DigestDomImpl> byId = CollectionUtils.createStringMap(); - private final SearchPanelRenderer renderer; - private final Pool<DigestDomImpl> digestPool = - ToppingUpPool.create(new ToppingUpPool.Factory<DigestDomImpl>() { - @Override - public DigestDomImpl create() { - return new DigestDomImpl(SearchPanelWidget.this); - } - }, 20); - private Listener listener; - - public SearchPanelWidget(SearchPanelRenderer renderer) { - initWidget(frame = BINDER.createAndBindUi(this)); - this.renderer = renderer; - } - - @Override - public void init(Listener listener) { - Preconditions.checkState(this.listener == null); - Preconditions.checkArgument(listener != null); - this.listener = listener; - } - - @Override - public void reset() { - Preconditions.checkState(listener != null); - listener = null; - } - - void onDigestRemoved(DigestDomImpl digestUi) { - digests.remove(digestUi); - byId.remove(digestUi.getId()); - - // Restore blank state and recycle. - digestUi.reset(); - digestPool.recycle(digestUi); - } - - @Override - public void setTitleText(String text) { - frame.setTitleText(text); - } - - @Override - public SearchWidget getSearch() { - return search; - } - - public ToplevelToolbarWidget getToolbar() { - return toolbar; - } - - @Override - public DigestDomImpl getFirst() { - return digests.getFirst(); - } - - @Override - public DigestDomImpl getLast() { - return digests.getLast(); - } - - @Override - public DigestDomImpl getNext(DigestView ref) { - return digests.getNext(narrow(ref)); - } - - @Override - public DigestDomImpl getPrevious(DigestView ref) { - return digests.getPrevious(narrow(ref)); - } - - @Override - public DigestDomImpl insertBefore(DigestView ref, Digest digest) { - DigestDomImpl digestUi = digestPool.get(); - renderer.render(digest, digestUi); - - DigestDomImpl refDomImpl = narrow(ref); - Element refElement = refDomImpl != null ? refDomImpl.getElement() : showMore; - byId.put(digestUi.getId(), digestUi); - digests.insertBefore(refDomImpl, digestUi); - list.insertBefore(digestUi.getElement(), refElement); - - return digestUi; - } - - @Override - public DigestDomImpl insertAfter(DigestView ref, Digest digest) { - DigestDomImpl digestUi = digestPool.get(); - renderer.render(digest, digestUi); - - DigestDomImpl refDomImpl = narrow(ref); - Element refElement = refDomImpl != null ? refDomImpl.getElement() : showMore; - byId.put(digestUi.getId(), digestUi); - if (refElement != showMore) { - digests.insertAfter(refDomImpl, digestUi); - list.insertAfter(digestUi.getElement(), refElement); - } else { - digests.insertBefore(refDomImpl, digestUi); - list.insertBefore(digestUi.getElement(), refElement); - } - return digestUi; - } - - @Override - public void clearDigests() { - while (!digests.isEmpty()) { - digests.getFirst().remove(); // onDigestRemoved removes it from digests. - } - assert digests.isEmpty(); - } - - @Override - public void setShowMoreVisible(boolean visible) { - // In order to keep the padding effect, the button always need to be present - // in order to affect layout. Just make it invisible and non-clickable. - if (visible) { - showMore.getStyle().clearVisibility(); - } else { - showMore.getStyle().setVisibility(Visibility.HIDDEN); - } - } - - @UiHandler("self") - void handleClick(ClickEvent e) { - Element target = e.getNativeEvent().getEventTarget().cast(); - Element top = self.getElement(); - while (!top.equals(target)) { - if ("digest".equals(target.getAttribute(BuilderHelper.KIND_ATTRIBUTE))) { - handleClick(byId.get(target.getAttribute(DigestDomImpl.DIGEST_ID_ATTRIBUTE))); - e.stopPropagation(); - return; - } else if (showMore.equals(target)) { - handleShowMoreClicked(); - } - target = target.getParentElement(); - } - } - - private void handleClick(DigestDomImpl digestUi) { - if (digestUi == null) { - // Error - there's an element in the DOM that looks like a digest, but - // it's not in the digest map. - // TODO(hearnden): log. - } else { - if (listener != null) { - listener.onClicked(digestUi); - } - } - } - - private void handleShowMoreClicked() { - if (listener != null) { - listener.onShowMoreClicked(); - } - } - - private static DigestDomImpl narrow(DigestView digestUi) { - return (DigestDomImpl) digestUi; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPresenter.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPresenter.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPresenter.java deleted file mode 100644 index e2978f2..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchPresenter.java +++ /dev/null @@ -1,399 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.core.client.GWT; -import org.waveprotocol.box.webclient.search.Search.State; -import org.waveprotocol.box.webclient.search.i18n.SearchPresenterMessages; -import org.waveprotocol.wave.client.account.Profile; -import org.waveprotocol.wave.client.account.ProfileListener; -import org.waveprotocol.wave.client.scheduler.Scheduler.IncrementalTask; -import org.waveprotocol.wave.client.scheduler.Scheduler.Task; -import org.waveprotocol.wave.client.scheduler.SchedulerInstance; -import org.waveprotocol.wave.client.scheduler.TimerService; -import org.waveprotocol.wave.client.widget.toolbar.GroupingToolbar; -import org.waveprotocol.wave.client.widget.toolbar.ToolbarButtonViewBuilder; -import org.waveprotocol.wave.client.widget.toolbar.ToolbarView; -import org.waveprotocol.wave.client.widget.toolbar.buttons.ToolbarClickButton; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.IdentityMap; -import org.waveprotocol.wave.model.wave.SourcesEvents; - -/** - * Presents a search model into a search view. - * <p> - * This class invokes rendering, and controls the lifecycle of digest views. It - * also handles all UI gesture events sourced from views in the search panel. - * - * @author [email protected] (David Hearnden) - */ -public final class SearchPresenter - implements Search.Listener, SearchPanelView.Listener, SearchView.Listener, ProfileListener { - - /** - * Handles wave actions. - */ - public interface WaveActionHandler { - /** Handles the wave creation action. */ - void onCreateWave(); - - /** Handles a wave selection action. */ - void onWaveSelected(WaveId id); - } - - private static final SearchPresenterMessages messages = GWT.create(SearchPresenterMessages.class); - - /** How often to repeat the search query. */ - private final static int POLLING_INTERVAL_MS = 15000; // 15s - private final static String DEFAULT_SEARCH = "in:inbox"; - private final static int DEFAULT_PAGE_SIZE = 20; - - // External references - private final TimerService scheduler; - private final Search search; - private final SearchPanelView searchUi; - private final WaveActionHandler actionHandler; - - // Internal state - private final IdentityMap<DigestView, Digest> digestUis = CollectionUtils.createIdentityMap(); - private final IncrementalTask searchUpdater = new IncrementalTask() { - @Override - public boolean execute() { - doSearch(); - return true; - } - }; - - private final Task renderer = new Task() { - @Override - public void execute() { - if (search.getState() == State.READY) { - render(); - } else { - // Try again later. - scheduler.schedule(this); - } - } - }; - - /** Current search query. */ - private String queryText = DEFAULT_SEARCH; - /** Number of results to query for. */ - private int querySize = DEFAULT_PAGE_SIZE; - /** Current selected digest. */ - private DigestView selected; - - /** The dispatcher of profiles events. */ - SourcesEvents<ProfileListener> profiles; - private boolean isRenderingInProgress = false; - - SearchPresenter(TimerService scheduler, Search search, SearchPanelView searchUi, - WaveActionHandler actionHandler, SourcesEvents<ProfileListener> profiles) { - this.search = search; - this.searchUi = searchUi; - this.scheduler = scheduler; - this.actionHandler = actionHandler; - this.profiles = profiles; - } - - /** - * Creates a search presenter. - * - * @param model model to present - * @param view view to render into - * @param actionHandler handler for actions - * @param profileEventsDispatcher the dispatcher of profile events. - */ - public static SearchPresenter create( - Search model, SearchPanelView view, WaveActionHandler actionHandler, - SourcesEvents<ProfileListener> profileEventsDispatcher) { - SearchPresenter presenter = new SearchPresenter( - SchedulerInstance.getHighPriorityTimer(), model, view, actionHandler, - profileEventsDispatcher); - presenter.init(); - return presenter; - } - - /** - * Performs initial presentation, and attaches listeners to live objects. - */ - private void init() { - initToolbarMenu(); - initSearchBox(); - render(); - search.addListener(this); - profiles.addListener(this); - searchUi.init(this); - searchUi.getSearch().init(this); - - // Fire a polling search. - scheduler.scheduleRepeating(searchUpdater, 0, POLLING_INTERVAL_MS); - } - - /** - * Releases resources and detaches listeners. - */ - public void destroy() { - scheduler.cancel(searchUpdater); - scheduler.cancel(renderer); - searchUi.getSearch().reset(); - searchUi.reset(); - search.removeListener(this); - profiles.removeListener(this); - } - - /** - * Adds custom buttons to the toolbar. - */ - private void initToolbarMenu() { - GroupingToolbar.View toolbarUi = searchUi.getToolbar(); - ToolbarView group = toolbarUi.addGroup(); - new ToolbarButtonViewBuilder().setText(messages.newWave()).applyTo( - group.addClickButton(), new ToolbarClickButton.Listener() { - @Override - public void onClicked() { - actionHandler.onCreateWave(); - - // HACK(hearnden): To mimic live search, fire a search poll - // reasonably soon (500ms) after creating a wave. This will be unnecessary - // with a real live search implementation. The delay is to give - // enough time for the wave state to propagate to the server. - int delay = 500; - scheduler.scheduleRepeating(searchUpdater, delay, POLLING_INTERVAL_MS); - } - }); - // Fake group with empty button - to force the separator be displayed. - group = toolbarUi.addGroup(); - new ToolbarButtonViewBuilder().setText("").applyTo(group.addClickButton(), null); - } - - /** - * Initializes the search box. - */ - private void initSearchBox() { - searchUi.getSearch().setQuery(queryText); - } - - /** - * Executes the current search. - */ - private void doSearch() { - search.find(queryText, querySize); - } - - /** - * Renders the current state of the search result into the panel. - */ - private void render() { - renderTitle(); - renderDigests(); - renderShowMore(); - } - - /** - * Renders the paging information into the title bar. - */ - private void renderTitle() { - int resultEnd = querySize; - String totalStr; - if (search.getTotal() != Search.UNKNOWN_SIZE) { - resultEnd = Math.min(resultEnd, search.getTotal()); - totalStr = messages.of(search.getTotal()); - } else { - totalStr = messages.ofUnknown(); - } - searchUi.setTitleText(queryText + " (0-" + resultEnd + " of " + totalStr + ")"); - } - - private void renderDigests() { - isRenderingInProgress = true; - // Preserve selection on re-rendering. - WaveId toSelect = selected != null ? digestUis.get(selected).getWaveId() : null; - searchUi.clearDigests(); - digestUis.clear(); - setSelected(null); - for (int i = 0, size = search.getMinimumTotal(); i < size; i++) { - Digest digest = search.getDigest(i); - if (digest == null) { - continue; - } - DigestView digestUi = searchUi.insertBefore(null, digest); - digestUis.put(digestUi, digest); - if (digest.getWaveId().equals(toSelect)) { - setSelected(digestUi); - } - } - isRenderingInProgress = false; - } - - private void renderShowMore() { - searchUi.setShowMoreVisible( - search.getTotal() == Search.UNKNOWN_SIZE || querySize < search.getTotal()); - } - - // - // UI gesture events. - // - - private void setSelected(DigestView digestUi) { - if (selected != null) { - selected.deselect(); - } - selected = digestUi; - if (selected != null) { - selected.select(); - } - } - - /** - * Invokes the wave-select action on the currently selected digest. - */ - private void openSelected() { - actionHandler.onWaveSelected(digestUis.get(selected).getWaveId()); - } - - @Override - public void onClicked(DigestView digestUi) { - setSelected(digestUi); - openSelected(); - } - - @Override - public void onQueryEntered() { - queryText = searchUi.getSearch().getQuery(); - querySize = DEFAULT_PAGE_SIZE; - searchUi.setTitleText(messages.searching()); - doSearch(); - } - - @Override - public void onShowMoreClicked() { - querySize += DEFAULT_PAGE_SIZE; - doSearch(); - } - - // - // Search events. For now, dumbly re-render the whole list. - // - - @Override - public void onStateChanged() { - // - // If the state switches to searching, then do nothing. A manual title-bar - // update is performed in onQueryEntered(), and the title-bar should not be - // updated when a polling search fires. - // - // If the state switches to ready, then just update the title. Do not - // necessarily re-render, since that is only necessary if a change occurred, - // which would have fired one of the other methods below. - // - if (search.getState() == State.READY) { - renderTitle(); - } - } - - @Override - public void onDigestAdded(int index, Digest digest) { - renderLater(); - } - - @Override - public void onDigestRemoved(int index, Digest digest) { - renderLater(); - } - - /** - * Find the DigestView that contains a certain digest - * - * @param digest the digest the DigestView should contain. - * @return the DigestView containing the digest. {@null} if the digest is - * not found. - */ - private DigestView findDigestView(Digest digest) { - DigestView digestUi = searchUi.getFirst(); - while(digestUi != null) { - if (digestUis.get(digestUi).equals(digest)) { - return digestUi; - } - digestUi = searchUi.getNext(digestUi); - } - return null; - } - - /** - * Insert a digest before amongst the currently shown digests - * - * @param insertRef the DigestView to insert the new digest before. The new digest - * is inserted last if insertRef is {@null}. - * @param digest the digest to insert. - * @return the newly inserted DigestView. - */ - private DigestView insertDigest(DigestView insertRef, Digest digest) { - DigestView newDigestUi = null; - if (insertRef != null) { - newDigestUi = searchUi.insertBefore(insertRef, digest); - digestUis.put(newDigestUi, digest); - } else { - insertRef = searchUi.getLast(); - newDigestUi = searchUi.insertAfter(insertRef, digest); - digestUis.put(newDigestUi, digest); - } - return newDigestUi; - } - - @Override - public void onDigestReady(int index, Digest digest) { - if (isRenderingInProgress) { - return; - } - - setSelected(null); - DigestView digestToRemove = findDigestView(digest); - if (digestToRemove == null) { - return; - } - DigestView insertRef = searchUi.getNext(digestToRemove); - digestToRemove.remove(); - DigestView newDigestUi = insertDigest(insertRef, digest); - setSelected(newDigestUi); - } - - @Override - public void onTotalChanged(int total) { - renderLater(); - } - - private void renderLater() { - if (!scheduler.isScheduled(renderer)) { - scheduler.schedule(renderer); - } - } - - @Override - public void onProfileUpdated(Profile profile) { - // NOTE: Search panel will be re-rendered once for every profile that comes - // back to the client. If this causes an efficiency problem then have the - // SearchPanelRenderer to be the profile listener, rather than - // SearchPresenter, and make it stateful. Have it remember which digests - // have used which profiles in their renderings. - renderLater(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchService.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchService.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchService.java deleted file mode 100644 index fe686c9..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchService.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.http.client.Request; - -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.util.ValueUtils; -import org.waveprotocol.wave.model.wave.ParticipantId; - -import java.util.List; - -/** - * Interface that exposes search services to the client. - * - * @author [email protected] (David Hearnden) - * @author [email protected] (Yuri Z.) - */ -public interface SearchService { - - public interface Callback { - void onFailure(String message); - - /** - * Notifies this callback of a successful search response. - * - * @param total total number of results in the search (this is greater or - * equal to the size of {@code snapshots}, since not necessarily all - * results are returned) - * @param snapshots some digest snapshots - */ - void onSuccess(int total, List<DigestSnapshot> snapshots); - } - - /** - * An immutable digest. - */ - public final static class DigestSnapshot implements Digest { - private final String title; - private final String snippet; - private final WaveId waveId; - private final double lastModified; - private final int unreadCount; - private final int blipCount; - private final ParticipantId author; - private final List<ParticipantId> participants; - - public DigestSnapshot(String title, String snippet, WaveId waveId, ParticipantId author, - List<ParticipantId> participants, double lastModified, int unreadCount, int blipCount) { - this.title = title; - this.snippet = snippet; - this.waveId = waveId; - this.author = author; - this.participants = participants; - this.lastModified = lastModified; - this.unreadCount = unreadCount; - this.blipCount = blipCount; - } - - @Override - public String getTitle() { - return title; - } - - @Override - public String getSnippet() { - return snippet; - } - - @Override - public WaveId getWaveId() { - return waveId; - } - - @Override - public ParticipantId getAuthor() { - return author; - } - - @Override - public List<ParticipantId> getParticipantsSnippet() { - return participants; - } - - @Override - public double getLastModifiedTime() { - return lastModified; - } - - @Override - public int getUnreadCount() { - return unreadCount; - } - - @Override - public int getBlipCount() { - return blipCount; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((author == null) ? 0 : author.hashCode()); - result = prime * result + blipCount; - result = prime * result + (int) lastModified; - result = prime * result + participants.hashCode(); - result = prime * result + ((snippet == null) ? 0 : snippet.hashCode()); - result = prime * result + ((title == null) ? 0 : title.hashCode()); - result = prime * result + unreadCount; - result = prime * result + waveId.hashCode(); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - DigestSnapshot other = (DigestSnapshot) obj; - return waveId.equals(other.waveId) // - && ValueUtils.equal(author, other.author) // - && participants.equals(other.participants) // - && ValueUtils.equal(title, other.title) // - && ValueUtils.equal(snippet, other.snippet) // - && blipCount == other.blipCount // - && unreadCount == other.unreadCount // - && lastModified == other.lastModified; - } - } - - /** - * Symbolic constant to indicate that the total size of the search result is - * unknown. - */ - int UNKNOWN_SIZE = -1; - - /** - * Performs a search. - * - * @param query the query to execute. - * @param index the index from which to return results. - * @param numResults the maximum number of results to return. - * @param callback callback through which the search query results are - * returned. - */ - Request search(String query, int index, int numResults, Callback callback); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchServiceImpl.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchServiceImpl.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchServiceImpl.java deleted file mode 100644 index 0bbdc09..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchServiceImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -import com.google.gwt.http.client.Request; - -/** - * Implementation of {@link SearchService}. - * - * @author [email protected] (Yuri Z.) - */ -public class SearchServiceImpl implements SearchService { - - public static SearchBuilder SEARCH_BUILDER = JsoSearchBuilderImpl.create(); - - @Override - public Request search(String query, int index, int numResults, Callback callback) { - return SEARCH_BUILDER.newSearch().setQuery(query).setIndex(index).setNumResults(numResults) - .search(callback); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchView.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchView.java b/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchView.java deleted file mode 100644 index d91cb0a..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/search/SearchView.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.search; - -/** - * View interface for the search area in a search panel.. - * - * @author [email protected] (David Hearnden) - */ -public interface SearchView { - - /** - * Handles UI gesture events. - */ - interface Listener { - void onQueryEntered(); - } - - /** Binds this view to a listener to handle UI gestures. */ - void init(Listener listener); - - /** Releases this view from its listener. */ - void reset(); - - /** Sets the text in the query input. */ - void setQuery(String text); - - /** @return the text from the query input. */ - String getQuery(); -}
