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

Commit

Permalink
rhbz978666 - style comments made against old translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jul 12, 2013
1 parent bad1cdb commit a02e784
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
Expand Up @@ -26,12 +26,15 @@
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder;
import org.zanata.webtrans.client.service.NavigationService;
import org.zanata.webtrans.client.view.ReviewCommentDisplay;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
import org.zanata.webtrans.shared.rpc.AddReviewCommentAction;
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import org.zanata.webtrans.shared.rpc.GetReviewCommentsAction;
import org.zanata.webtrans.shared.rpc.GetReviewCommentsResult;
import com.allen_sauer.gwt.log.client.Log;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand All @@ -48,16 +51,18 @@ public class ReviewCommentPresenter extends WidgetPresenter<ReviewCommentDisplay
private final CachingDispatchAsync dispatcher;
private final ReviewCommentDataProvider dataProvider;
private final GetTransUnitActionContextHolder contextHolder;
private final NavigationService navigationService;
private TransUnitId transUnitId;

@Inject
public ReviewCommentPresenter(ReviewCommentDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, ReviewCommentDataProvider dataProvider, GetTransUnitActionContextHolder contextHolder)
public ReviewCommentPresenter(ReviewCommentDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, ReviewCommentDataProvider dataProvider, GetTransUnitActionContextHolder contextHolder, NavigationService navigationService)
{
super(display, eventBus);
this.display = display;
this.dispatcher = dispatcher;
this.dataProvider = dataProvider;
this.contextHolder = contextHolder;
this.navigationService = navigationService;

display.setListener(this);
display.setDataProvider(dataProvider);
Expand All @@ -73,6 +78,8 @@ protected void onBind()
public void onShowReviewComment(ReviewCommentEvent event)
{
this.transUnitId = event.getTransUnitId();
Integer currentTargetVersion = navigationService.getByIdOrNull(transUnitId).getVerNum();
display.setCurrentTargetVersion(currentTargetVersion);
dataProvider.setLoading(true);
dispatcher.execute(new GetReviewCommentsAction(transUnitId), new AbstractAsyncCallback<GetReviewCommentsResult>()
{
Expand Down
Expand Up @@ -48,6 +48,8 @@ public Object getKey(ReviewComment item)

void clearInput();

void setCurrentTargetVersion(Integer targetVersion);

interface Listener
{
void addComment(String comment);
Expand Down
Expand Up @@ -26,11 +26,14 @@
import org.zanata.webtrans.client.ui.DialogBoxCloseButton;
import org.zanata.webtrans.client.util.DateUtil;
import org.zanata.webtrans.shared.model.ReviewComment;
import com.google.common.base.Objects;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
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.user.cellview.client.CellTable;
Expand Down Expand Up @@ -62,10 +65,13 @@ public class ReviewCommentView extends DialogBox implements ReviewCommentDisplay
WebTransMessages messages;
@UiField
VerticalPanel commentsContainer;
@UiField
Styles style;

private final CellTable<ReviewComment> commentTable;
private Listener listener;
private TextBox commentInputBox;
private Integer currentTargetVersion;

public ReviewCommentView()
{
Expand All @@ -91,8 +97,7 @@ private Widget createCommentInput()
FlowPanel panel = new FlowPanel();
commentInputBox = new TextBox();
panel.add(commentInputBox);
// TODO pahuang localize
Button addButton = new Button("Add", new ClickHandler()
Button addButton = new Button(messages.reviewComment(), new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
Expand Down Expand Up @@ -126,7 +131,7 @@ private CellTable<ReviewComment> setUpTable()
return table;
}

private static Column<ReviewComment, String> createCommentColumn()
private Column<ReviewComment, String> createCommentColumn()
{
return new Column<ReviewComment, String>(new TextCell())
{
Expand All @@ -135,6 +140,16 @@ public String getValue(ReviewComment object)
{
return object.getComment();
}

@Override
public String getCellStyleNames(Cell.Context context, ReviewComment object)
{
if (!Objects.equal(object.getTargetVersion(), currentTargetVersion))
{
return style.obsoleteComment();
}
return super.getCellStyleNames(context, object);
}
};
}

Expand Down Expand Up @@ -168,6 +183,12 @@ public void clearInput()
commentInputBox.setText("");
}

@Override
public void setCurrentTargetVersion(Integer targetVersion)
{
this.currentTargetVersion = targetVersion;
}

@Override
public void setDataProvider(ListDataProvider<ReviewComment> dataProvider)
{
Expand All @@ -183,4 +204,10 @@ public void setListener(Listener listener)
interface AddReviewCommentViewUiBinder extends UiBinder<HTMLPanel, ReviewCommentView>
{
}

interface Styles extends CssResource
{

String obsoleteComment();
}
}
Expand Up @@ -23,6 +23,13 @@
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:z='urn:import:org.zanata.webtrans.client.ui'>
<ui:with field="messages" type="org.zanata.webtrans.client.resources.WebTransMessages"/>
<ui:style field="style" type="org.zanata.webtrans.client.view.ReviewCommentView.Styles">
.obsoleteComment
{
font-style: italic;
text-decoration: line-through;
}
</ui:style>

<g:HTMLPanel width="800px" height="600px">
<g:ScrollPanel>
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder;
import org.zanata.webtrans.client.service.NavigationService;
import org.zanata.webtrans.client.view.ReviewCommentDisplay;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.ReviewComment;
Expand Down Expand Up @@ -67,27 +68,33 @@ public class ReviewCommentPresenterTest
private ReviewCommentDataProvider dataProvider;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private GetTransUnitActionContextHolder contextHolder;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NavigationService navigationService;


@BeforeMethod
public void beforeMethod()
{
MockitoAnnotations.initMocks(this);

presenter = new ReviewCommentPresenter(display, eventBus, dispather, dataProvider, contextHolder);
presenter = new ReviewCommentPresenter(display, eventBus, dispather, dataProvider, contextHolder, navigationService);

verify(display).setDataProvider(dataProvider);
verify(display).setListener(presenter);
}
@Test
public void testDisplayCommentView() throws Exception
{
// Given: trans unit id 1 and current target version 99
TransUnitId transUnitId = new TransUnitId(1L);
when(navigationService.getByIdOrNull(transUnitId).getVerNum()).thenReturn(99);
ArgumentCaptor<GetReviewCommentsAction> actionCaptor = ArgumentCaptor.forClass(GetReviewCommentsAction.class);
ArgumentCaptor<AsyncCallback> resultCaptor = ArgumentCaptor.forClass(AsyncCallback.class);

// When:
presenter.onShowReviewComment(new ReviewCommentEvent(transUnitId));

// Then:
verify(dataProvider).setLoading(true);
verify(dispather).execute(actionCaptor.capture(), resultCaptor.capture());
assertThat(actionCaptor.getValue().getTransUnitId(), Matchers.equalTo(transUnitId));
Expand All @@ -96,6 +103,7 @@ public void testDisplayCommentView() throws Exception
GetReviewCommentsResult result = new GetReviewCommentsResult(Lists.newArrayList(new ReviewComment()));
callback.onSuccess(result);

verify(display).setCurrentTargetVersion(99);
verify(dataProvider).setLoading(false);
verify(dataProvider).setList(result.getComments());
}
Expand Down

0 comments on commit a02e784

Please sign in to comment.