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

Commit

Permalink
rhbz996398 - disable editor shortcut when history popup shows
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Sep 5, 2013
1 parent db31b95 commit ea5296d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
Expand Up @@ -4,13 +4,11 @@
import java.util.Date;
import java.util.List;

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

import org.zanata.webtrans.client.events.CopyDataToEditorEvent;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.events.ReviewCommentEventHandler;
import org.zanata.webtrans.client.keys.ShortcutContext;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
Expand All @@ -24,14 +22,16 @@
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryAction;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;
import com.google.inject.Singleton;

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

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
Expand All @@ -44,19 +44,21 @@ public class TranslationHistoryPresenter extends WidgetPresenter<TranslationHist
private final CachingDispatchAsync dispatcher;
private final WebTransMessages messages;
private final GetTransUnitActionContextHolder contextHolder;
private final KeyShortcutPresenter keyShortcutPresenter;
private TargetContentsPresenter targetContentsPresenter;
private TransUnitId transUnitId;
private ComparingPair comparingPair = ComparingPair.empty();

@Inject
public TranslationHistoryPresenter(TranslationHistoryDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, WebTransMessages messages, GetTransUnitActionContextHolder contextHolder)
public TranslationHistoryPresenter(TranslationHistoryDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, WebTransMessages messages, GetTransUnitActionContextHolder contextHolder, KeyShortcutPresenter keyShortcutPresenter)
{
super(display, eventBus);
this.display = display;
this.eventBus = eventBus;
this.dispatcher = dispatcher;
this.messages = messages;
this.contextHolder = contextHolder;
this.keyShortcutPresenter = keyShortcutPresenter;

display.setListener(this);
eventBus.addHandler(ReviewCommentEvent.TYPE, this);
Expand All @@ -80,6 +82,7 @@ public void onFailure(Throwable caught)
Log.error("failure getting translation history", caught);
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Error, caught.getMessage()));
display.hide();
disableShortcut();
}

@Override
Expand All @@ -97,6 +100,7 @@ protected void popupAndShowLoading(String title)
display.setTitle(title);
display.resetView();
display.center();
enableShortcut();
}

protected void displayEntries(TransHistoryItem latest, List<TransHistoryItem> otherEntries, List<ReviewComment> reviewComments)
Expand Down Expand Up @@ -154,6 +158,19 @@ public void compareClicked(TransHistoryItem item)
}
}

private void enableShortcut()
{
keyShortcutPresenter.setContextActive(ShortcutContext.Edit, false);
keyShortcutPresenter.setContextActive(ShortcutContext.Popup, true);
}

@Override
public void disableShortcut()
{
keyShortcutPresenter.setContextActive(ShortcutContext.Edit, true);
keyShortcutPresenter.setContextActive(ShortcutContext.Popup, false);
}

@Override
public boolean isItemInComparison(TransHistoryItem item)
{
Expand Down
Expand Up @@ -42,5 +42,7 @@ interface Listener extends ForceReviewCommentDisplay.Listener
void compareClicked(TransHistoryItem item);

boolean isItemInComparison(TransHistoryItem item);

void disableShortcut();
}
}
Expand Up @@ -8,12 +8,9 @@
import org.zanata.webtrans.shared.model.TransHistoryItem;
import com.google.common.collect.Lists;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
Expand Down Expand Up @@ -69,6 +66,13 @@ public void setData(List<ComparableByDate> items)
redrawList();
}

@Override
public void hide()
{
super.hide();
listener.disableShortcut();
}

private void redrawList()
{
itemList.clear();
Expand Down
@@ -1,17 +1,8 @@
package org.zanata.webtrans.client.presenter;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Date;
import java.util.List;

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

import org.hamcrest.Matchers;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
Expand All @@ -24,6 +15,7 @@
import org.zanata.webtrans.client.events.CopyDataToEditorEvent;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.keys.ShortcutContext;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder;
Expand All @@ -38,12 +30,18 @@
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryAction;
import org.zanata.webtrans.shared.rpc.GetTranslationHistoryResult;

import com.google.common.collect.Lists;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.view.client.SelectionChangeEvent;

import net.customware.gwt.presenter.client.EventBus;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
Expand Down Expand Up @@ -72,12 +70,14 @@ public class TranslationHistoryPresenterTest
private final TransUnitId transUnitId = new TransUnitId(1L);
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private GetTransUnitActionContextHolder contextHolder;
@Mock
private KeyShortcutPresenter keyShortcutPresenter;

@BeforeMethod
public void beforeMethod()
{
MockitoAnnotations.initMocks(this);
presenter = new TranslationHistoryPresenter(display, eventBus, dispatcher, messages, contextHolder);
presenter = new TranslationHistoryPresenter(display, eventBus, dispatcher, messages, contextHolder, keyShortcutPresenter);
presenter.setCurrentValueHolder(targetContentsPresenter);

doNothing().when(dispatcher).execute(actionCaptor.capture(), resultCaptor.capture());
Expand Down Expand Up @@ -110,6 +110,8 @@ public void willNotifyErrorAndHideTranslationHistoryOnFailure()

verify(eventBus).fireEvent(isA(NotificationEvent.class));
verify(display).hide();
verify(keyShortcutPresenter).setContextActive(ShortcutContext.Edit, true);
verify(keyShortcutPresenter).setContextActive(ShortcutContext.Popup, false);
}

@Test
Expand All @@ -134,6 +136,8 @@ public void willShowTranslationHistoryOnSuccess()
AsyncCallback<GetTranslationHistoryResult> result = resultCaptor.getValue();
result.onSuccess(createTranslationHistory(latest, historyItem));
verify(display).setData(Lists.<ComparableByDate>newArrayList(latest, historyItem));
verify(keyShortcutPresenter).setContextActive(ShortcutContext.Edit, false);
verify(keyShortcutPresenter).setContextActive(ShortcutContext.Popup, true);
}

@Test
Expand Down

0 comments on commit ea5296d

Please sign in to comment.