import java.util.List;
import java.util.Set;
+import org.apache.sanselan.ImageReadException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
+import eu.etaxonomy.cdm.common.UriUtils;
import eu.etaxonomy.cdm.common.media.ImageInfo;
import eu.etaxonomy.cdm.model.media.ImageFile;
import eu.etaxonomy.cdm.model.media.Media;
if(uri == null){
return;
}
- imageInfo = ImageInfo.NewInstance(uri, 10000);
+ //first check if uri refers to an actual (non-image) file
+ UriUtils.getInputStream(uri);// will fail with a FileNotFoundException if not
+ imageInfo = ImageInfo.NewInstance(uri, 10000);//will fail when it is no image file
singleMediaRepresentationPart.setSize((int) imageInfo.getLength());
if(singleMediaRepresentationPart instanceof ImageFile){
((ImageFile) singleMediaRepresentationPart).setHeight(imageInfo.getHeight());
element_image = formFactory.createImageElement(parentFormElement, uri, style);
element_image.initImageUri(uri);
element_image.loadImage();
- if(lblNoImage!=null){
- lblNoImage.dispose();
- }
- lblNoImage = null;
- } catch (Exception e) {
- handleException();
+ disposeErrorLabel();
+ } catch (Exception e){
+ if(e.getCause()!=null && e.getCause().getClass().equals(ImageReadException.class)){
+ disposeErrorLabel();
+ handleException(uri, "No preview available for this file type");
+ }
+ else{
+ disposeErrorLabel();
+ handleException(uri, "No file found");
+ }
}
}
+ private void disposeErrorLabel() {
+ if(lblNoImage!=null){
+ lblNoImage.dispose();
+ }
+ lblNoImage = null;
+ }
+
public void toggleAdvancedMediaView() {
if (getEntity().getRepresentations() != null
&& (getEntity().getRepresentations().size() > 1 ||
isAdvancedMediaView = false;
}
- private void handleException() {
+ private void handleException(URI uri, String labelText) {
if(element_image!=null){
element_image.unloadImage();
element_image.loadImage();
element_image.dispose();
}
if(lblNoImage==null){
- lblNoImage = formFactory.createLabel(getLayoutComposite(), "No Image found");
+ lblNoImage = formFactory.createLabel(getLayoutComposite(), labelText);
lblNoImage.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
lblNoImage.setAlignment(SWT.CENTER);
}