Revision 1ce04105
Added by Patrick Plitzner almost 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationElement.java | ||
---|---|---|
14 | 14 |
import java.util.Collection; |
15 | 15 |
|
16 | 16 |
import org.apache.http.HttpException; |
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
18 |
import org.eclipse.core.runtime.IStatus; |
|
19 |
import org.eclipse.core.runtime.Status; |
|
20 |
import org.eclipse.core.runtime.jobs.Job; |
|
17 | 21 |
import org.eclipse.swt.events.SelectionListener; |
18 | 22 |
|
19 | 23 |
import eu.etaxonomy.cdm.common.UriUtils; |
... | ... | |
79 | 83 |
// FIXME HACK automatically set the mime type to the first mediaRepresentationPart's mimetype |
80 | 84 |
else if(eventSource == section_mediaRepresentationPart){ |
81 | 85 |
firePropertyChangeEvent(this); |
86 |
new Job("Set mime type") { |
|
87 |
@Override |
|
88 |
protected IStatus run(IProgressMonitor monitor) { |
|
89 |
Collection<MediaRepresentationPart> imageFileElements = section_mediaRepresentationPart.getCollection(section_mediaRepresentationPart.getEntity()); |
|
90 |
if(! imageFileElements.iterator().hasNext()){ |
|
91 |
return Status.CANCEL_STATUS; |
|
92 |
} |
|
93 |
MediaRepresentationPart mediaRepresentationPart = imageFileElements.iterator().next(); |
|
94 |
if(mediaRepresentationPart == null || !(mediaRepresentationPart instanceof ImageFile)){ |
|
95 |
return Status.CANCEL_STATUS; |
|
96 |
} |
|
97 |
ImageFile imageFile = (ImageFile) mediaRepresentationPart; |
|
82 | 98 |
|
83 |
Collection<MediaRepresentationPart> imageFileElements = section_mediaRepresentationPart.getCollection(section_mediaRepresentationPart.getEntity()); |
|
84 |
|
|
85 |
if(! imageFileElements.iterator().hasNext()){ |
|
86 |
return; |
|
87 |
} |
|
88 |
|
|
89 |
MediaRepresentationPart mediaRepresentationPart = imageFileElements.iterator().next(); |
|
90 |
if(mediaRepresentationPart == null || !(mediaRepresentationPart instanceof ImageFile)){ |
|
91 |
return; |
|
92 |
} |
|
93 |
ImageFile imageFile = (ImageFile) mediaRepresentationPart; |
|
94 |
|
|
95 |
URI uri = imageFile.getUri(); |
|
96 |
if(!UriUtils.isServiceAvailable(uri)){ |
|
97 |
return; |
|
98 |
} |
|
99 |
try { |
|
100 |
ImageInfo imageInfo = ImageInfo.NewInstance(uri, 10000); |
|
101 |
String mimeType = imageInfo.getMimeType(); |
|
102 |
text_mimeType.setText(mimeType); |
|
103 |
getEntity().setMimeType(mimeType); |
|
104 |
text_suffix.setText(imageInfo.getSuffix()); |
|
105 |
getEntity().setSuffix(imageInfo.getSuffix()); |
|
106 |
} |
|
107 |
//theses exceptions do not need to be logged |
|
108 |
//especially because this happens with every key stroke |
|
109 |
catch (IOException e) { |
|
110 |
// MessagingUtils.error(getClass(), e); |
|
111 |
} |
|
112 |
catch (HttpException e) { |
|
113 |
// MessagingUtils.error(getClass(), e); |
|
114 |
} |
|
99 |
URI uri = imageFile.getUri(); |
|
100 |
if(!UriUtils.isServiceAvailable(uri)){ |
|
101 |
return Status.CANCEL_STATUS; |
|
102 |
} |
|
103 |
try { |
|
104 |
ImageInfo imageInfo = ImageInfo.NewInstance(uri, 10000); |
|
105 |
String mimeType = imageInfo.getMimeType(); |
|
106 |
getEntity().setMimeType(mimeType); |
|
107 |
getEntity().setSuffix(imageInfo.getSuffix()); |
|
108 |
MediaRepresentationElement.this.getLayoutComposite().getDisplay().asyncExec(()->{ |
|
109 |
text_mimeType.setText(mimeType); |
|
110 |
text_suffix.setText(imageInfo.getSuffix()); |
|
111 |
}); |
|
112 |
} |
|
113 |
//theses exceptions do not need to be logged |
|
114 |
//especially because this happens with every key stroke |
|
115 |
catch (IOException|HttpException e) { |
|
116 |
// ignore |
|
117 |
} |
|
118 |
return Status.OK_STATUS; |
|
119 |
} |
|
120 |
}.schedule(); |
|
115 | 121 |
} |
116 | 122 |
} |
117 | 123 |
} |
Also available in: Unified diff
ref #8129 Load images asynchronously in advanced media view