Enhance handling of simple and advanced media view
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 20 Jul 2015 18:16:59 +0000 (20:16 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 21 Jul 2015 09:19:09 +0000 (11:19 +0200)
 - Buffer URI string in case of parsing errors
 - disable toggling when media conists of more than one representation
or part

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/MediaDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java

index fbde0b7e0ed056e51d0b6d809db9aa24e4a535ac..9d016cb3175be5d881d8eb238c4c495ff5b1410d 100644 (file)
@@ -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);
 
index e05ed4064260e68d770df99dec3a5c11e950a8bd..1c27665647713fdd53c267767588114f683fb708 100644 (file)
@@ -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;
+    }
+
 }
index 5a295254788c851528ec31c0a1eb5e141f4d2b17..663848da419d2bef3ba02e2b78c73f4c0911f147 100644 (file)
@@ -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;
+    }
+
 }