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 - refactoring in preparation for the big change...
  • Loading branch information
Patrick Huang committed Mar 14, 2013
1 parent c64105f commit 97b3e28
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 67 deletions.

This file was deleted.

This file was deleted.

@@ -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 BookmarkedTextFlowEvent extends GwtEvent<BookmarkedTextFlowEventHandler>
{
public static Type<BookmarkedTextFlowEventHandler> TYPE = new Type<BookmarkedTextFlowEventHandler>();

private TransUnitId textFlowId;

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

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

protected void dispatch(BookmarkedTextFlowEventHandler 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 BookmarkedTextFlowEventHandler extends EventHandler
{
void onBookmarkableTextFlow(BookmarkedTextFlowEvent event);
}
Expand Up @@ -332,7 +332,7 @@ public void onTableRowSelected(TableRowSelectedEvent event)
{
TransUnitId selectedId = event.getSelectedId();
int rowIndex = navigationService.findRowIndexById(selectedId);
if (rowIndex != NavigationService.UNSELECTED)
if (rowIndex != NavigationService.UNDEFINED)
{
onRowSelected(rowIndex, event.isSuppressSavePending());
}
Expand Down
Expand Up @@ -3,11 +3,9 @@
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.BookmarkedTextFlowEvent;
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;
Expand Down Expand Up @@ -51,12 +49,13 @@ public void onValueChange(ValueChangeEvent<String> event)
Log.info("[gwt-history] Responding to history token: " + event.getValue());

processForDocumentListPresenter(newHistoryToken);
//AppPresenter process need to happen before transFilter. We want DocumentSelectionEvent to happen before FindMessageEvent.
processForAppPresenter(newHistoryToken);
processForTransFilter(newHistoryToken);
processForProjectWideSearch(newHistoryToken);

processForTransUnitSelection(newHistoryToken);
// AppPresenter process need to happen before transFilter. We want certain events happen in order:
// DocumentSelectionEvent -> FindMessageEvent -> BookmarkedTextFlowEvent
processForAppPresenter(newHistoryToken);
processForTransFilter(newHistoryToken);
processForBookmarkedTextFlow(newHistoryToken);

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

protected void processForTransUnitSelection(HistoryToken token)
protected void processForBookmarkedTextFlow(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())));
Log.info("[gwt-history] bookmarkable text flow has changed: " + token.getTextFlowId());
eventBus.fireEvent(new BookmarkedTextFlowEvent(new TransUnitId(token.getTextFlowId())));
}
}
}
Expand Up @@ -84,6 +84,10 @@ protected int getCurrentPage()
protected int getTargetPage(TransUnitId targetId)
{
int targetIndex = idIndexList.indexOf(targetId);
if (targetIndex == NavigationService.UNDEFINED)
{
return NavigationService.UNDEFINED;
}
return targetIndex / configHolder.getState().getEditorPageSize();
}

Expand Down
Expand Up @@ -25,8 +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.BookmarkedTextFlowEvent;
import org.zanata.webtrans.client.events.BookmarkedTextFlowEventHandler;
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 @@ -67,10 +67,10 @@
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class NavigationService implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, EditorPageSizeChangeEventHandler, BookmarkableTextFlowEventHandler
public class NavigationService implements TransUnitUpdatedEventHandler, FindMessageHandler, DocumentSelectionHandler, NavTransUnitHandler, EditorPageSizeChangeEventHandler, BookmarkedTextFlowEventHandler
{
public static final int FIRST_PAGE = 0;
public static final int UNSELECTED = -1;
public static final int UNDEFINED = -1;
private final EventBus eventBus;
private final CachingDispatchAsync dispatcher;
private final ModalNavigationStateHolder navigationStateHolder;
Expand Down Expand Up @@ -101,7 +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);
eventBus.addHandler(BookmarkedTextFlowEvent.TYPE, this);
}

protected void requestTransUnitsAndUpdatePageIndex(GetTransUnitActionContext actionContext, final boolean needReloadIndex)
Expand Down Expand Up @@ -352,10 +352,20 @@ protected void init(GetTransUnitActionContext context)
}

@Override
public void onBookmarkableTextFlow(BookmarkableTextFlowEvent event)
public void onBookmarkableTextFlow(BookmarkedTextFlowEvent event)
{
this.context = context.changeTargetTransUnitId(event.getTextFlowId());
requestTransUnitsAndUpdatePageIndex(context, true);
// FIXME this won't work. navigationStateHolder is not loaded on first load.
// int targetPage = navigationStateHolder.getTargetPage(event.getTextFlowId());
// if (targetPage == UNDEFINED)
// {
// TODO send a notification to user saying this bookmarked text flow id is invalid?
// TODO do we remove invalid bookmarked text flow from history token and url?
// return;
// }
this.context = context
// .changeOffset(targetPage)
.changeTargetTransUnitId(event.getTextFlowId());
requestTransUnitsAndUpdatePageIndex(context, false);
}

public static interface UpdateContextCommand
Expand Down
Expand Up @@ -15,12 +15,12 @@
public class SinglePageDataModelImpl
{
private List<TransUnit> data = Lists.newArrayList();
private int currentRow = NavigationService.UNSELECTED;
private int currentRow = NavigationService.UNDEFINED;

protected void setData(List<TransUnit> data)
{
this.data = Lists.newArrayList(data);
currentRow = NavigationService.UNSELECTED;
currentRow = NavigationService.UNDEFINED;
}

protected List<TransUnit> getData()
Expand Down Expand Up @@ -89,6 +89,6 @@ protected int findIndexById(TransUnitId id)
return rowNum;
}
}
return NavigationService.UNSELECTED;
return NavigationService.UNDEFINED;
}
}
Expand Up @@ -192,7 +192,7 @@ public void onSuccess(UpdateTransUnitResult result)
// we do not include goToLink here is because we haven't had message bookmark working
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Info, messages.notifyUpdateSaved(updatedTU.getRowIndex(), updatedTU.getId().toString())));
int rowIndexOnPage = navigationService.findRowIndexById(updatedTU.getId());
if (rowIndexOnPage != NavigationService.UNSELECTED)
if (rowIndexOnPage != NavigationService.UNDEFINED)
{
UndoLink undoLink = undoLinkProvider.get();
undoLink.prepareUndoFor(result);
Expand Down
Expand Up @@ -202,6 +202,7 @@ public void canGetTargetPage() {
assertThat(navigationStateHolder.getTargetPage(new TransUnitId(7)), Matchers.equalTo(2));
assertThat(navigationStateHolder.getTargetPage(new TransUnitId(9)), Matchers.equalTo(3));
assertThat(navigationStateHolder.getTargetPage(new TransUnitId(10)), Matchers.equalTo(3));
assertThat(navigationStateHolder.getTargetPage(new TransUnitId(999)), Matchers.equalTo(NavigationService.UNDEFINED));
}

@Test
Expand Down
Expand Up @@ -316,7 +316,7 @@ public void testFindRowIndexById() throws Exception
assertThat(service.findRowIndexById(new TransUnitId(2)), Matchers.equalTo(1));

// not in current page
assertThat(service.findRowIndexById(new TransUnitId(99)), Matchers.equalTo(NavigationService.UNSELECTED));
assertThat(service.findRowIndexById(new TransUnitId(99)), Matchers.equalTo(NavigationService.UNDEFINED));
}

@Test
Expand Down
Expand Up @@ -13,7 +13,7 @@
import com.google.common.collect.Lists;

import static org.hamcrest.MatcherAssert.*;
import static org.zanata.webtrans.client.service.NavigationService.UNSELECTED;
import static org.zanata.webtrans.client.service.NavigationService.UNDEFINED;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
Expand Down Expand Up @@ -45,13 +45,13 @@ public void canSetDataAndResetCurrentRowToUnselected()

model.setData(data);

assertThat(model.getCurrentRow(), Matchers.equalTo(UNSELECTED));
assertThat(model.getCurrentRow(), Matchers.equalTo(UNDEFINED));
assertThat(model.getData(), Matchers.is(data));

model.setSelected(1);
assertThat(model.getCurrentRow(), Matchers.equalTo(1));
model.setData(data);
assertThat(model.getCurrentRow(), Matchers.equalTo(UNSELECTED));
assertThat(model.getCurrentRow(), Matchers.equalTo(UNDEFINED));
}

@Test
Expand All @@ -75,7 +75,7 @@ public void canFindIndexById()
assertThat(index, Matchers.is(2));

int notFoundIndex = model.findIndexById(new TransUnitId(99));
assertThat(notFoundIndex, Matchers.is(UNSELECTED));
assertThat(notFoundIndex, Matchers.is(UNDEFINED));
}

@Test
Expand Down

0 comments on commit 97b3e28

Please sign in to comment.