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

Commit

Permalink
rhbz978666 - add comment indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Jul 12, 2013
1 parent 65bd09c commit 3fbc6ad
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 26 deletions.
@@ -0,0 +1,52 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.events;

import org.zanata.webtrans.shared.model.TransUnitId;
import com.google.gwt.event.shared.GwtEvent;

public class ReviewCommentEvent extends GwtEvent<ReviewCommentEventHandler>
{
public static Type<ReviewCommentEventHandler> TYPE = new Type<ReviewCommentEventHandler>();

private TransUnitId transUnitId;

public ReviewCommentEvent(TransUnitId transUnitId)
{
this.transUnitId = transUnitId;
}

public TransUnitId getTransUnitId()
{
return transUnitId;
}

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

protected void dispatch(ReviewCommentEventHandler handler)
{
handler.onShowReviewComment(this);
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface ReviewCommentEventHandler extends EventHandler
{
void onShowReviewComment(ReviewCommentEvent event);
}
Expand Up @@ -21,16 +21,16 @@

package org.zanata.webtrans.client.presenter;

import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.events.ReviewCommentEventHandler;
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.view.ReviewCommentDisplay;
import org.zanata.webtrans.shared.model.ReviewComment;
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.google.gwt.view.client.ListDataProvider;
import com.google.inject.Inject;
import com.google.inject.Singleton;

Expand All @@ -41,7 +41,7 @@
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class ReviewCommentPresenter extends WidgetPresenter<ReviewCommentDisplay> implements ReviewCommentDisplay.Listener
public class ReviewCommentPresenter extends WidgetPresenter<ReviewCommentDisplay> implements ReviewCommentDisplay.Listener, ReviewCommentEventHandler
{
private final ReviewCommentDisplay display;
private final CachingDispatchAsync dispatcher;
Expand All @@ -63,11 +63,13 @@ public ReviewCommentPresenter(ReviewCommentDisplay display, EventBus eventBus, C
@Override
protected void onBind()
{
eventBus.addHandler(ReviewCommentEvent.TYPE, this);
}

public void displayCommentView(TransUnitId transUnitId)
@Override
public void onShowReviewComment(ReviewCommentEvent event)
{
this.transUnitId = transUnitId;
this.transUnitId = event.getTransUnitId();
dataProvider.setLoading(true);
dispatcher.execute(new GetReviewCommentsAction(transUnitId), new AbstractAsyncCallback<GetReviewCommentsResult>()
{
Expand Down
Expand Up @@ -148,6 +148,7 @@ private void bindEventHandlers()
eventBus.addHandler(CopyDataToEditorEvent.getType(), this);
eventBus.addHandler(TransUnitEditEvent.getType(), this);
eventBus.addHandler(WorkspaceContextUpdateEvent.getType(), this);
reviewCommentPresenter.bind();
}

public void savePendingChangesIfApplicable()
Expand Down Expand Up @@ -683,13 +684,6 @@ public void rejectTranslation(TransUnitId id)
saveCurrent(ContentState.Rejected);
}

@Override
public void commentTranslation(TransUnitId id)
{
ensureRowSelection(id);
reviewCommentPresenter.displayCommentView(id);
}

/**
* For testing only
* @param currentTransUnitId current trans unit id
Expand Down
@@ -1,9 +1,9 @@
package org.zanata.webtrans.client.ui;

import org.zanata.common.ContentState;
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.view.TargetContentsDisplay;
import org.zanata.webtrans.shared.model.TransUnitId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.resources.client.CssResource;
Expand All @@ -15,9 +15,12 @@
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.SimplePanel;

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

public class EditorButtonsWidget extends Composite
{
private static EditorButtonsWidgetUiBinder ourUiBinder = GWT.create(EditorButtonsWidgetUiBinder.class);
private final EventBus eventBus;

@UiField
HTMLPanel buttons;
Expand All @@ -43,8 +46,9 @@ public class EditorButtonsWidget extends Composite
private TargetContentsDisplay.Listener listener;
private TransUnitId id;

public EditorButtonsWidget()
public EditorButtonsWidget(EventBus eventBus)
{
this.eventBus = eventBus;
initWidget(ourUiBinder.createAndBindUi(this));
displayReviewButtons(listener != null && listener.canReviewTranslation());
}
Expand Down Expand Up @@ -120,8 +124,7 @@ public void onReject(ClickEvent event)
@UiHandler("commentIcon")
public void onCommentClick(ClickEvent event)
{
listener.commentTranslation(id);
event.stopPropagation();
eventBus.fireEvent(new ReviewCommentEvent(id));
}

public void setListener(TargetContentsDisplay.Listener listener)
Expand Down
Expand Up @@ -102,7 +102,6 @@ interface Listener

void rejectTranslation(TransUnitId id);

void commentTranslation(TransUnitId id);
}

enum EditingState
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.List;

import org.zanata.common.ContentState;
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.resources.TableEditorMessages;
import org.zanata.webtrans.client.ui.Editor;
import org.zanata.webtrans.client.ui.EditorButtonsWidget;
Expand All @@ -37,9 +38,11 @@
import com.google.common.base.Objects;
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.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
Expand All @@ -48,10 +51,13 @@
import com.google.inject.Inject;
import com.google.inject.Provider;

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

public class TargetContentsView extends Composite implements TargetContentsDisplay
{
private static final int COLUMNS = 1;
private static Binder binder = GWT.create(Binder.class);
private final EventBus eventBus;

@UiField
Grid editorGrid;
Expand All @@ -64,7 +70,7 @@ public class TargetContentsView extends Composite implements TargetContentsDispl

@UiField
Label savingIndicator;
@UiField
@UiField(provided = true)
EditorButtonsWidget buttons;
@UiField
Label commentIndicator;
Expand All @@ -77,8 +83,10 @@ public class TargetContentsView extends Composite implements TargetContentsDispl
private TransUnit cachedValue;

@Inject
public TargetContentsView(Provider<ValidationMessagePanelView> validationMessagePanelViewProvider)
public TargetContentsView(Provider<ValidationMessagePanelView> validationMessagePanelViewProvider, EventBus eventBus)
{
this.eventBus = eventBus;
buttons = new EditorButtonsWidget(eventBus);
validationPanel = validationMessagePanelViewProvider.get();
rootPanel = binder.createAndBindUi(this);
editorGrid.addStyleName("TableEditorCell-Target-Table");
Expand All @@ -87,6 +95,12 @@ public TargetContentsView(Provider<ValidationMessagePanelView> validationMessage
editors = Lists.newArrayList();
}

@UiHandler("commentIndicator")
public void commentIndicatorClicked(ClickEvent event)
{
eventBus.fireEvent(new ReviewCommentEvent(getId()));
}

@Override
public void showButtons(boolean displayButtons)
{
Expand Down
Expand Up @@ -33,16 +33,19 @@
background-color: #ff4500;
}

.commentCount {
.commentIndicator {
position: absolute;
top: 8px;
right: 30px;
right: 5px;
font-size: smaller;
color: #ffffff;
z-index: 1;
background-color: #ff4500;
border-radius: 3px;
background-color: #ff0000;
border-radius: 10px;
border: thick double #ffffff;
padding-left: 2px;
padding-right: 2px;
box-shadow: 2px 2px 2px #888;
cursor: pointer;
}

</ui:style>
Expand All @@ -51,7 +54,7 @@
<g:cell verticalAlignment="ALIGN_TOP">
<g:FlowPanel styleName="{style.editorGridWrapper}">
<g:Label ui:field="savingIndicator" text="{messages.saving}" styleName="icon-progress {style.saving}" visible="false"/>
<g:Label ui:field="commentIndicator" styleName="{style.commentCount}" visible="false"/>
<g:Label ui:field="commentIndicator" styleName="{style.commentIndicator}" visible="false"/>
<g:Grid ui:field="editorGrid" />
<fui:ValidationMessagePanelView ui:field="validationPanel"/>
</g:FlowPanel>
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.webtrans.client.events.ReviewCommentEvent;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.view.ReviewCommentDisplay;
import org.zanata.webtrans.shared.model.ReviewComment;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void testDisplayCommentView() throws Exception
ArgumentCaptor<GetReviewCommentsAction> actionCaptor = ArgumentCaptor.forClass(GetReviewCommentsAction.class);
ArgumentCaptor<AsyncCallback> resultCaptor = ArgumentCaptor.forClass(AsyncCallback.class);

presenter.displayCommentView(transUnitId);
presenter.onShowReviewComment(new ReviewCommentEvent(transUnitId));

verify(dataProvider).setLoading(true);
verify(dispather).execute(actionCaptor.capture(), resultCaptor.capture());
Expand Down

0 comments on commit 3fbc6ad

Please sign in to comment.