73 lines
1.8 KiB
Java
73 lines
1.8 KiB
Java
package org.gcube.portlets.user.newsfeed.client.ui;
|
|
|
|
import org.gcube.portal.databook.shared.Attachment;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
import com.google.gwt.uibinder.client.UiBinder;
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
import com.google.gwt.user.client.Window;
|
|
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;
|
|
|
|
/**
|
|
* Shows an attachment
|
|
* @author Costantino Perciante at ISTI-CNR
|
|
*
|
|
*/
|
|
public class AttachmentPreviewer extends Composite{
|
|
|
|
private static AttachmentPreviewerUiBinder uiBinder = GWT
|
|
.create(AttachmentPreviewerUiBinder.class);
|
|
|
|
interface AttachmentPreviewerUiBinder extends
|
|
UiBinder<Widget, AttachmentPreviewer> {
|
|
}
|
|
|
|
public AttachmentPreviewer() {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
}
|
|
|
|
@UiField
|
|
Image attachmentPreviewImage;
|
|
|
|
@UiField
|
|
Label attachmentFileName;
|
|
|
|
// save the attachment
|
|
private Attachment attachment;
|
|
|
|
public AttachmentPreviewer(final Attachment attachment) {
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
// print attachment
|
|
printJSLOG(attachment.toString());
|
|
|
|
// save it
|
|
this.attachment = attachment;
|
|
|
|
// set label
|
|
attachmentFileName.setText(attachment.getName());
|
|
|
|
// set thumbnail
|
|
if(attachment.getThumbnailURL() != null)
|
|
attachmentPreviewImage.setUrl(attachment.getThumbnailURL());
|
|
|
|
attachmentPreviewImage.addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
Window.open(attachment.getUri(), "_parent", "");
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
private static native void printJSLOG(String msg)/*-{
|
|
console.log(msg);
|
|
}-*/;
|
|
}
|