fix #9035: fix NPE in reference details
authorKatja Luther <k.luther@bgbm.org>
Wed, 27 May 2020 20:33:37 +0000 (22:33 +0200)
committerKatja Luther <k.luther@bgbm.org>
Wed, 27 May 2020 20:33:37 +0000 (22:33 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/DoiWithLabelElement.java

index a21d13ae9d882663b772c62dbd3da104f2f58c08..66ad9ccae730d11d028d314e71216d0db862267c 100755 (executable)
@@ -8,8 +8,15 @@
 */
 package eu.etaxonomy.taxeditor.ui.element;
 
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -17,6 +24,10 @@ import org.eclipse.ui.forms.widgets.TableWrapLayout;
 
 import eu.etaxonomy.cdm.common.DOI;
 import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * @author k.luther
@@ -69,39 +80,42 @@ public class DoiWithLabelElement extends AbstractUriWithExceptionLabelElement<DO
 
         //label
         initLabel(formFactory, labelString, false, getLayoutComposite());
-        //uri text
-        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
-
-//        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
-//        addControl(textAndButton);
-//        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
-//        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
-//      //button
-//        btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
-//        btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
-//        btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
-//        btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
-//            @Override
-//            public void widgetSelected(SelectionEvent e) {
-//                String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
-//                String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
-//
-//                DOI doi= parseText();
-//                if(doi!=null){
-//                    try {
-//                        WorkbenchUtility.openWebpage(new URL(doi.asURI()));
-//                    } catch (IOException pie) {
-//                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
-//                    } catch (IllegalArgumentException iae) {
-//                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
-//                    }
-//                }
-//                else{
-//                    MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
-//                }
-//            }
-//        });
-//        btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
+
+
+
+        Composite textAndButton = formFactory.createComposite(getLayoutComposite(), style);
+        addControl(textAndButton);
+        textAndButton.setLayout(LayoutConstants.LAYOUT(2, false));
+        textAndButton.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+      //uri text
+        initText(formFactory, null, textHeight, null, false, style, textAndButton);
+
+      //button
+        btnOpenBrowser = formFactory.createButton(textAndButton, "", SWT.NONE); //$NON-NLS-1$
+        btnOpenBrowser.setImage(ImageResources.getImage(ImageResources.WEB));
+        btnOpenBrowser.setToolTipText(Messages.UriWithLabelElement_OPEN_EXTERNAL_BROWSER);
+        btnOpenBrowser.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                String errorTitle = Messages.UriWithLabelElement_INVALID_URL;
+                String errorText = Messages.UriWithLabelElement_COULD_NOT_OPEN_BROWSER;
+
+                DOI doi= parseText();
+                if(doi!=null){
+                    try {
+                        WorkbenchUtility.openWebpage(new URL(doi.asURI()));
+                    } catch (IOException pie) {
+                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, pie));
+                    } catch (IllegalArgumentException iae) {
+                        MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, iae));
+                    }
+                }
+                else{
+                    MessagingUtils.informationDialog(errorTitle, new Status(IStatus.WARNING, TaxeditorStorePlugin.PLUGIN_ID, errorText, null));
+                }
+            }
+        });
+        btnOpenBrowser.setLayoutData(LayoutConstants.RIGHT());
         initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
     }