Author: yurize
Date: Fri Nov 25 15:40:43 2011
New Revision: 1206227

URL: http://svn.apache.org/viewvc?rev=1206227&view=rev
Log:
Allow other uses of HistorySupport by [email protected] 
https://reviews.apache.org/r/2913/

Added:
    
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryChangeListener.java
      - copied, changed from r1206176, 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
    
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProvider.java
    
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProviderDefault.java
Modified:
    
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
    
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/WebClient.java
    
incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java

Copied: 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryChangeListener.java
 (from r1206176, 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java)
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryChangeListener.java?p2=incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryChangeListener.java&p1=incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java&r1=1206176&r2=1206227&rev=1206227&view=diff
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
 (original)
+++ 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryChangeListener.java
 Fri Nov 25 15:40:43 2011
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010 Google Inc.
+ * Copyright 2011 Google Inc.
  *
  * Licensed 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
@@ -20,21 +20,26 @@ import com.google.gwt.event.logical.shar
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 import com.google.gwt.user.client.History;
 
-import org.waveprotocol.box.webclient.client.events.Log;
 import org.waveprotocol.box.webclient.client.events.WaveSelectionEvent;
-import org.waveprotocol.wave.model.waveref.InvalidWaveRefException;
 import org.waveprotocol.wave.model.waveref.WaveRef;
-import org.waveprotocol.wave.util.escapers.GwtWaverefEncoder;
-
-import javax.annotation.Nullable;
+import org.waveprotocol.box.webclient.client.events.Log;
 
 /**
- * Contains the code to interface the history event mechanism with the client's
- * event bus. At the moment, a history token encodes a wave id or wave ref.
+ * The listener interface for receiving historyChange events from browser 
history.
+ *
+ * @author [email protected]
+ *
+ * @see {@link ValueChangeEvent}
  */
-public class HistorySupport {
-  private static final Log LOG = Log.get(HistorySupport.class);
+public class HistoryChangeListener {
+  private static final Log LOG = Log.get(HistoryChangeListener.class);
 
+  /**
+   * Commonly we start to listen history changes when webclient starts calling 
this
+   * method. If you are using wave client integrated with other different GWT 
application
+   * and with a different History management, you can avoid to use this and 
just
+   * call to the {@link WaveSelectionEvent} events (for example) or other uses.
+   */
   public static void init() {
     History.addValueChangeHandler(new ValueChangeHandler<String>() {
       @Override
@@ -43,7 +48,7 @@ public class HistorySupport {
         if (encodedToken == null || encodedToken.length() == 0) {
           return;
         }
-        WaveRef waveRef = waveRefFromHistoryToken(encodedToken);
+        WaveRef waveRef = HistorySupport.waveRefFromHistoryToken(encodedToken);
         if (waveRef == null) {
           LOG.info("History token contains invalid path: " + encodedToken);
           return;
@@ -54,23 +59,6 @@ public class HistorySupport {
     });
   }
 
-  /**
-   * @param encodedToken token to parse into waveref
-   * @return null if cannot parse into valid waveRef
-   */
-  @Nullable
-  public static WaveRef waveRefFromHistoryToken(String encodedToken) {
-    try {
-      return GwtWaverefEncoder.decodeWaveRefFromPath(encodedToken);
-    } catch (InvalidWaveRefException e) {
-      return null;
-    }
-  }
-
-  static String historyTokenFromWaveref(WaveRef ref) {
-    return GwtWaverefEncoder.encodeToUriPathSegment(ref);
-  }
-
-  private HistorySupport() {
+  public HistoryChangeListener() {
   }
 }

Added: 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProvider.java?rev=1206227&view=auto
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProvider.java
 (added)
+++ 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProvider.java
 Fri Nov 25 15:40:43 2011
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed 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.client;
+
+/**
+ * The Interface HistoryProvider gives access to the browser history stack in
+ * order to access to the wave tokens.
+ *
+ * Also this give us the opportunity to intercept these wave token petitions.
+ * Imagine that you are in fact using #clean-urls in your client you can return
+ * the waveref equivalent to the #clean-url when the wave webclient ask for the
+ * current token.
+ *
+ * @author [email protected]
+ */
+public interface HistoryProvider {
+
+  /**
+   * Gets the current wave history token. The handler will not receive a
+   * {@link 
ValueChangeHandler#onValueChange(com.google.gwt.event.logical.shared.ValueChangeEvent)}
+   * event for the initial token; requiring that an application request the
+   * token explicitly on startup gives it an opportunity to run different
+   * initialization code in the presence or absence of an initial token.
+   *
+   * @return the initial token, or the empty string if none is present.
+   */
+  String getToken();
+
+}

Added: 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProviderDefault.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProviderDefault.java?rev=1206227&view=auto
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProviderDefault.java
 (added)
+++ 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistoryProviderDefault.java
 Fri Nov 25 15:40:43 2011
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed 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.client;
+
+import com.google.gwt.user.client.History;
+
+/**
+ * The Class HistoryProviderDefault implements the common use of 
HistoryProvider in Webclient.
+ * @see org.waveprotocol.box.webclient.client.HistoryProvider
+ *
+ * @author [email protected]
+ *
+ */
+public class HistoryProviderDefault implements HistoryProvider {
+
+  /* (non-Javadoc)
+   * @see org.waveprotocol.box.webclient.client.HistoryProvider#getToken()
+   */
+  @Override
+  public String getToken() {
+    return History.getToken();
+  }
+}

Modified: 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java?rev=1206227&r1=1206226&r2=1206227&view=diff
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
 (original)
+++ 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/HistorySupport.java
 Fri Nov 25 15:40:43 2011
@@ -16,12 +16,7 @@
 
 package org.waveprotocol.box.webclient.client;
 
-import com.google.gwt.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.logical.shared.ValueChangeHandler;
-import com.google.gwt.user.client.History;
 
-import org.waveprotocol.box.webclient.client.events.Log;
-import org.waveprotocol.box.webclient.client.events.WaveSelectionEvent;
 import org.waveprotocol.wave.model.waveref.InvalidWaveRefException;
 import org.waveprotocol.wave.model.waveref.WaveRef;
 import org.waveprotocol.wave.util.escapers.GwtWaverefEncoder;
@@ -33,25 +28,11 @@ import javax.annotation.Nullable;
  * event bus. At the moment, a history token encodes a wave id or wave ref.
  */
 public class HistorySupport {
-  private static final Log LOG = Log.get(HistorySupport.class);
 
-  public static void init() {
-    History.addValueChangeHandler(new ValueChangeHandler<String>() {
-      @Override
-      public void onValueChange(ValueChangeEvent<String> event) {
-        String encodedToken = event.getValue();
-        if (encodedToken == null || encodedToken.length() == 0) {
-          return;
-        }
-        WaveRef waveRef = waveRefFromHistoryToken(encodedToken);
-        if (waveRef == null) {
-          LOG.info("History token contains invalid path: " + encodedToken);
-          return;
-        }
-        LOG.info("Changing selected wave based on history event to " + 
waveRef.toString());
-        ClientEvents.get().fireEvent(new WaveSelectionEvent(waveRef));
-      }
-    });
+  private static HistoryProvider historyProvider;
+
+  public static void init(HistoryProvider historyProvider) {
+    HistorySupport.historyProvider = historyProvider;
   }
 
   /**
@@ -67,10 +48,14 @@ public class HistorySupport {
     }
   }
 
-  static String historyTokenFromWaveref(WaveRef ref) {
+  public static String historyTokenFromWaveref(WaveRef ref) {
     return GwtWaverefEncoder.encodeToUriPathSegment(ref);
   }
 
   private HistorySupport() {
   }
+
+  public static String getToken() {
+    return historyProvider.getToken();
+  }
 }

Modified: 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/WebClient.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/WebClient.java?rev=1206227&r1=1206226&r2=1206227&view=diff
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/WebClient.java 
(original)
+++ 
incubator/wave/trunk/src/org/waveprotocol/box/webclient/client/WebClient.java 
Fri Nov 25 15:40:43 2011
@@ -162,7 +162,8 @@ public class WebClient implements EntryP
 
     setupConnectionIndicator();
 
-    HistorySupport.init();
+    HistorySupport.init(new HistoryProviderDefault());
+    HistoryChangeListener.init();
 
     websocket = new WaveWebSocketClient(useSocketIO(), 
getWebSocketBaseUrl(GWT.getModuleBaseURL()));
     websocket.connect();

Modified: 
incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java?rev=1206227&r1=1206226&r2=1206227&view=diff
==============================================================================
--- 
incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java
 (original)
+++ 
incubator/wave/trunk/src/org/waveprotocol/wave/client/wavepanel/impl/toolbar/EditToolbar.java
 Fri Nov 25 15:40:43 2011
@@ -23,7 +23,6 @@ import com.google.gwt.dom.client.Documen
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.http.client.URL;
-import com.google.gwt.user.client.History;
 import com.google.gwt.user.client.Window;
 
 import org.waveprotocol.box.webclient.client.HistorySupport;
@@ -340,7 +339,7 @@ public class EditToolbar {
 
   private void createInsertAttachmentButton(ToolbarView toolbar, final 
ParticipantId user) {
     // Find the current wave id.
-    String encodedToken = History.getToken();
+    String encodedToken = HistorySupport.getToken();
     WaveRef waveRef = null;
     if (encodedToken != null && !encodedToken.isEmpty()) {
       waveRef = HistorySupport.waveRefFromHistoryToken(encodedToken);


Reply via email to