From 3caf2336b04ba19de12a4e347579961820bdb81b Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Fri, 22 Jan 2016 17:51:57 +0000 Subject: [PATCH] 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 --- .../client/EnhancedImage.java | 1 + .../client/ui/Carousel.java | 44 +++++++++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) 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; - + } }