*/
package eu.etaxonomy.taxeditor.ui.section.media;
+import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Set;
+import org.apache.http.HttpException;
import org.apache.sanselan.ImageReadException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
*/
public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
+ /**
+ * @author pplitzner
+ * @since Jul 11, 2019
+ *
+ */
+ private final class LoadImageJob extends Job {
+ private URI uri;
+ private LoadImageJob(URI uri, String name) {
+ super(name);
+ this.uri = uri;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ ImageInfo imageInfo;
+ try {
+ //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
+ MediaDetailElement.this.getLayoutComposite().getDisplay().asyncExec(()->{
+ singleMediaRepresentationPart.setSize((int) imageInfo.getLength());
+ if(singleMediaRepresentationPart.isInstanceOf(ImageFile.class)){
+ ImageFile image = CdmBase.deproxy(singleMediaRepresentationPart, ImageFile.class);
+ image.setHeight(imageInfo.getHeight());
+ image.setWidth(imageInfo.getWidth());
+ }
+ singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
+ singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
+ element_image = formFactory.createImageElement(parentFormElement, uri, style);
+ StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
+ try {
+ element_image.initImageUri(uri);
+ } catch (IOException | HttpException e) {
+ exception(e, uri);
+ }
+ element_image.loadImage();
+ disposeErrorLabel();
+ });
+ } catch (IOException|HttpException e){
+ exception(e, uri);
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
private UriWithLabelElement textUri;
private MediaRepresentationSection section_mediaRepresentation;
uriBuffer=textUri.getText();
}
else{
- createImageElement(uri);
+ new LoadImageJob(uri, "loadImage").schedule();
}
}
}
- private void createImageElement(URI uri) {
- ImageInfo imageInfo;
- try {
- if(uri == null){
- return;
+ private void exception(Exception e, URI uri){
+ getLayoutComposite().getDisplay().asyncExec(()->{
+ if(e.getCause()!=null && e.getCause().getClass().equals(ImageReadException.class)){
+ disposeErrorLabel();
+ handleException(uri, "No preview available for this file type");
}
- //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.isInstanceOf(ImageFile.class)){
- ImageFile image = CdmBase.deproxy(singleMediaRepresentationPart, ImageFile.class);
- image.setHeight(imageInfo.getHeight());
- image.setWidth(imageInfo.getWidth());
+ else{
+ disposeErrorLabel();
+ handleException(uri, "No file found");
}
- singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
- singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
- element_image = formFactory.createImageElement(parentFormElement, uri, style);
- element_image.initImageUri(uri);
- element_image.loadImage();
- 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() {
}
textUri.getLayoutComposite().layout();
- createImageElement(singleMediaRepresentationPart.getUri());
+ new LoadImageJob(singleMediaRepresentationPart.getUri(), "loadImage").schedule();
}
}