- fixed NPE (#4937)
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 15 Jun 2015 12:31:29 +0000 (14:31 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 15 Jun 2015 12:31:29 +0000 (14:31 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/ProtologueElement.java

index a11e8e43bb55e870e4f6de962e502564edeabd07..5896a5e2ad9d73282f229fca8a8dbc4f6c1d3e7d 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.
 */
@@ -42,7 +42,7 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
  */
 public class ProtologueElement extends AbstractEntityCollectionElement<DescriptionElementBase> implements ISelectableElement, IOpenUrlEnabled{
 
-       private SelectionArbitrator selectionArbitrator;
+       private final SelectionArbitrator selectionArbitrator;
 
        private TextWithLabelElement protologueUriText;
        private MediaRepresentationPart mediaRepresentationPart;
@@ -64,9 +64,6 @@ public class ProtologueElement extends AbstractEntityCollectionElement<Descripti
                selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite#createControls(org.eclipse.swt.widgets.Composite, int)
-        */
        /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
@@ -75,93 +72,75 @@ public class ProtologueElement extends AbstractEntityCollectionElement<Descripti
                formFactory.createOpenUrlSelectorElement(element, "Query BHL for Reference Image", this, style);
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite#setElement(eu.etaxonomy.cdm.model.common.VersionableEntity)
-        */
        /** {@inheritDoc} */
        @Override
        public void setEntity(DescriptionElementBase element) {
                this.entity = element;
-                               
+
                if(element.getMedia().size() == 0){
                        element.addMedia(Media.NewInstance());
                }
                media = element.getMedia().iterator().next();
-               
+
                if(media.getRepresentations().size() == 0){
                        media.addRepresentation(MediaRepresentation.NewInstance());
-               }               
+               }
                mediaRepresentation = media.getRepresentations().iterator().next();
-               
+
                if(mediaRepresentation.getParts().size() == 0){
                        mediaRepresentation.addRepresentationPart(MediaRepresentationPart.NewInstance(null, null));
                }
-               
+
                mediaRepresentationPart = mediaRepresentation.getParts().iterator().next();
-               
+
                if(mediaRepresentationPart.getUri() != null){
                        protologueUriText.setText(mediaRepresentationPart.getUri().toString());
                }
        }
-       
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
-        */
+
        /**
         * <p>Getter for the field <code>selectionArbitrator</code>.</p>
         *
         * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
         */
-       public SelectionArbitrator getSelectionArbitrator() {
+       @Override
+    public SelectionArbitrator getSelectionArbitrator() {
                return selectionArbitrator;
        }
-       
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement#handleEvent(java.lang.Object)
-        */
+
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
-               if(eventSource == protologueUriText){
+               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());
                        }
-               }       
+               }
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.openurl.IOpenUrlEnabled#setOpenUrl(java.net.URI)
-        */
        @Override
        public void setOpenUrl(URI uri) {
                protologueUriText.setText(uri.toString());
                firePropertyChangeEvent(new CdmPropertyChangeEvent(protologueUriText, null));
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.openurl.IOpenUrlEnabled#getReference()
-        */
        @Override
        public Reference getReference() {
                return (Reference) getName().getNomenclaturalReference();
        }
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.forms.openurl.IOpenUrlEnabled#getDetail()
-        */
        @Override
        public String getDetail() {
                return getName().getNomenclaturalMicroReference();
        }
-       
+
        private TaxonNameBase getName(){
                TaxonNameDescription description = (TaxonNameDescription) entity.getInDescription();
-               
+
                TaxonNameBase taxonName = description.getTaxonName();
-               
+
                return taxonName;
        }
 }