Fixing problems with image handling.
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / media / MediaRepresentationElement.java
index 248a07865c5998d904bc3e22971ca7380a5a8552..1958ba58727099a41c11cd435f17d88bfbca2485 100644 (file)
@@ -14,16 +14,13 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.Collection;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpException;
 import org.eclipse.swt.events.SelectionListener;
 
-import eu.etaxonomy.cdm.api.service.IMediaService;
 import eu.etaxonomy.cdm.common.media.ImageInfo;
 import eu.etaxonomy.cdm.model.media.ImageFile;
 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
-import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
@@ -96,9 +93,15 @@ public class MediaRepresentationElement extends AbstractEntityCollectionElement<
                        getEntity().setSuffix(text_suffix.getText());
                }
                // FIXME HACK automatically set the mime type to the first mediaRepresentationPart's mimetype
-               else if(eventSource == section_mediaRepresentationPart){
+               else if(eventSource == section_mediaRepresentationPart){                        
+                       firePropertyChangeEvent(this);
+                       
                        Collection<MediaRepresentationPart> imageFileElements = section_mediaRepresentationPart.getCollection(section_mediaRepresentationPart.getEntity());
                        
+                       if(! imageFileElements.iterator().hasNext()){
+                               return; 
+                       }
+                       
                        MediaRepresentationPart mediaRepresentationPart = imageFileElements.iterator().next();
                        if(mediaRepresentationPart == null || !(mediaRepresentationPart instanceof ImageFile)){
                                return;
@@ -113,13 +116,17 @@ public class MediaRepresentationElement extends AbstractEntityCollectionElement<
                                ImageInfo imageInfo = ImageInfo.NewInstance(uri, 10000);
                                String mimeType = imageInfo.getMimeType();
                                text_mimeType.setText(mimeType);
+                               getEntity().setMimeType(mimeType);
                                text_suffix.setText(imageInfo.getSuffix());     
+                               getEntity().setSuffix(imageInfo.getSuffix());
                        } catch (IOException e) {
                                StoreUtil.error(getClass(), e);
                        } catch (HttpException e) {
                                StoreUtil.error(getClass(), e);
                        }
                }
+               
+               
        }
        
        private String getMimeType(URI uri){