Bug fix for multi-attachment

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@122415 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-21 13:29:46 +00:00
parent c8019b8100
commit 81a42d8866
6 changed files with 34 additions and 31 deletions

View File

@ -54,6 +54,7 @@ public class AttachmentPreviewer extends Composite {
public AttachmentPreviewer(Attachment a) { public AttachmentPreviewer(Attachment a) {
// init
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
// save the attachment // save the attachment
@ -62,8 +63,8 @@ public class AttachmentPreviewer extends Composite {
// set image preview // set image preview
imagePreview.setUrl(a.getThumbnailURL()); imagePreview.setUrl(a.getThumbnailURL());
// set file name // set file name (be careful on file name length)
String shownName = a.getName().length() > 21 ? a.getName().substring(0, 15) + "..." : a.getName(); String shownName = a.getName().length() > 21 ? a.getName().substring(0, 18) + "..." : a.getName();
fileNameLabel.setText(shownName); fileNameLabel.setText(shownName);
fileNameLabel.setTitle(a.getName()); fileNameLabel.setTitle(a.getName());
@ -72,7 +73,7 @@ public class AttachmentPreviewer extends Composite {
downloadLabel.setHref(attachment.getUri()); downloadLabel.setHref(attachment.getUri());
downloadLabel.setTarget("_blank"); downloadLabel.setTarget("_blank");
// preview // preview TODO
showPreviewLabel.setText("Show"); showPreviewLabel.setText("Show");
showPreviewLabel.addClickHandler(new ClickHandler() { showPreviewLabel.addClickHandler(new ClickHandler() {

View File

@ -24,11 +24,11 @@
border-radius: 4px; border-radius: 4px;
margin: 5px; margin: 5px;
display: inline-block; display: inline-block;
width: 95%;
} }
.label-filename-style { .label-filename-style {
overflow-x: hidden; overflow-x: hidden;
width: 100%;
margin-left: 5px; margin-left: 5px;
} }
@ -45,6 +45,7 @@
.display-inline-style { .display-inline-style {
display: inline-block; display: inline-block;
margin-right:5px;
} }
</ui:style> </ui:style>
<g:HTMLPanel styleName="{style.container-style}" ui:field="attachmentContainer"> <g:HTMLPanel styleName="{style.container-style}" ui:field="attachmentContainer">

View File

@ -16,8 +16,10 @@ import com.google.gwt.user.client.ui.WidgetCollection;
*/ */
public class Placeholder extends FlowPanel { public class Placeholder extends FlowPanel {
private static final String SHOW_OTHER_ATTACHMENTS_LABEL = "Show all";
// check if we need to show more attachments // check if we need to show more attachments
private boolean appendShowMoreLabel = false; private boolean appendShowMoreLabel;
/** /**
* Modified version of the add method. * Modified version of the add method.
@ -29,7 +31,6 @@ public class Placeholder extends FlowPanel {
// check the size // check the size
int size = listOfChildren.size(); int size = listOfChildren.size();
if(size % 2 == 0){ if(size % 2 == 0){
// in this case the next attachment we are going to add remains with the same width // in this case the next attachment we are going to add remains with the same width
add((Widget)atPrev); add((Widget)atPrev);
@ -48,6 +49,7 @@ public class Placeholder extends FlowPanel {
// ok, we are going to add the 5th attachment and so forth but we hide them.. // ok, we are going to add the 5th attachment and so forth but we hide them..
atPrev.setVisible(false); atPrev.setVisible(false);
// remember to add the button to show them later
appendShowMoreLabel = true; appendShowMoreLabel = true;
} }
} }
@ -57,14 +59,14 @@ public class Placeholder extends FlowPanel {
*/ */
public void appendShowMoreLabel(){ public void appendShowMoreLabel(){
final WidgetCollection listOfChildren = this.getChildren();
if(appendShowMoreLabel){ if(appendShowMoreLabel){
final WidgetCollection listOfChildren = this.getChildren();
final SimplePanel sp = new SimplePanel(); final SimplePanel sp = new SimplePanel();
sp.setStyleName("centered"); sp.setStyleName("centered");
final Anchor showMoreAttachments = new Anchor("Show other attachments"); final Anchor showMoreAttachments = new Anchor(SHOW_OTHER_ATTACHMENTS_LABEL);
showMoreAttachments.setStyleName("link"); showMoreAttachments.setStyleName("link");
sp.add(showMoreAttachments); sp.add(showMoreAttachments);
@ -73,7 +75,7 @@ public class Placeholder extends FlowPanel {
@Override @Override
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
// retrieve the list of attachmentPreviewers // retrieve the list of attachmentPreviewers and show them
for(Widget w: listOfChildren){ for(Widget w: listOfChildren){
w.setVisible(true); w.setVisible(true);
} }
@ -83,7 +85,7 @@ public class Placeholder extends FlowPanel {
} }
}); });
// show it // show the panel
this.add(sp); this.add(sp);
} }
} }

View File

@ -131,13 +131,6 @@ public class TweetTemplate extends Composite {
this.myFeed = myFeed; this.myFeed = myFeed;
isAppFeed = myFeed.getFeed().isApplicationFeed(); isAppFeed = myFeed.getFeed().isApplicationFeed();
Feed feed = myFeed.getFeed(); Feed feed = myFeed.getFeed();
GWT.log("Is feed multiupload? " + feed.isMultiFileUpload());
// if there is one attachment, maintain backward 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; this.eventBus = eventBus;
this.isUsers = myFeed.isUsers(); this.isUsers = myFeed.isUsers();
myComments = new ArrayList<SingleComment>(); myComments = new ArrayList<SingleComment>();
@ -149,9 +142,25 @@ public class TweetTemplate extends Composite {
closeImage.removeFromParent(); closeImage.removeFromParent();
} }
GWT.log("Is feed multiupload? " + feed.isMultiFileUpload());
// if there is one attachment, maintain backward compatibility
if (feed.getUri() != null && feed.getUri().compareTo("") != 0 && feed.getLinkTitle() != null && feed.getLinkTitle().compareTo("") != 0 && !feed.isMultiFileUpload()) {
// add link preview
previewPanel.add(new LinkPreviewer(feed.getLinkTitle(), feed.getLinkDescription(), feed.getLinkHost(), feed.getUriThumbnail(), feed.getUri()));
// hide the attachments panel
attachmentPreviewPanel.setVisible(false);
}
// in case there are attachments, we have to fill attachmentPreviewPanel instead of the previewPanel // in case there are attachments, we have to fill attachmentPreviewPanel instead of the previewPanel
if(feed.isMultiFileUpload()){ if(feed.isMultiFileUpload()){
// set style to the attachment container
attachmentPreviewPanel.setStyleName("attachment-preview-container");
// hide link preview panel
previewPanel.setVisible(false);
// remember that one attachment is stored in the fields: uri, uriThumbnail, linkTitle, linkDescription, linkHost // remember that one attachment is stored in the fields: uri, uriThumbnail, linkTitle, linkDescription, linkHost
// build up an attachment // build up an attachment
@ -166,19 +175,15 @@ public class TweetTemplate extends Composite {
// add it to the panel // add it to the panel
attachmentPreviewPanel.add(new AttachmentPreviewer(firstAttachment)); attachmentPreviewPanel.add(new AttachmentPreviewer(firstAttachment));
for (Attachment otherAttachment : myFeed.getAttachments()) { for (Attachment otherAttachment : myFeed.getAttachments()) {
// try to build the attachment viewer // try to build the attachment viewer
attachmentPreviewPanel.add(new AttachmentPreviewer(otherAttachment)); attachmentPreviewPanel.add(new AttachmentPreviewer(otherAttachment));
} }
// invoke append label // invoke append label
attachmentPreviewPanel.appendShowMoreLabel(); attachmentPreviewPanel.appendShowMoreLabel();
// set style to the attachment container
attachmentPreviewPanel.setStyleName("attachment-preview-container");
} }
openImage.setStyleName("openImage"); openImage.setStyleName("openImage");

View File

@ -124,7 +124,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
*/ */
public String getDevelopmentUser() { public String getDevelopmentUser() {
String user = NewsConstants.TEST_USER; String user = NewsConstants.TEST_USER;
// user = "costantino.perciante"; user = "costantino.perciante";
return user; return user;
} }
/** /**
@ -1054,10 +1054,4 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
return toReturn; return toReturn;
} }
} }

View File

@ -600,4 +600,4 @@ a.link:hover {
transition: background .25s ease-in-out; transition: background .25s ease-in-out;
-moz-transition: background .25s ease-in-out; -moz-transition: background .25s ease-in-out;
-webkit-transition: background .25s ease-in-out; -webkit-transition: background .25s ease-in-out;
} }