commit ec683ee129dd91c5c31da7e1df3a51b0ed600a7d
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Jul 20 20:16:59 2015 +0200

    Enhance handling of simple and advanced media view
    
     - Buffer URI string in case of parsing errors
     - disable toggling when media conists of more than one representation
    or part

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 fbde0b7e0..9d016cb31 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
@@ -119,7 +119,13 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
 			try {
 			    URI uri = text_uri.getUri();
 				getEntity().setUri(uri);
-
+				if(uri==null){
+				    //buffer URI if parsing error occurred
+				    MediaDetailElement parentMediaDetailElement = getParentMediaDetailElement();
+				    if(parentMediaDetailElement!=null){
+				        parentMediaDetailElement.setUriBuffer(text_uri.getText());
+				    }
+				}
 
 				loadImage(getEntity().getUri(), true);
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
index e05ed4064..1c2766564 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaDetailElement.java
@@ -9,6 +9,7 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.media;
 
+import java.net.URI;
 import java.util.List;
 import java.util.Set;
 
@@ -16,6 +17,7 @@ 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.MediaUtils;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -39,6 +41,11 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
     private ICdmFormElement parentFormElement;
     private int style;
 
+    /**
+     * Used to store the URI even if it is invalid and thus cannot be stored in CDM
+     */
+    private String uriBuffer;
+
     public MediaDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
         super(formFactory, formElement);
     }
@@ -63,11 +70,25 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
     public void handleEvent(Object eventSource){
         if(eventSource==textUri){
             textUri.setBackground(getPersistentBackground());
-            singleMediaRepresentationPart.setUri(textUri.getUri());
+            URI uri = textUri.getUri();
+            singleMediaRepresentationPart.setUri(uri);
+            if(uri==null){
+                uriBuffer=textUri.getText();
+            }
         }
     }
 
-    public void toggleAdvancedMediaView(){
+    public void toggleAdvancedMediaView() {
+        if (getEntity().getRepresentations() != null
+                && (getEntity().getRepresentations().size() > 1 ||
+                        (getEntity().getRepresentations().size() == 1
+                        && getEntity().getRepresentations().iterator().next().getParts().size() > 1))) {
+            MessagingUtils.informationDialog("Toggling not possible",
+                    "Media has consists of multiple representations or representatio parts");
+            // toggling is only possible if there are no more than one
+            // MediaRepresentation resp. MediaRepresentationParts
+            return;
+        }
         isAdvancedMediaView = !isAdvancedMediaView;
         showAdvancedView();
         reflowParentScrolledForm(true);
@@ -81,13 +102,23 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
             section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
             section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
             section_mediaRepresentation.setEntity(getEntity());
+            //set buffered uri as text if uri had parsing problems in simple view
+            if(uriBuffer!=null){
+                section_mediaRepresentation.getLayoutComposite().getChildren();
+            }
         }
         else{
             if(section_mediaRepresentation!=null){
                 removeElementsAndControls(section_mediaRepresentation);
             }
             textUri = formFactory.createUriWithLabelElement(parentFormElement, "Media URI", null, style);
-            textUri.setUri(singleMediaRepresentationPart.getUri());
+            URI uri = singleMediaRepresentationPart.getUri();
+            textUri.setUri(uri);
+            //set buffered uri as text if uri had parsing problems in advanced view
+            if(uri==null && uriBuffer!=null){
+                textUri.setText(uriBuffer);
+                textUri.getUri();
+            }
             textUri.getLayoutComposite().layout();
         }
     }
@@ -116,4 +147,12 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
         return isAdvancedMediaView;
     }
 
+    public void setUriBuffer(String uriBuffer) {
+        this.uriBuffer = uriBuffer;
+    }
+
+    public String getUriBuffer() {
+        return uriBuffer;
+    }
+
 }
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
index 5a2952547..663848da4 100644
--- 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
@@ -58,8 +58,14 @@ public class MediaRepresentationPartElement<T extends MediaRepresentationPart> e
 			text_size.setText(FileUtils.byteCountToDisplaySize(entity.getSize()));
 		}
 		if(entity.getUri() != null){
-			text_uri.setText(entity.getUri().toString());
-		}
+			text_uri.setUri(entity.getUri());
+		} else {
+            String uriBuffer = getParentMediaDetailElement().getUriBuffer();
+            if(uriBuffer!=null){
+                text_uri.setText(uriBuffer);
+                text_uri.getUri();//just to update the error label
+            }
+        }
 	}
 
 	@Override
@@ -67,8 +73,27 @@ public class MediaRepresentationPartElement<T extends MediaRepresentationPart> e
 		if(eventSource == text_uri){
 		    URI uri = text_uri.getUri();
 		    getEntity().setUri(uri);
+		    if(uri==null){
+                //buffer URI if parsing error occurred
+                MediaDetailElement parentMediaDetailElement = getParentMediaDetailElement();
+                if(parentMediaDetailElement!=null){
+                    parentMediaDetailElement.setUriBuffer(text_uri.getText());
+                }
+            }
+
 		    firePropertyChangeEvent(this);
 		}
 	}
 
+    protected MediaDetailElement getParentMediaDetailElement() {
+        ICdmFormElement parentElement = getParentElement();
+        while(parentElement!=null){
+            parentElement = parentElement.getParentElement();
+            if(parentElement instanceof MediaDetailElement){
+                return (MediaDetailElement) parentElement;
+            }
+        }
+        return null;
+    }
+
 }
