user-statistics/src/main/java/org/gcube/portlet/user/userstatisticsportlet/client/ui/ActivityWidget.java

170 lines
4.2 KiB
Java
Raw Normal View History

package org.gcube.portlet.user.userstatisticsportlet.client.ui;
import org.gcube.portal.databook.shared.ShowUserStatisticAction;
import org.gcube.portlet.user.userstatisticsportlet.client.events.ShowFeedsRelatedToUserStatisticsEvent;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
public class ActivityWidget extends Composite {
private static CommentsAndLikesWidgetUiBinder uiBinder = GWT
.create(CommentsAndLikesWidgetUiBinder.class);
interface CommentsAndLikesWidgetUiBinder extends
UiBinder<Widget, ActivityWidget> {
}
@UiField
Image likesImage;
@UiField
Image commentsImage;
@UiField
Image postsImage;
@UiField
Label likesValue;
@UiField
Label commentsValue;
@UiField
Label postsValue;
private HandlerManager busEvents;
public ActivityWidget() {
initWidget(uiBinder.createAndBindUi(this));
}
/**
* Set comments information
* @param url
* @param value
* @param tipIcon
* @param tipValue
* @param actionToTakeOnClick
* @param landingPage
*/
public void setComments(String url, String value, String tipIcon, String tipValue, final ShowUserStatisticAction actionToTakeOnClick, final String landingPage){
commentsImage.setUrl(url);
commentsImage.setTitle(tipIcon);
commentsValue.setText(value);
commentsValue.setTitle(tipValue);
if(busEvents != null && actionToTakeOnClick != null){
commentsValue.getElement().getStyle().setCursor(Cursor.POINTER);
commentsValue.addStyleName("statistic-value-underline");
commentsValue.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
busEvents.fireEvent(new ShowFeedsRelatedToUserStatisticsEvent(actionToTakeOnClick, landingPage));
}
});
}
// set to visible
commentsValue.setVisible(true);
commentsImage.setVisible(true);
}
/**
* Set likes information
* @param url
* @param value
* @param tipIcon
* @param tipValue
* @param actionToTakeOnClick
* @param landingPage
*/
public void setLikes(String url, String value, String tipIcon, String tipValue, final ShowUserStatisticAction actionToTakeOnClick, final String landingPage){
likesImage.setUrl(url);
likesImage.setTitle(tipIcon);
likesValue.setText(value);
likesValue.setTitle(tipValue);
if(busEvents != null && actionToTakeOnClick != null){
likesValue.getElement().getStyle().setCursor(Cursor.POINTER);
likesValue.addStyleName("statistic-value-underline");
likesValue.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
busEvents.fireEvent(new ShowFeedsRelatedToUserStatisticsEvent(actionToTakeOnClick, landingPage));
}
});
}
// set to visible
likesValue.setVisible(true);
likesImage.setVisible(true);
}
/**
* Set posts information
* @param url
* @param value
* @param tipIcon
* @param tipValue
* @param actionToTakeOnClick
* @param landingPage
*/
public void setPosts(String url, String value, String tipIcon, String tipValue, final ShowUserStatisticAction actionToTakeOnClick, final String landingPage){
postsImage.setUrl(url);
postsImage.setTitle(tipIcon);
postsValue.setText(value);
postsValue.setTitle(tipValue);
if(busEvents != null && actionToTakeOnClick != null){
postsValue.getElement().getStyle().setCursor(Cursor.POINTER);
postsValue.addStyleName("statistic-value-underline");
postsValue.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
busEvents.fireEvent(new ShowFeedsRelatedToUserStatisticsEvent(actionToTakeOnClick, landingPage));
}
});
}
// set to visible
postsValue.setVisible(true);
postsImage.setVisible(true);
}
/**
* Set the event bus to let this widget fire events
* @param busEvents
*/
public void setEventBus(HandlerManager busEvents){
this.busEvents = busEvents;
}
}