Fixes #2525
authorn.hoffmann <n.hoffmann@localhost>
Wed, 17 Aug 2011 15:53:54 +0000 (15:53 +0000)
committern.hoffmann <n.hoffmann@localhost>
Wed, 17 Aug 2011 15:53:54 +0000 (15:53 +0000)
.gitattributes
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java [moved from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractMediaRepresentationPartElement.java with 60% similarity]

index 8257ee1fd918aa704922ef2cc7d419a4dc59ce2f..07e18a5a2a585ae17902a57ed2afe9ba3d627773 100644 (file)
@@ -1013,10 +1013,10 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/PolytomousKeyNodeDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/ScopeRestrictionSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/TaxonomicScopeSection.java -text
-eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractMediaRepresentationPartElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaSection.java -text
index 73c96492bfdde739e64bf5a78189ff1aee6c0f06..4bb783007ced008dda5cd7ea1a825ede1b1457df 100644 (file)
@@ -95,6 +95,7 @@ import eu.etaxonomy.cdm.model.location.ReferenceSystem;
 import eu.etaxonomy.cdm.model.media.ImageFile;
 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.Rights;
 import eu.etaxonomy.cdm.model.media.RightsTerm;
 import eu.etaxonomy.cdm.model.name.NameRelationship;
@@ -189,6 +190,7 @@ import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
 import eu.etaxonomy.taxeditor.ui.section.media.ImageFileElement;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaElement;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationElement;
+import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartElement;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartSection;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
 import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
@@ -2175,6 +2177,9 @@ public class CdmFormFactory extends FormToolkit {
                } else if (entity instanceof ImageFile) {
                        element = new ImageFileElement(this, parentElement,
                                        (ImageFile) entity, removeListener, style);
+               } else if (entity instanceof MediaRepresentationPart){
+                       element = new MediaRepresentationPartElement(this, parentElement, 
+                                       (MediaRepresentationPart) entity, removeListener, style);                       
                } else if (entity instanceof NomenclaturalStatus) {
                        element = new NomenclaturalStatusElement(this, parentElement,
                                        (NomenclaturalStatus) entity, removeListener, style);
@@ -2254,6 +2259,7 @@ public class CdmFormFactory extends FormToolkit {
                                                        "Could not generate element for entity. "
                                                                        + "Looks like the case is not handled already. Check implementation. Entity: "
                                                                        + entity, null);
+
                }
 
                if (backgroundColor != null && !backgroundColor.isDisposed()) {
index 4b2e70343bca8e7a0a362ceeecfa75a6cbd2557f..a012172d96935babe8e21a216ffca6ba3fa5befb 100644 (file)
@@ -17,6 +17,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.http.HttpException;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.ui.editors.text.EditorsUI;
 
 import eu.etaxonomy.cdm.common.media.ImageInfo;
 import eu.etaxonomy.cdm.model.media.ImageFile;
@@ -27,7 +28,6 @@ import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.forms.ImageElement;
 import eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement;
-import eu.etaxonomy.taxeditor.ui.forms.LabelElement;
 import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
 
 /**
@@ -37,14 +37,14 @@ import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
  * @created Mar 26, 2010
  * @version 1.0
  */
-public class ImageFileElement extends AbstractMediaRepresentationPartElement<ImageFile> {
+public class ImageFileElement extends MediaRepresentationPartElement<ImageFile> {
 
        private NumberWithLabelElement text_height;
        private NumberWithLabelElement text_width;
        private KeyValueViewerElement element_keyValue;
        private ImageElement element_image;
        
-       private LabelElement element_messages;
+       
        private Runnable postRunnable = new Runnable(){
                public void run() {
                        StoreUtil.reflowDetailsViewer();
@@ -78,25 +78,17 @@ public class ImageFileElement extends AbstractMediaRepresentationPartElement<Ima
                text_width = formFactory.createIntegerTextWithLabelElement(formElement, "Width", null, style);
                text_width.setEnabled(false);
                element_image = formFactory.createImageElement(formElement, null, style);
-               element_messages = formFactory.createLabel(formElement, "");
                element_keyValue = formFactory.createKeyValueViewerElement(formElement, "Key", "Value", null);
        }
        
        /** {@inheritDoc} */
        @Override
        public void setEntity(ImageFile entity) {
-               this.entity = entity;
-               if(entity.getSize() != null){
-                       text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
-               }
+               super.setEntity(entity);
                text_height.setInteger(entity.getHeight());
                text_width.setInteger(entity.getWidth());
-               if(entity.getUri() != null){
-                       text_uri.setText(entity.getUri().toString());
-               }
                try {
                        showImage(entity.getUri());             
-                       element_messages.setText("");
                } catch (Exception e) {
                        handleException(e);
                }
@@ -153,10 +145,9 @@ public class ImageFileElement extends AbstractMediaRepresentationPartElement<Ima
                }
        }
 
-       private void handleException(Exception e) {
-               element_messages.setText(e.getMessage());
+       protected void handleException(Exception e) {
+               super.handleException(e);
                element_image.unloadImage(postRunnable);
-               text_size.setText("");
                text_height.setInteger(0);
                text_width.setInteger(0);
                
 
 package eu.etaxonomy.taxeditor.ui.section.media;
 
-import org.apache.log4j.Logger;
+import java.net.URI;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
 import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.forms.LabelElement;
 import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
@@ -28,15 +32,14 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
  * @created Mar 24, 2010
  * @version 1.0
  */
-public abstract class AbstractMediaRepresentationPartElement<T extends MediaRepresentationPart> extends
+public class MediaRepresentationPartElement<T extends MediaRepresentationPart> extends
                AbstractEntityCollectionElement<T> {
 
-
-       private static final Logger logger = Logger
-                       .getLogger(AbstractMediaRepresentationPartElement.class);
        protected TextWithLabelElement text_uri;
        protected NumberWithLabelElement text_size;
 
+       protected LabelElement element_messages;
+       
        /**
         * <p>Constructor for AbstractMediaRepresentationPartElement.</p>
         *
@@ -47,7 +50,7 @@ public abstract class AbstractMediaRepresentationPartElement<T extends MediaRepr
         * @param style a int.
         * @param <T> a T object.
         */
-       public AbstractMediaRepresentationPartElement(CdmFormFactory formFactory,
+       public MediaRepresentationPartElement(CdmFormFactory formFactory,
                        AbstractFormSection section,
                        T element, SelectionListener removeListener,
                        int style) {
@@ -60,6 +63,40 @@ public abstract class AbstractMediaRepresentationPartElement<T extends MediaRepr
                text_uri = formFactory.createTextWithLabelElement(element, "URI", null, style);
                text_size = formFactory.createIntegerTextWithLabelElement(element, "Size", null, style);
                text_size.setEnabled(false);
+               
+               element_messages = formFactory.createLabel(element, "");
+       }
+
+       @Override
+       public void setEntity(T entity) {
+               this.entity = entity;
+               if(entity.getSize() != null){
+                       text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
+               }
+               if(entity.getUri() != null){
+                       text_uri.setText(entity.getUri().toString());
+               }
+               element_messages.setText("We currrently do not know how to display this generic MediaRepresentationPart to you.");
+       }
+
+       @Override
+       public void handleEvent(Object eventSource) {
+               if(eventSource == text_uri){
+                       try {
+                               String uriString = text_uri.getText();
+                               URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null;
+                               getEntity().setUri(uri);
+                       } catch (Exception e) {
+                               handleException(e);
+                       } finally {                             
+                               firePropertyChangeEvent(this);
+                       }
+               } 
+       }
+       
+       protected void handleException(Exception e) {
+               element_messages.setText(e.getMessage());
+               text_size.setText("");
        }
 
 }