commit 5d8edc8c4c8081aa66f7a597f2183a4fa29d9e53
Author: n.hoffmann <n.hoffmann@localhost>
Date:   Wed Aug 17 15:53:54 2011 +0000

    Fixes #2525

diff --git a/.gitattributes b/.gitattributes
index 8257ee1fd..07e18a5a2 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -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
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/CdmFormFactory.java
index 73c96492b..4bb783007 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/forms/CdmFormFactory.java
@@ -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()) {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractMediaRepresentationPartElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractMediaRepresentationPartElement.java
deleted file mode 100644
index 3de858cc8..000000000
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/AbstractMediaRepresentationPartElement.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// $Id$
-/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
-* http://www.e-taxonomy.eu
-* 
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-
-package eu.etaxonomy.taxeditor.ui.section.media;
-
-import org.apache.log4j.Logger;
-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.NumberWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
-
-/**
- * <p>Abstract AbstractMediaRepresentationPartElement class.</p>
- *
- * @author n.hoffmann
- * @created Mar 24, 2010
- * @version 1.0
- */
-public abstract class AbstractMediaRepresentationPartElement<T extends MediaRepresentationPart> extends
-		AbstractEntityCollectionElement<T> {
-
-
-	private static final Logger logger = Logger
-			.getLogger(AbstractMediaRepresentationPartElement.class);
-	protected TextWithLabelElement text_uri;
-	protected NumberWithLabelElement text_size;
-
-	/**
-	 * <p>Constructor for AbstractMediaRepresentationPartElement.</p>
-	 *
-	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
-	 * @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
-	 * @param element a T object.
-	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
-	 * @param style a int.
-	 * @param <T> a T object.
-	 */
-	public AbstractMediaRepresentationPartElement(CdmFormFactory formFactory,
-			AbstractFormSection section,
-			T element, SelectionListener removeListener,
-			int style) {
-		super(formFactory, section, element, removeListener, null, style);
-	}
-	
-	/** {@inheritDoc} */
-	@Override
-	public void createControls(ICdmFormElement element, int style) {
-		text_uri = formFactory.createTextWithLabelElement(element, "URI", null, style);
-		text_size = formFactory.createIntegerTextWithLabelElement(element, "Size", null, style);
-		text_size.setEnabled(false);
-	}
-
-}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
index 4b2e70343..a012172d9 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/ImageFileElement.java
@@ -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);
 		
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java
new file mode 100644
index 000000000..756661cba
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java
@@ -0,0 +1,102 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.ui.section.media;
+
+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;
+
+/**
+ * <p>Abstract AbstractMediaRepresentationPartElement class.</p>
+ *
+ * @author n.hoffmann
+ * @created Mar 24, 2010
+ * @version 1.0
+ */
+public class MediaRepresentationPartElement<T extends MediaRepresentationPart> extends
+		AbstractEntityCollectionElement<T> {
+
+	protected TextWithLabelElement text_uri;
+	protected NumberWithLabelElement text_size;
+
+	protected LabelElement element_messages;
+	
+	/**
+	 * <p>Constructor for AbstractMediaRepresentationPartElement.</p>
+	 *
+	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
+	 * @param section a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection} object.
+	 * @param element a T object.
+	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
+	 * @param style a int.
+	 * @param <T> a T object.
+	 */
+	public MediaRepresentationPartElement(CdmFormFactory formFactory,
+			AbstractFormSection section,
+			T element, SelectionListener removeListener,
+			int style) {
+		super(formFactory, section, element, removeListener, null, style);
+	}
+	
+	/** {@inheritDoc} */
+	@Override
+	public void createControls(ICdmFormElement element, int style) {
+		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("");
+	}
+
+}
