new panel for attachments added but it has to be finished

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@122327 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-19 17:43:15 +00:00
parent f663bfe58b
commit a028ef42fa
5 changed files with 111 additions and 11 deletions

View File

@ -0,0 +1,72 @@
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);
}-*/;
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:AbsolutePanel>
<g:Label ui:field="attachmentFileName"></g:Label>
<g:Image ui:field="attachmentPreviewImage">
</g:Image>
</g:AbsolutePanel>
</ui:UiBinder>

View File

@ -36,6 +36,7 @@ import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
@ -44,7 +45,8 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* @author Massimiliano Assante. ISTI-CNR
* @author Massimiliano Assante at ISTI-CNR
* @author Costantino Perciante at ISTI-CNR
*
*/
public class TweetTemplate extends Composite {
@ -111,6 +113,8 @@ public class TweetTemplate extends Composite {
@UiField
VerticalPanel previewPanel;
@UiField
FlowPanel attachmentPreviewPanel;
@UiField
Label messageSeparator;
/**
* used when fetching tweets from server
@ -128,7 +132,9 @@ public class TweetTemplate extends Composite {
this.myFeed = myFeed;
isAppFeed = myFeed.getFeed().isApplicationFeed();
Feed feed = myFeed.getFeed();
if (feed.getUri() != null && feed.getUri().compareTo("") != 0 && feed.getLinkTitle() != null && feed.getLinkTitle().compareTo("") != 0 ) {
// if there is one attachment, maintain retro compatibility
if (feed.getUri() != null && feed.getUri().compareTo("") != 0 && feed.getLinkTitle() != null && feed.getLinkTitle().compareTo("") != 0 && !feed.isMultiFileUpload()) {
previewPanel.add(new LinkPreviewer(feed.getLinkTitle(), feed.getLinkDescription(), feed.getLinkHost(), feed.getUriThumbnail(), feed.getUri()));
}
this.eventBus = eventBus;
@ -141,12 +147,27 @@ public class TweetTemplate extends Composite {
} else {
closeImage.removeFromParent();
}
// in case there are attachments, we have to fill attachmentPreviewPanel instead of the previewPanel
if(myFeed.getAttachments() != null){
GWT.log("# attachments: "+myFeed.getAttachments().size());
if (myFeed.getAttachments().size() > 0) {
for (Attachment a : myFeed.getAttachments()) {
GWT.log(a.toString());
}
// remember that one attachment is stored in the fields: uri, uriThumbnail, linkTitle, linkDescription, linkHost
// build up an attachment
Attachment firstAttachment = new Attachment(
feed.getKey(), // it is meaningless but it's needed
feed.getUri(),
feed.getLinkTitle(),
feed.getLinkDescription(),
feed.getUriThumbnail(),
feed.getLinkHost());
// add it to the panel
attachmentPreviewPanel.add(new AttachmentPreviewer(firstAttachment));
for (Attachment a : myFeed.getAttachments()) {
attachmentPreviewPanel.add(new AttachmentPreviewer(a));
}
}

View File

@ -16,6 +16,7 @@
<g:HTML styleName="" ui:field="seeMore" />
</div>
<g:VerticalPanel ui:field="previewPanel"></g:VerticalPanel>
<g:FlowPanel ui:field="attachmentPreviewPanel"></g:FlowPanel>
<div class="tweet-actions">
<table cellspacing="0" cellpadding="0">
<tbody>

View File

@ -124,7 +124,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*/
public String getDevelopmentUser() {
String user = NewsConstants.TEST_USER;
// user = "andrea.rossi";
// user = "costantino.perciante";
return user;
}
/**
@ -211,9 +211,6 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
}
}
@Override
public ArrayList<EnhancedFeed> getAllUpdateUserFeeds(int feedsNoPerCategory) {
String userName = getASLSession().getUsername();