notifications/src/main/java/org/gcube/portlets/user/notifications/client/view/templates/SingleNotificationView.java

89 lines
2.6 KiB
Java

package org.gcube.portlets.user.notifications.client.view.templates;
import java.util.Date;
import com.google.gwt.user.datepicker.client.CalendarUtil;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portlets.user.notifications.client.view.templates.images.NotificationImages;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.ImageResource;
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.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
public class SingleNotificationView extends Composite {
private static NotificationsDayUiBinder uiBinder = GWT
.create(NotificationsDayUiBinder.class);
interface NotificationsDayUiBinder extends
UiBinder<Widget, SingleNotificationView> {
}
NotificationImages images = GWT.create(NotificationImages.class);
private Notification myNotification;
@UiField
Image notificationImage;
@UiField HTMLPanel mainPanel;
@UiField HTML notificationText;
@UiField HTML timeArea;
public SingleNotificationView(Notification toShow) {
initWidget(uiBinder.createAndBindUi(this));
myNotification = toShow;
String notificationToShow = toShow.getDescription();
notificationText.setHTML(
"<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"\">"+
toShow.getSenderFullName()+"</a> " + notificationToShow);
timeArea.setHTML(DateTimeFormat.getFormat("h:mm a").format(toShow.getTime()));
notificationImage.setResource(getImageType(toShow.getType()));
}
private ImageResource getImageType(NotificationType type) {
switch (type) {
case LIKE:
return images.like();
case COMMENT:
return images.comment();
case MESSAGE:
return images.message();
case WP_FOLDER_ADDEDUSER:
return images.share();
case WP_FOLDER_REMOVEDUSER:
return images.share();
case WP_FOLDER_SHARE:
return images.share();
case WP_ITEM_NEW:
return images.share();
case WP_ITEM_DELETE:
return images.share();
case WP_ITEM_UPDATED:
return images.share();
case OWN_COMMENT:
return images.comment();
case REQUEST_CONNECTION:
return images.connectionRequest();
case JOB_COMPLETED_NOK:
return images.jobNOK();
case JOB_COMPLETED_OK:
return images.jobOK();
default:
return images.generic();
}
}
}