use mediaUtils for getting the best matching media representation for mediaViewLabelP...
authorKatja Luther <k.luther@bgbm.org>
Wed, 15 Nov 2017 09:40:23 +0000 (10:40 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 15 Nov 2017 09:40:23 +0000 (10:40 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/MediaViewLabelProvider.java

index 01895419a1647cd73c4493212fadf3111188f353..12eb1c0d9513a8a7f829ab38461d5353e81faa52 100755 (executable)
@@ -27,6 +27,7 @@ import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
+import eu.etaxonomy.cdm.model.media.MediaUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 
 /**
@@ -61,12 +62,15 @@ public class MediaViewLabelProvider extends LabelProvider implements IStyledLabe
     @Override
     public Image getImage(Object element) {
         Image image = null;
+        int scale = 50;
         if (element instanceof Media && PreferencesUtil.isShowMediaPreview()){
             Set<MediaRepresentation> representations = ((Media)element).getRepresentations();
             if(representations.iterator().hasNext()){
-                MediaRepresentation rep = representations.iterator().next();
-                List<MediaRepresentationPart> parts = rep.getParts();
+                MediaRepresentation rep = null;
+
                 MediaRepresentationPart smallestPart = null;
+                rep = MediaUtils.findBestMatchingRepresentation((Media)element, null, null, scale, scale, null);
+                List<MediaRepresentationPart> parts = rep.getParts();
                 for (MediaRepresentationPart part: parts){
                     if (smallestPart != null){
                         if (smallestPart.getSize() != null && part.getSize() != null) {
@@ -79,7 +83,7 @@ public class MediaViewLabelProvider extends LabelProvider implements IStyledLabe
                     }
 
                 }
-                URI uri = parts.get(0).getUri();
+                URI uri = smallestPart.getUri();
                 if (uri == null){
                     return null;
                 }
@@ -89,7 +93,7 @@ public class MediaViewLabelProvider extends LabelProvider implements IStyledLabe
                     image = new Image(Display.getCurrent(), imageStream);
                     int height = image.getBounds().height;
                     int width = image.getBounds().width;
-                    int scale = 50;
+
                     if (height>width){
                         width = width/(height/scale);
                         height = scale;