Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rhbz723084 - initial work for bookmarkable text flow
  • Loading branch information
Patrick Huang committed Mar 14, 2013
1 parent 7a3ff69 commit c64105f
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 4 deletions.
@@ -0,0 +1,31 @@
package org.zanata.webtrans.client.events;

import org.zanata.webtrans.shared.model.TransUnitId;
import com.google.gwt.event.shared.GwtEvent;

public class BookmarkableTextFlowEvent extends GwtEvent<BookmarkableTextFlowEventHandler>
{
public static Type<BookmarkableTextFlowEventHandler> TYPE = new Type<BookmarkableTextFlowEventHandler>();

private TransUnitId textFlowId;

public BookmarkableTextFlowEvent(TransUnitId textFlowId)
{
this.textFlowId = textFlowId;
}

public Type<BookmarkableTextFlowEventHandler> getAssociatedType()
{
return TYPE;
}

protected void dispatch(BookmarkableTextFlowEventHandler handler)
{
handler.onBookmarkableTextFlow(this);
}

public TransUnitId getTextFlowId()
{
return textFlowId;
}
}
@@ -0,0 +1,8 @@
package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface BookmarkableTextFlowEventHandler extends EventHandler
{
void onBookmarkableTextFlow(BookmarkableTextFlowEvent event);
}
Expand Up @@ -41,6 +41,8 @@ public class HistoryToken
public static final String KEY_DOC_FILTER_CASE = "filtercase";
public static final String VALUE_DOC_FILTER_CASE_SENSITIVE = "sensitive";

public static final String KEY_TEXT_FLOW_ID = "textflow";

private MainView view;
private String fullDocPath;
private boolean docFilterExact;
Expand All @@ -52,6 +54,7 @@ public class HistoryToken
private boolean projectSearchCaseSensitive;
private boolean projectSearchInSource;
private boolean projectSearchInTarget;
private Long textFlowId;

// defaults
private static final MainView DEFAULT_VIEW = MainView.Documents;
Expand All @@ -65,6 +68,7 @@ public class HistoryToken
private static final boolean DEFAULT_PROJECT_SEARCH_CASE_SENSITIVE = false;
private static final boolean DEFAULT_PROJECT_SEARCH_IN_SOURCE = false;
private static final boolean DEFAULT_PROJECT_SEARCH_IN_TARGET = true;
private static final Long DEFAULT_TEXT_FLOW_ID = null;

public HistoryToken()
{
Expand All @@ -79,11 +83,12 @@ public HistoryToken()
projectSearchCaseSensitive = DEFAULT_PROJECT_SEARCH_CASE_SENSITIVE;
projectSearchInSource = DEFAULT_PROJECT_SEARCH_IN_SOURCE;
projectSearchInTarget = DEFAULT_PROJECT_SEARCH_IN_TARGET;
textFlowId = DEFAULT_TEXT_FLOW_ID;
}

/**
* Generate a history token from the given token string
*
*
* @param token A GWT history token in the form key1:value1;key2:value2;...
* @see #toTokenString()
*/
Expand Down Expand Up @@ -190,6 +195,10 @@ else if (value.equals(VALUE_SEARCH_PROJECT_FIELD_BOTH))
}
//else default used
}
else if (key.equals(KEY_TEXT_FLOW_ID))
{
historyToken.setTextFlowId(value);
}
else
{
Log.info("unrecognised history key: " + key);
Expand Down Expand Up @@ -404,6 +413,11 @@ else if (!projectSearchInSource && projectSearchInTarget)
// ignore if neither
}

if (textFlowId != null)
{
token = addTokenToTokenString(token, KEY_TEXT_FLOW_ID, textFlowId.toString());
}

return token;
}

Expand Down Expand Up @@ -477,7 +491,6 @@ private static String decode(String toDecode)
else if (nextChar == '!')
{
escaped = true;
continue;
}
else
{
Expand All @@ -498,4 +511,22 @@ public boolean isProjectSearchInTarget()
return projectSearchInTarget;
}

public void setTextFlowId(String textFlowId)
{
Long id;
try
{
id = Long.valueOf(textFlowId);
}
catch (Exception e)
{
id = null;
}
this.textFlowId = id;
}

public Long getTextFlowId()
{
return textFlowId;
}
}
Expand Up @@ -3,13 +3,17 @@
import static com.google.common.base.Objects.equal;
import net.customware.gwt.presenter.client.EventBus;

import org.zanata.webtrans.client.events.BookmarkableTextFlowEvent;
import org.zanata.webtrans.client.events.DocumentSelectionEvent;
import org.zanata.webtrans.client.events.FindMessageEvent;
import org.zanata.webtrans.client.events.TableRowSelectedEvent;
import org.zanata.webtrans.client.events.TransUnitSelectionEvent;
import org.zanata.webtrans.client.history.HistoryToken;
import org.zanata.webtrans.client.presenter.AppPresenter;
import org.zanata.webtrans.client.presenter.DocumentListPresenter;
import org.zanata.webtrans.client.presenter.SearchResultsPresenter;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.TransUnitId;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
Expand Down Expand Up @@ -52,6 +56,8 @@ public void onValueChange(ValueChangeEvent<String> event)
processForTransFilter(newHistoryToken);
processForProjectWideSearch(newHistoryToken);

processForTransUnitSelection(newHistoryToken);

currentHistoryState = newHistoryToken;
appPresenter.showView(newHistoryToken.getView());
}
Expand Down Expand Up @@ -116,5 +122,12 @@ protected void processForProjectWideSearch(HistoryToken token)
}
}


protected void processForTransUnitSelection(HistoryToken token)
{
if (!equal(token.getTextFlowId(), currentHistoryState.getTextFlowId()) && token.getTextFlowId() != null)
{
Log.info("[gwt-history] bookmarkable text flow has changed");
eventBus.fireEvent(new BookmarkableTextFlowEvent(new TransUnitId(token.getTextFlowId())));
}
}
}
Expand Up @@ -25,6 +25,8 @@

import net.customware.gwt.presenter.client.EventBus;

import org.zanata.webtrans.client.events.BookmarkableTextFlowEvent;
import org.zanata.webtrans.client.events.BookmarkableTextFlowEventHandler;
import org.zanata.webtrans.client.events.DocumentSelectionEvent;
import org.zanata.webtrans.client.events.DocumentSelectionHandler;
import org.zanata.webtrans.client.events.FindMessageEvent;
Expand Down Expand Up @@ -65,7 +67,7 @@
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class NavigationService implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, EditorPageSizeChangeEventHandler
public class NavigationService implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, EditorPageSizeChangeEventHandler, BookmarkableTextFlowEventHandler
{
public static final int FIRST_PAGE = 0;
public static final int UNSELECTED = -1;
Expand Down Expand Up @@ -99,6 +101,7 @@ private void bindHandlers()
eventBus.addHandler(FindMessageEvent.getType(), this);
eventBus.addHandler(NavTransUnitEvent.getType(), this);
eventBus.addHandler(EditorPageSizeChangeEvent.TYPE, this);
eventBus.addHandler(BookmarkableTextFlowEvent.TYPE, this);
}

protected void requestTransUnitsAndUpdatePageIndex(GetTransUnitActionContext actionContext, final boolean needReloadIndex)
Expand Down Expand Up @@ -348,6 +351,13 @@ protected void init(GetTransUnitActionContext context)
requestTransUnitsAndUpdatePageIndex(context, true);
}

@Override
public void onBookmarkableTextFlow(BookmarkableTextFlowEvent event)
{
this.context = context.changeTargetTransUnitId(event.getTextFlowId());
requestTransUnitsAndUpdatePageIndex(context, true);
}

public static interface UpdateContextCommand
{
GetTransUnitActionContext updateContext(GetTransUnitActionContext currentContext);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.*;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.testng.annotations.Test;
import org.zanata.webtrans.client.presenter.MainView;
Expand Down Expand Up @@ -36,6 +37,7 @@ public void constructionSetsDefaults()
assertEquals("default project-wide search text should be an empty string", "", token.getProjectSearchText());
assertEquals("default project-wide search replacement text should be an empty string", "", token.getProjectSearchReplacement());
assertFalse("default project-wide search case sensitive flag should be false", token.getProjectSearchCaseSensitive());
assertThat(token.getTextFlowId(), Matchers.nullValue());
}

@Test
Expand All @@ -51,6 +53,7 @@ public void fromEmptyStringSetsDefaults()
assertEquals("default project-wide search text should be an empty string", "", token.getProjectSearchText());
assertEquals("default project-wide search replacement text should be an empty string", "", token.getProjectSearchReplacement());
assertFalse("default project-wide search case sensitive flag should be false", token.getProjectSearchCaseSensitive());
assertThat(token.getTextFlowId(), Matchers.nullValue());
}

@Test
Expand All @@ -66,6 +69,7 @@ public void fromNullStringSetsDefaults()
assertEquals("default project-wide search text should be an empty string", "", token.getProjectSearchText());
assertEquals("default project-wide search replacement text should be an empty string", "", token.getProjectSearchReplacement());
assertFalse("default project-wide search case sensitive flag should be false", token.getProjectSearchCaseSensitive());
assertThat(token.getTextFlowId(), Matchers.nullValue());
}

@Test
Expand Down Expand Up @@ -118,6 +122,26 @@ public void fromTokenStringParameterOrderIrrelevant2()
assertTrue("project-wide search case sensitivity should be set from any position in token string", token.getProjectSearchCaseSensitive());
}

@Test
public void fromTokenStringHasTextFlowId()
{
String tokenString = "textflow:1";

token = HistoryToken.fromTokenString(tokenString);

assertThat(token.getTextFlowId(), Matchers.equalTo(1L));
}

@Test
public void badTextFlowId()
{
String tokenString = "textflow:abc";

token = HistoryToken.fromTokenString(tokenString);

assertThat(token.getTextFlowId(), Matchers.nullValue());
}

@Test
public void fromTokenStringUnknownTokenKeysIgnored()
{
Expand Down

0 comments on commit c64105f

Please sign in to comment.