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

121 lines
3.9 KiB
Java

package org.gcube.portlets.user.notifications.client.view.templates;
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 final static String LINK_TEXT = "likes your post: shared a link. ";
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 Span notificationText;
@UiField Span timeArea;
@UiField Span goApp;
public SingleNotificationView(Notification toShow) {
initWidget(uiBinder.createAndBindUi(this));
myNotification = toShow;
String notificationToShow = toShow.getDescription();
String removeMarkup = notificationToShow.replaceAll("&amp;", "&");
String actualHTML = new HTML(removeMarkup).getText();
//in case of links behave differently, i know is terrible //TODO: write better code here i think
if (new HTML(actualHTML).getText().equalsIgnoreCase(LINK_TEXT)) {
GWT.log("E' UN LINK!");
actualHTML = actualHTML.replace("your post:", "");
actualHTML = actualHTML.replace("shared", "");
actualHTML = actualHTML.replace("link.", "link");
actualHTML += " you shared.";
}
notificationText.setHTML(
"<a class=\"link\" href=\""+GCubeSocialNetworking.USER_PROFILE_LINK+"\">"+
toShow.getSenderFullName()+"</a> " + actualHTML);
timeArea.setHTML(DateTimeFormat.getFormat("h:mm a").format(toShow.getTime()));
notificationImage.setResource(getImageType(toShow.getType()));
switch (toShow.getType()) {
case DOCUMENT_WORKFLOW_STEP_REQUEST_TASK:
goApp.setHTML("<a class=\"link\" href=\""+toShow.getUri()+"\"> See this Document Workflow.</a>");
case DOCUMENT_WORKFLOW_VIEW:
goApp.setHTML("<a class=\"link\" href=\""+toShow.getUri()+"\"> See User Activity.</a>");
case DOCUMENT_WORKFLOW_EDIT:
goApp.setHTML("<a class=\"link\" href=\""+toShow.getUri()+"\"> See User Activity.</a>");
}
}
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();
case DOCUMENT_WORKFLOW_EDIT:
return images.documentWorkflow();
case DOCUMENT_WORKFLOW_VIEW:
return images.documentWorkflow();
case DOCUMENT_WORKFLOW_STEP_REQUEST_TASK:
return images.documentWorkflow();
case DOCUMENT_WORKFLOW_STEP_FORWARD_OWNER:
return images.workflowForward();
case DOCUMENT_WORKFLOW_STEP_FORWARD_PEER:
return images.workflowForward();
default:
return images.generic();
}
}
}