Added no topics message when there are no topics available

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/top-topics@128551 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-05-10 16:30:20 +00:00
parent f08a74a8a7
commit 9b7db56867
1 changed files with 23 additions and 17 deletions

View File

@ -31,6 +31,7 @@ public class TopicsPanel extends Composite {
public static final String loading = GWT.getModuleBaseURL() + "../images/topics-loader.gif"; public static final String loading = GWT.getModuleBaseURL() + "../images/topics-loader.gif";
public static final String DISPLAY_NAME = "Top Topics"; public static final String DISPLAY_NAME = "Top Topics";
public static final int THRESHOLD_SHOW_HASHTAGS = 10; // show the first X ones public static final int THRESHOLD_SHOW_HASHTAGS = 10; // show the first X ones
private static final String NO_TOP_TOPICS_MESSAGE = "No Topics Available";
private Image loadingImage; private Image loadingImage;
@ -55,7 +56,7 @@ public class TopicsPanel extends Composite {
} }
else { else {
int counter = 0; int counter = 0;
if (hashtags != null) { if (hashtags != null && !hashtags.isEmpty()) {
for (String hashtag : hashtags) { for (String hashtag : hashtags) {
counter ++; counter ++;
HTML toAdd = new HTML(hashtag); HTML toAdd = new HTML(hashtag);
@ -65,30 +66,35 @@ public class TopicsPanel extends Composite {
if(counter > THRESHOLD_SHOW_HASHTAGS) // 11, 12... if(counter > THRESHOLD_SHOW_HASHTAGS) // 11, 12...
toAdd.setVisible(false); toAdd.setVisible(false);
} }
}
// add a show all button if needed // add a show all button if needed
if(counter > THRESHOLD_SHOW_HASHTAGS){ if(counter > THRESHOLD_SHOW_HASHTAGS){
final Button showAllHashtags = new Button("Show All"); final Button showAllHashtags = new Button("Show All");
showAllHashtags.addClickHandler(new ClickHandler() {
@Override showAllHashtags.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
int numberChildren = mainPanel.getWidgetCount(); @Override
for (int i = THRESHOLD_SHOW_HASHTAGS; i < numberChildren; i++) { public void onClick(ClickEvent event) {
mainPanel.getWidget(i).setVisible(true); int numberChildren = mainPanel.getWidgetCount();
for (int i = THRESHOLD_SHOW_HASHTAGS; i < numberChildren; i++) {
mainPanel.getWidget(i).setVisible(true);
}
// hide the button
showAllHashtags.setVisible(false);
} }
});
mainPanel.add(showAllHashtags);
}
}else{
mainPanel.add(new HTML(NO_TOP_TOPICS_MESSAGE));
// hide the button
showAllHashtags.setVisible(false);
}
});
mainPanel.add(showAllHashtags);
} }
} }
} }