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 titleToShow
* @param toolTipToShow
* @param download url
*/
public EnhancedImage(Image image, String titleToShow, String toolTipToShow, String downloadUrl) {

View File

@ -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<EnhancedImage> imagesToShow){
listOfAttachmentsToShow = imagesToShow;
}
}