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

Commit

Permalink
Merge branch 'master' of github.com:zanata/zanata
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Munoz committed Dec 14, 2011
2 parents 3acf716 + 0b2b5b3 commit 1426487
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 36 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
@@ -0,0 +1,27 @@
package org.zanata.webtrans.client.history;

import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;

/**
* JRE-safe class that wraps GWT's {@link com.google.gwt.user.client.History} class, allowing non-GWT testing of code that uses gwt's History mechanism.
*
* @author David Mason, damason@redhat.com
*
*/
public interface History
{
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler);

public void back();

public void fireCurrentHistoryState();

public void forward();

public String getToken();

public void newItem(String historyToken);

public void newItem(String historyToken, boolean issueEvent);
}
@@ -0,0 +1,57 @@
package org.zanata.webtrans.client.history;

import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerRegistration;

//TODO inject this

/**
* @author David Mason, damason@redhat.com
*
*/
public class HistoryImpl implements History
{

@Override
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler)
{
return com.google.gwt.user.client.History.addValueChangeHandler(handler);
}

@Override
public void back()
{
com.google.gwt.user.client.History.back();
}

@Override
public void fireCurrentHistoryState()
{
com.google.gwt.user.client.History.fireCurrentHistoryState();
}

@Override
public void forward()
{
com.google.gwt.user.client.History.forward();
}

@Override
public String getToken()
{
return com.google.gwt.user.client.History.getToken();
}

@Override
public void newItem(String historyToken)
{
com.google.gwt.user.client.History.newItem(historyToken);
}

@Override
public void newItem(String historyToken, boolean issueEvent)
{
com.google.gwt.user.client.History.newItem(historyToken, issueEvent);
}

}
Expand Up @@ -18,14 +18,12 @@ public class HistoryToken
public static final String KEY_DOCUMENT = "doc";

public static final String KEY_VIEW = "view";
// public static final String VALUE_DOCLIST_VIEW = "list";
public static final String VALUE_EDITOR_VIEW = "doc";

public static final String KEY_DOC_FILTER_TEXT = "filter";

public static final String KEY_DOC_FILTER_OPTION = "filtertype";
public static final String VALUE_DOC_FILTER_EXACT = "exact";
// public static final String VALUE_DOC_FILTER_INEXACT = "substr";

private AppPresenter.Display.MainView view;
private String fullDocPath;
Expand Down Expand Up @@ -75,25 +73,27 @@ public static HistoryToken fromTokenString(String token)
continue;
}

if (key == HistoryToken.KEY_DOCUMENT)
if (key.equals(HistoryToken.KEY_DOCUMENT))
{
historyToken.setDocumentPath(value);
}
else if (key == HistoryToken.KEY_VIEW)
else if (key.equals(HistoryToken.KEY_VIEW))
{
if (value.equals(VALUE_EDITOR_VIEW))
{
historyToken.setView(AppPresenter.Display.MainView.Editor);
}
// else default will be used
}
else if (key == HistoryToken.KEY_DOC_FILTER_OPTION)
else if (key.equals(KEY_DOC_FILTER_OPTION))
{
if (value == VALUE_DOC_FILTER_EXACT)
if (value.equals(VALUE_DOC_FILTER_EXACT))
{
historyToken.setDocFilterExact(true);
}
// else default used
}
else if (key == HistoryToken.KEY_DOC_FILTER_TEXT)
else if (key.equals(HistoryToken.KEY_DOC_FILTER_TEXT))
{
historyToken.setDocFilterText(value);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public void setView(AppPresenter.Display.MainView view)
this.view = view;
}

public Boolean getDocFilterExact()
public boolean getDocFilterExact()
{
return docFilterExact;
}
Expand Down
@@ -0,0 +1,26 @@
/**
*
*/
package org.zanata.webtrans.client.history;

import java.util.List;
import java.util.Map;

/**
* Wraps calls to the {@link com.google.gwt.user.client.Window.Location} object
* to allow mocking for testing in a JRE (non-GWT) environment.
*
* Does not implement all Window.Location methods.
*
* @author David Mason, damason@redhat.com
*
*/
public interface WindowLocation
{
public String getParameter(String name);

public Map<String, List<String>> getParameterMap();

public String getHref();

}
@@ -0,0 +1,28 @@
package org.zanata.webtrans.client.history;

import java.util.List;
import java.util.Map;
import com.google.gwt.user.client.Window;

public class WindowLocationImpl implements WindowLocation
{

@Override
public String getParameter(String name)
{
return Window.Location.getParameter(name);
}

@Override
public Map<String, List<String>> getParameterMap()
{
return Window.Location.getParameterMap();
}

@Override
public String getHref()
{
return Window.Location.getHref();
}

}
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,17 +58,13 @@
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.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
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;
import com.google.gwt.view.client.ListDataProvider;
import com.google.inject.Inject;

public class DocumentListPresenter extends WidgetPresenter<DocumentListPresenter.Display> implements HasDocumentSelectionHandlers
public class DocumentListPresenter extends WidgetPresenter<DocumentListPresenter.Display>
{

public interface Display extends WidgetDisplay
Expand All @@ -89,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 @@ -108,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 @@ -131,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 @@ -150,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 @@ -175,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 @@ -189,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 @@ -324,23 +326,11 @@ public void onRevealDisplay()
// TODO Auto-generated method stub
}

@Override
public HandlerRegistration addDocumentSelectionHandler(DocumentSelectionHandler handler)
{
return eventBus.addHandler(DocumentSelectionEvent.getType(), handler);
}

@Override
public void fireEvent(GwtEvent<?> event)
{
eventBus.fireEvent(event);
}

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 @@ -365,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 1426487

Please sign in to comment.