Show URI parsing exceptions below URI text field (fixes #5055, #5003, #4587)
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 24 Jun 2015 17:55:55 +0000 (19:55 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 11:47:21 +0000 (13:47 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.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/MediaDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaRepresentationPartElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/ProtologueElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/NamedAreaDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/vocabulary/TermVocabularyDetailElement.java

index 8e1ff192767b343711416e1917b66bb5d26238a7..ee6867db2b3a57827f7e4f552affc3713903b1bc 100644 (file)
@@ -11,9 +11,9 @@
 package eu.etaxonomy.taxeditor.ui.element;
 
 import java.net.URI;
-import java.net.URISyntaxException;
-
 
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
 
 /**
  * @author n.hoffmann
@@ -22,35 +22,33 @@ import java.net.URISyntaxException;
  */
 public class UriWithLabelElement extends TextWithLabelElement {
 
-       /**
-        * @param formFactory
-        * @param parentElement
-        * @param labelString
-        * @param initialText
-        * @param textHeight
-        * @param style
-        */
+    private final Label labelException;
+
        protected UriWithLabelElement(CdmFormFactory formFactory,
                        ICdmFormElement parentElement, String labelString,
                        URI initialUri, Integer textHeight, int style) {
                super(formFactory, parentElement, labelString, null, textHeight, style);
+
+               labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP);
+               labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+               addControl(labelException);
                setUri(initialUri);
        }
 
-       /**
-        *
-        */
        public void setUri(URI uri) {
                if(uri != null){
                        super.setText(uri.toString());
                }
        }
 
-       public URI getUri() throws URISyntaxException{
-           if(super.getText()!=null){
-               return new URI(super.getText());
-           }
-           return null;
+       public URI getUri(){
+        try {
+            labelException.setText("");
+            return new URI(super.getText());
+        } catch (Exception e) {
+            labelException.setText(e.getMessage());
+            return null;
+        }
        }
 
 }
index 098620fd70d003c00b96a7bc129492c53277f732..ffa008b59897fdad17d2bd6432e52dce5617c85d 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -20,6 +20,7 @@ import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.common.media.ImageInfo;
 import eu.etaxonomy.cdm.model.media.ImageFile;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -42,16 +43,17 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
        private NumberWithLabelElement text_width;
        private KeyValueViewerElement element_keyValue;
        private ImageElement element_image;
-       
-       
-       private Runnable postRunnable = new Runnable(){
-               public void run() {
+
+
+       private final Runnable postRunnable = new Runnable(){
+               @Override
+        public void run() {
                        StoreUtil.reflowDetailsViewer();
                        StoreUtil.reflowSupplementalViewer();
                }
        };
-       
-       
+
+
        /**
         * <p>Constructor for ImageFileElement.</p>
         *
@@ -66,12 +68,12 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
                        SelectionListener removeListener, int style) {
                super(cdmFormFactory, section, element, removeListener, style);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement formElement, int style) {
                super.createControls(formElement, style);
-               
+
                text_height = formFactory.createNumberTextWithLabelElement(formElement, "Height", null, style);
                text_height.setEnabled(false);
                text_width = formFactory.createNumberTextWithLabelElement(formElement, "Width", null, style);
@@ -79,7 +81,7 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
                element_image = formFactory.createImageElement(formElement, null, style);
                element_keyValue = formFactory.createKeyValueViewerElement(formElement, "Key", "Value", null);
        }
-       
+
        /** {@inheritDoc} */
        @Override
        public void setEntity(ImageFile entity) {
@@ -87,41 +89,40 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
                text_height.setNumber(entity.getHeight());
                text_width.setNumber(entity.getWidth());
                try {
-                       loadImage(entity.getUri(), false);              
+                       loadImage(entity.getUri(), false);
                } catch (Exception e) {
                        handleException(e);
                }
        }
-       
+
        private void loadImage(URI uri, boolean updateDimensions) throws IOException, HttpException{
                element_image.initImageUri(uri);
-               
+
                element_image.loadImage(postRunnable );
-               
-               
+
+
                if(uri == null){
                        return;
                }
-               
+
                ImageInfo imageInfo = ImageInfo.NewInstanceWithMetaData(uri, 10000);
-                               
+
                element_keyValue.setInput(imageInfo.getMetaData());
-               
+
                if(updateDimensions){
                        text_size.setText(FileUtils.byteCountToDisplaySize(imageInfo.getLength()));
-                       // KLUDGE this is not save for very large files, because of the int cast. 
+                       // KLUDGE this is not save for very large files, because of the int cast.
                        // But then, I don't think we will handle such large files in the near future
                        getEntity().setSize((int) imageInfo.getLength());
-                       
+
                        text_height.setNumber(imageInfo.getHeight());
                        getEntity().setHeight(imageInfo.getHeight());
-                               
+
                        text_width.setNumber(imageInfo.getWidth());
                        getEntity().setWidth(imageInfo.getWidth());
                }
-               
-               
-               element_messages.setText("");
+
+
        }
 
        /*
@@ -136,29 +137,29 @@ public class ImageFileElement extends MediaRepresentationPartElement<ImageFile>
                                String uriString = text_uri.getText();
                                URI uri = StringUtils.isNotEmpty(uriString) ? new URI(uriString) : null;
                                getEntity().setUri(uri);
-                               
-                               
+
+
                                loadImage(getEntity().getUri(), true);
-                               
+
                                firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
                        } catch (Exception e) {
                                handleException(e);
-                       } finally {                             
+                       } finally {
                                firePropertyChangeEvent(this);
                        }
                }
        }
 
        protected void handleException(Exception e) {
-               super.handleException(e);
                element_image.unloadImage(postRunnable);
                text_height.setNumber(0);
                text_width.setNumber(0);
-               
+
                element_image.loadImage(new Runnable(){
-                       public void run() {
-                               StoreUtil.reflowDetailsViewer();
-                               StoreUtil.reflowSupplementalViewer();
+                       @Override
+            public void run() {
+                               AbstractUtility.reflowDetailsViewer();
+                               AbstractUtility.reflowSupplementalViewer();
                        }
                });
        }
index 09b8b8991e3decfa8416b2acc3c5be19a4348831..e05ed4064260e68d770df99dec3a5c11e950a8bd 100644 (file)
@@ -9,7 +9,6 @@
 */
 package eu.etaxonomy.taxeditor.ui.section.media;
 
-import java.net.URISyntaxException;
 import java.util.List;
 import java.util.Set;
 
@@ -19,7 +18,6 @@ import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
 import eu.etaxonomy.cdm.model.media.MediaUtils;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
@@ -62,14 +60,10 @@ public class MediaDetailElement extends AbstractCdmDetailElement<Media>{
     }
 
     @Override
-    public void handleEvent(Object eventSource) {
+    public void handleEvent(Object eventSource){
         if(eventSource==textUri){
             textUri.setBackground(getPersistentBackground());
-            try {
-                singleMediaRepresentationPart.setUri(textUri.getUri());
-            } catch (URISyntaxException e) {
-                textUri.setBackground(getColor(Resources.COLOR_PARSE_ERROR));
-            }
+            singleMediaRepresentationPart.setUri(textUri.getUri());
         }
     }
 
index a5ef673414987ed2965ce762c3d0cc092dd6459b..5a295254788c851528ec31c0a1eb5e141f4d2b17 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -13,16 +13,14 @@ 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.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.LabelElement;
 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
 
 /**
@@ -35,36 +33,22 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
 public class MediaRepresentationPartElement<T extends MediaRepresentationPart> extends
                AbstractEntityCollectionElement<T> {
 
-       protected TextWithLabelElement text_uri;
+       protected UriWithLabelElement text_uri;
        protected NumberWithLabelElement text_size;
 
-       protected LabelElement element_messages;
-       
-       /**
-        * <p>Constructor for AbstractMediaRepresentationPartElement.</p>
-        *
-        * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
-        * @param section a {@link eu.etaxonomy.taxeditor.ui.element.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_uri = formFactory.createUriWithLabelElement(element, "URI", null, style);
                text_size = formFactory.createNumberTextWithLabelElement(element, "Size", null, style);
                text_size.setEnabled(false);
-               
-               element_messages = formFactory.createLabel(element, "");
        }
 
        @Override
@@ -76,27 +60,15 @@ public class MediaRepresentationPartElement<T extends MediaRepresentationPart> e
                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("");
+                   URI uri = text_uri.getUri();
+                   getEntity().setUri(uri);
+                   firePropertyChangeEvent(this);
+               }
        }
 
 }
index 5896a5e2ad9d73282f229fca8a8dbc4f6c1d3e7d..aa7a3ef6b84a3e12599efb74d08028327ac6d30d 100644 (file)
@@ -11,7 +11,6 @@
 package eu.etaxonomy.taxeditor.ui.section.name;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 import org.eclipse.swt.events.SelectionListener;
 
@@ -22,14 +21,13 @@ import eu.etaxonomy.cdm.model.media.MediaRepresentation;
 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
 import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
-import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
 
@@ -44,7 +42,7 @@ public class ProtologueElement extends AbstractEntityCollectionElement<Descripti
 
        private final SelectionArbitrator selectionArbitrator;
 
-       private TextWithLabelElement protologueUriText;
+       private UriWithLabelElement protologueUriText;
        private MediaRepresentationPart mediaRepresentationPart;
        private Media media;
        private MediaRepresentation mediaRepresentation;
@@ -67,7 +65,7 @@ public class ProtologueElement extends AbstractEntityCollectionElement<Descripti
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
-               protologueUriText = formFactory.createTextWithLabelElement(this, "Protologue URI", "", style);
+               protologueUriText = formFactory.createUriWithLabelElement(element, "Protologue URI", null, style);
 
                formFactory.createOpenUrlSelectorElement(element, "Query BHL for Reference Image", this, style);
        }
@@ -112,11 +110,7 @@ public class ProtologueElement extends AbstractEntityCollectionElement<Descripti
        @Override
        public void handleEvent(Object eventSource) {
                if(eventSource == protologueUriText && protologueUriText.getText()!=null){
-                       try {
-                               mediaRepresentationPart.setUri(new URI(protologueUriText.getText()));
-                       } catch (URISyntaxException e) {
-                               MessagingUtils.warningDialog("Could not parse URI", getClass(), e.getMessage());
-                       }
+                   mediaRepresentationPart.setUri(protologueUriText.getUri());
                }
        }
 
index 743f0bcd733f56d5c5a7af3b3ecf106384fcfb38..bdbab1697900c68af8eed7c30ee18368aee0f574 100644 (file)
@@ -10,7 +10,6 @@
 
 package eu.etaxonomy.taxeditor.ui.section.reference;
 
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -24,7 +23,6 @@ import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
 import eu.etaxonomy.cdm.model.reference.ReferenceType;
 import eu.etaxonomy.taxeditor.model.AuthorHelper;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
@@ -443,12 +441,7 @@ public class ReferenceDetailElement extends AbstractIdentifiableEntityDetailElem
                    getEntity().setAbbrevTitle(text_abbrevTitle.getText());
                    toggleableAbbrevCache.setText(text_abbrevTitle.getText());
                } else if (eventSource == text_uri) {
-                       try {
-                               getEntity().setUri(text_uri.getUri());
-                       } catch (URISyntaxException e) {
-                               MessagingUtils.warningDialog("Invalid URI", getClass(),
-                                               e.getLocalizedMessage());
-                       }
+                       getEntity().setUri(text_uri.getUri());
                } else if (eventSource == text_volume) {
                        getEntity().setVolume(text_volume.getText());
                }
index 2e1d746c62b4e12b47c3a64d7a704112926785f2..0a5a6ad37156c72fc0099fe986efc2ba1e0ebb02 100644 (file)
@@ -9,8 +9,6 @@
 */\r
 package eu.etaxonomy.taxeditor.ui.section.vocabulary;\r
 \r
-import java.net.URISyntaxException;\r
-\r
 import eu.etaxonomy.cdm.model.common.Language;\r
 import eu.etaxonomy.cdm.model.common.TermType;\r
 import eu.etaxonomy.cdm.model.location.NamedArea;\r
@@ -66,17 +64,9 @@ public class NamedAreaDetailElement extends DefinedTermDetailElement<NamedArea>
                        getEntity().setLabel(text_label.getText());\r
                        getEntity().setTitleCache(null);\r
                } else if (eventSource == text_description) {\r
-\r
                        getEntity().getRepresentation(Language.getDefaultLanguage()).setText(text_description.getText());\r
-\r
                } else if (eventSource == uri_uri) {\r
-\r
-                       try {\r
-                               getEntity().setUri(uri_uri.getUri());\r
-                       } catch (URISyntaxException e) {\r
-\r
-                               e.printStackTrace();\r
-                       }\r
+                       getEntity().setUri(uri_uri.getUri());\r
                } else if (eventSource == text_abbreviatedLabel) {\r
                        getEntity().getRepresentation(Language.getDefaultLanguage()).setAbbreviatedLabel(text_abbreviatedLabel.getText());\r
                } else if (eventSource == timePeriod_validPeriod) {\r
index e1aea5b8fb3294b709076f7d5fc86141caafd0b3..5f62d2417e571a62672f1a149a741c17bd13c39a 100644 (file)
@@ -1,19 +1,15 @@
 // $Id$\r
 /**\r
 * Copyright (C) 2009 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
 * http://www.e-taxonomy.eu\r
-* \r
+*\r
 * The contents of this file are subject to the Mozilla Public License Version 1.1\r
 * See LICENSE.TXT at the top of this package for the full license terms.\r
 */\r
 package eu.etaxonomy.taxeditor.ui.section.vocabulary;\r
 \r
-import java.net.URISyntaxException;\r
-\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.taxeditor.model.MessagingUtils;\r
-import eu.etaxonomy.taxeditor.store.StoreUtil;\r
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;\r
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;\r
 import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;\r
@@ -41,7 +37,7 @@ public class TermVocabularyDetailElement extends AbstractTermBaseDetailElement<T
        @Override\r
        protected void createControls(ICdmFormElement formElement,\r
                        TermVocabulary entity, int style) {\r
-               \r
+\r
                super.createControls(formElement, entity, style);\r
                uri_uriTermSource = formFactory.createUriWithLabelElement(formElement, "Term Source URI", getEntity().getTermSourceUri(), style);\r
        }\r
@@ -51,21 +47,13 @@ public class TermVocabularyDetailElement extends AbstractTermBaseDetailElement<T
         */\r
        @Override\r
        public void handleEvent(Object eventSource) {\r
-               \r
+\r
                handleRepresentation(eventSource);\r
-               \r
+\r
                if (eventSource == uri_uri) {\r
-                       try {\r
-                               getEntity().setUri(uri_uri.getUri());\r
-                       } catch (URISyntaxException e) {\r
-                               MessagingUtils.messageDialog("Not a URI", getClass(), "You have to provide a valid URI");\r
-                       }\r
+                       getEntity().setUri(uri_uri.getUri());\r
                } else if (eventSource == uri_uriTermSource) {\r
-                       try {\r
-                               getEntity().setTermSourceUri(uri_uriTermSource.getUri());\r
-                       } catch (URISyntaxException e) {\r
-                               MessagingUtils.messageDialog("Not a URI", getClass(), "You have to provide a valid URI");\r
-                       }\r
+                       getEntity().setTermSourceUri(uri_uriTermSource.getUri());\r
                }\r
        }\r
 \r