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

Commit

Permalink
use testable history and window location interfaces in document list …
Browse files Browse the repository at this point in the history
…presenter
  • Loading branch information
davidmason committed Dec 12, 2011
1 parent e583829 commit 3adde38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Expand Up @@ -31,6 +31,10 @@
import org.zanata.webtrans.client.editor.filter.TransFilterView;
import org.zanata.webtrans.client.editor.table.TableEditorPresenter;
import org.zanata.webtrans.client.editor.table.TableEditorView;
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.HistoryImpl;
import org.zanata.webtrans.client.history.WindowLocation;
import org.zanata.webtrans.client.history.WindowLocationImpl;
import org.zanata.webtrans.client.presenter.AppPresenter;
import org.zanata.webtrans.client.presenter.DocumentListPresenter;
import org.zanata.webtrans.client.presenter.GlossaryPresenter;
Expand Down Expand Up @@ -95,6 +99,8 @@ protected void configure()
bindPresenter(UndoRedoPresenter.class, UndoRedoPresenter.Display.class, UndoRedoView.class);

bind(HasPageNavigation.class).to(TableEditorView.class).in(Singleton.class);
bind(History.class).to(HistoryImpl.class).in(Singleton.class);
bind(WindowLocation.class).to(WindowLocationImpl.class).in(Singleton.class);

// NB: if we bind directly to SeamDispatchAsync, we can't use
// replace-class in
Expand All @@ -103,7 +109,6 @@ protected void configure()

bind(Identity.class).toProvider(IdentityProvider.class).in(Singleton.class);
bind(WorkspaceContext.class).toProvider(WorkspaceContextProvider.class).in(Singleton.class);

}

static class WorkspaceContextProvider implements Provider<WorkspaceContext>
Expand Down
Expand Up @@ -39,7 +39,9 @@
import org.zanata.webtrans.client.events.ProjectStatsRetrievedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEventHandler;
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.HistoryToken;
import org.zanata.webtrans.client.history.WindowLocation;
import org.zanata.webtrans.client.presenter.AppPresenter.Display.MainView;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
Expand All @@ -56,8 +58,6 @@
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.view.client.HasData;
Expand Down Expand Up @@ -87,6 +87,8 @@ public interface Display extends WidgetDisplay
private DocumentInfo currentDocument;
private DocumentNode currentSelection;
private final WebTransMessages messages;
private final History history;
private final WindowLocation windowLocation;

private ListDataProvider<DocumentNode> dataProvider;
private HashMap<DocumentId, DocumentNode> nodes;
Expand All @@ -106,12 +108,14 @@ public interface Display extends WidgetDisplay
private static final String PRE_FILTER_QUERY_PARAMETER_KEY = "doc";

@Inject
public DocumentListPresenter(Display display, EventBus eventBus, WorkspaceContext workspaceContext, CachingDispatchAsync dispatcher, final WebTransMessages messages)
public DocumentListPresenter(Display display, EventBus eventBus, WorkspaceContext workspaceContext, CachingDispatchAsync dispatcher, final WebTransMessages messages, History history, WindowLocation windowLocation)
{
super(display, eventBus);
this.workspaceContext = workspaceContext;
this.dispatcher = dispatcher;
this.messages = messages;
this.history = history;
this.windowLocation = windowLocation;

dataProvider = display.getDataProvider();
nodes = new HashMap<DocumentId, DocumentNode>();
Expand All @@ -129,7 +133,7 @@ protected void onBind()
public void onSelection(SelectionEvent<DocumentInfo> event)
{
// generate history token
HistoryToken token = HistoryToken.fromTokenString(History.getToken());
HistoryToken token = HistoryToken.fromTokenString(history.getToken());

// prevent feedback loops between history and selection
boolean isNewSelection;
Expand All @@ -148,7 +152,7 @@ public void onSelection(SelectionEvent<DocumentInfo> event)
currentDocument = event.getSelectedItem();
token.setDocumentPath(event.getSelectedItem().getPath() + event.getSelectedItem().getName());
token.setView(MainView.Editor);
History.newItem(token.toTokenString());
history.newItem(token.toTokenString());
}
}
}));
Expand All @@ -173,11 +177,11 @@ public void onDocumentSelected(DocumentSelectionEvent event)
@Override
public void onValueChange(ValueChangeEvent<String> event)
{
HistoryToken token = HistoryToken.fromTokenString(History.getToken());
HistoryToken token = HistoryToken.fromTokenString(history.getToken());
if (event.getValue() != token.getDocFilterText())
{
token.setDocFilterText(event.getValue());
History.newItem(token.toTokenString());
history.newItem(token.toTokenString());
}
}
}));
Expand All @@ -187,16 +191,16 @@ public void onValueChange(ValueChangeEvent<String> event)
@Override
public void onValueChange(ValueChangeEvent<Boolean> event)
{
HistoryToken token = HistoryToken.fromTokenString(History.getToken());
HistoryToken token = HistoryToken.fromTokenString(history.getToken());
if (event.getValue() != token.getDocFilterExact())
{
token.setDocFilterExact(event.getValue());
History.newItem(token.toTokenString());
history.newItem(token.toTokenString());
}
}
}));

History.addValueChangeHandler(new ValueChangeHandler<String>()
history.addValueChangeHandler(new ValueChangeHandler<String>()
{

@Override
Expand Down Expand Up @@ -326,7 +330,7 @@ private void loadDocumentList()
{
// generate filter from query string if present
ArrayList<String> filterDocs = null;
List<String> queryDocs = Window.Location.getParameterMap().get(PRE_FILTER_QUERY_PARAMETER_KEY);
List<String> queryDocs = windowLocation.getParameterMap().get(PRE_FILTER_QUERY_PARAMETER_KEY);
if (queryDocs != null && !queryDocs.isEmpty())
{
filterDocs = new ArrayList<String>(queryDocs);
Expand All @@ -351,7 +355,7 @@ public void onSuccess(GetDocumentListResult result)
Log.info("Time to load docs into DocListView: " + String.valueOf(System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();

History.fireCurrentHistoryState();
history.fireCurrentHistoryState();

TranslationStats projectStats = new TranslationStats(); // projStats
// = 0
Expand Down

0 comments on commit 3adde38

Please sign in to comment.