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.dom.client.Style.Unit; 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.Anchor; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; /** * Class to show an attached file. * @author Costantino Perciante at ISTI-CNR * */ public class AttachmentPreviewer extends Composite { private static AttachmentPreviewerUiBinder uiBinder = GWT .create(AttachmentPreviewerUiBinder.class); interface AttachmentPreviewerUiBinder extends UiBinder { } public AttachmentPreviewer() { initWidget(uiBinder.createAndBindUi(this)); } @UiField HTMLPanel attachmentContainer; @UiField Image imagePreview; @UiField Label fileNameLabel; @UiField Anchor downloadLabel; @UiField Anchor showPreviewLabel; // save attachment private Attachment attachment; public AttachmentPreviewer(Attachment a) { // init initWidget(uiBinder.createAndBindUi(this)); // save the attachment attachment = a; // set image preview imagePreview.setUrl(a.getThumbnailURL()); // set file name (be careful on file name length) String shownName = a.getName().length() > 21 ? a.getName().substring(0, 18) + "..." : a.getName(); fileNameLabel.setText(shownName); fileNameLabel.setTitle(a.getName()); // download label downloadLabel.setText("Download"); downloadLabel.setHref(attachment.getUri()); downloadLabel.setTarget("_blank"); // preview TODO showPreviewLabel.setText("Show"); showPreviewLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { Window.alert("Image preview widget will be made soon..."); } }); // style links downloadLabel.addStyleName("link"); showPreviewLabel.addStyleName("link"); } /** * Change the width of this container. * @param newWidth * @param unit */ public void changeAttachmentWidth(int newWidth, Unit unit){ attachmentContainer.getElement().getStyle().setWidth(newWidth, unit); } }