diff --git a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java index a9652c2..604c650 100644 --- a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java +++ b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/EnhancedImage.java @@ -83,6 +83,7 @@ public class EnhancedImage { * @param image * @param titleToShow * @param toolTipToShow + * @param download url */ public EnhancedImage(Image image, String titleToShow, String toolTipToShow, String downloadUrl) { diff --git a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java index 3b4fb09..8b11cce 100644 --- a/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java +++ b/src/main/java/org/gcube/portlets/widgets/imagepreviewerwidget/client/ui/Carousel.java @@ -65,8 +65,8 @@ public class Carousel extends Composite{ public Carousel() { 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); // set alignment of the horizontal panel's children @@ -108,6 +108,7 @@ public class Carousel extends Composite{ @UiHandler("downloadButton") public void downloadOnClick(ClickEvent e){ + mainModalPanel.hide(); Window.open(listOfAttachmentsToShow.get(currentPreviewPosition).getDownloadUrl(), "_blank", ""); } @@ -146,12 +147,12 @@ public class Carousel extends Composite{ mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow()); } - + /** * Used to show this carousel. */ public void show(){ - + // take the first object currentPreviewPosition = 0; @@ -163,20 +164,23 @@ public class Carousel extends Composite{ // change the title to the modal mainModalPanel.setTitle(listOfAttachmentsToShow.get(currentPreviewPosition).getTitleToShow()); - + mainModalPanel.show(); } /** - * Change the current image. - * @param newPosition index of the new image to show + * Used to show a specific image of this carousel. */ - 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; - currentPreviewPosition = newPosition; + // take the first object + currentPreviewPosition = index; // show it shownImage.setUrl(listOfAttachmentsToShow.get(currentPreviewPosition).getImageUrl()); @@ -187,16 +191,30 @@ public class Carousel extends Composite{ // change the title to the modal 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 * @param imagesToShow */ public void updateImages(List imagesToShow){ - + listOfAttachmentsToShow = imagesToShow; - + } }