Added method to show a specific image in the carousel

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/image-previewer-widget@122482 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-22 17:51:57 +00:00
parent fdc03577dd
commit 3caf2336b0
2 changed files with 32 additions and 13 deletions

View File

@ -83,6 +83,7 @@ public class EnhancedImage {
* @param image * @param image
* @param titleToShow * @param titleToShow
* @param toolTipToShow * @param toolTipToShow
* @param download url
*/ */
public EnhancedImage(Image image, String titleToShow, String toolTipToShow, String downloadUrl) { public EnhancedImage(Image image, String titleToShow, String toolTipToShow, String downloadUrl) {

View File

@ -65,8 +65,8 @@ public class Carousel extends Composite{
public Carousel() { public Carousel() {
initWidget(uiBinder.createAndBindUi(this)); initWidget(uiBinder.createAndBindUi(this));
// hide show button (not needed when the widget is used) // hide show button (not needed when the widget is used...it was used while creating the widget)
showButton.setVisible(false); showButton.setVisible(false);
// set alignment of the horizontal panel's children // set alignment of the horizontal panel's children
@ -108,6 +108,7 @@ public class Carousel extends Composite{
@UiHandler("downloadButton") @UiHandler("downloadButton")
public void downloadOnClick(ClickEvent e){ public void downloadOnClick(ClickEvent e){
mainModalPanel.hide();
Window.open(listOfAttachmentsToShow.get(currentPreviewPosition).getDownloadUrl(), "_blank", ""); Window.open(listOfAttachmentsToShow.get(currentPreviewPosition).getDownloadUrl(), "_blank", "");
} }
@ -146,12 +147,12 @@ public class Carousel extends Composite{
mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow()); mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow());
} }
/** /**
* Used to show this carousel. * Used to show this carousel.
*/ */
public void show(){ public void show(){
// take the first object // take the first object
currentPreviewPosition = 0; currentPreviewPosition = 0;
@ -163,20 +164,23 @@ public class Carousel extends Composite{
// change the title to the modal // change the title to the modal
mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow()); mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow());
mainModalPanel.show(); mainModalPanel.show();
} }
/** /**
* Change the current image. * Used to show a specific image of this carousel.
* @param newPosition index of the new image to show
*/ */
public void changeIndexImageShown(int newPosition){ public void show(EnhancedImage image){
if(newPosition < 0 || newPosition >= listOfAttachmentsToShow.size()) // evaluate where this image is
int index = evaluateImagePosition(image);
if(index == -1)
return; return;
currentPreviewPosition = newPosition; // take the first object
currentPreviewPosition = index;
// show it // show it
shownImage.setUrl(listOfAttachmentsToShow.get(currentPreviewPosition).getImageUrl()); shownImage.setUrl(listOfAttachmentsToShow.get(currentPreviewPosition).getImageUrl());
@ -187,16 +191,30 @@ public class Carousel extends Composite{
// change the title to the modal // change the title to the modal
mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow()); mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow());
mainModalPanel.show();
} }
private int evaluateImagePosition(EnhancedImage image) {
for(int index = 0; index < listOfAttachmentsToShow.size(); index++){
if(listOfAttachmentsToShow.get(index).equals(image))
return index;
}
return -1;
}
/** /**
* Change the set of images to show * Change the set of images to show
* @param imagesToShow * @param imagesToShow
*/ */
public void updateImages(List<EnhancedImage> imagesToShow){ public void updateImages(List<EnhancedImage> imagesToShow){
listOfAttachmentsToShow = imagesToShow; listOfAttachmentsToShow = imagesToShow;
} }
} }