ref #8667: add orcid to person detail element
authorKatja Luther <k.luther@bgbm.org>
Mon, 11 Nov 2019 09:18:38 +0000 (10:18 +0100)
committerKatja Luther <k.luther@bgbm.org>
Mon, 11 Nov 2019 09:18:38 +0000 (10:18 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OrcidWithLabelElement.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/agent/PersonDetailElement.java

index e0e6d42136c8c539c1cfd95b555124c18d7cb31b..d874c8ed5afc3a626cb3f5d96ac5377334725bfb 100644 (file)
@@ -119,6 +119,7 @@ public class Messages extends NLS {
     public static String UriWithLabelElement_OPEN_EXTERNAL_BROWSER;
     public static String UriWithLabelElement_URL_NOT_SAVED;
     public static String DoiWithLabelElement_DOI_NOT_SAVED;
+    public static String OrcidWithLabelElement_DOI_NOT_SAVED;
 
        public static String CdmStoreConnector_AUTHENTICATING_USER;
        public static String CdmStoreConnector_CHECK_IF_EDITOR_IS_COMPATIBLE;
index aa7f0c37e9efb2abb6f668fd44289965838c4fc7..390794f95d8e93ace8969c614538ff5a2b94b2eb 100644 (file)
@@ -63,6 +63,7 @@ UriWithLabelElement_INVALID_URL=Invalid URI
 UriWithLabelElement_OPEN_EXTERNAL_BROWSER=Open in external browser
 
 DoiWithLabelElement_DOI_NOT_SAVED=DOI won't be saved\!
+OrcidWithLabelElement_DOI_NOT_SAVED=ORCID won't be saved\!
 
 ChangeConnectionHandler_ALREADY_CONNECTING=Already creating data model
 ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY=You are currently creating a data model for a datasource already.
index 448228cb745f290d0ba687f3524a5f16dc23e65f..e7ebc55dd7215d35993000ee062f694a0d2db42c 100644 (file)
@@ -63,6 +63,7 @@ UriWithLabelElement_INVALID_URL=Ung\u00FCltige URI
 UriWithLabelElement_OPEN_EXTERNAL_BROWSER=Im Browser öffnen 
 
 DoiWithLabelElement_DOI_NOT_SAVED=DOI wird nicht gespeichert\!
+OrcidWithLabelElement_DOI_NOT_SAVED=ORCID wird nicht gespeichert\!
 
 ChangeConnectionHandler_ALREADY_CONNECTING=Datenmodell wird erstellt
 ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY=Es wird schon das Datenmodell für eine Datenquelle erstellt
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OrcidWithLabelElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/OrcidWithLabelElement.java
new file mode 100755 (executable)
index 0000000..9d8c3fd
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+* Copyright (C) 2019 EDIT
+* 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.
+*/
+package eu.etaxonomy.taxeditor.ui.element;
+
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+import eu.etaxonomy.cdm.model.agent.ORCID;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+
+/**
+ * @author k.luther
+ * @since 11.11.2019
+ */
+public class OrcidWithLabelElement extends AbstractUriWithExceptionLabelElement<ORCID> {
+
+    /**
+     * @param formFactory
+     * @param parentElement
+     * @param labelString
+     * @param initialObject
+     * @param textHeight
+     * @param style
+     */
+    protected OrcidWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
+            ORCID initialObject, Integer textHeight, int style) {
+        super(formFactory, parentElement, labelString, initialObject, textHeight, style);
+        // TODO Auto-generated constructor stub
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setParsedText(ORCID object) {
+        if(object != null){
+            super.setText(object.toString());
+        }
+
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected ORCID getParsedText() throws Exception {
+        String orcidText = super.getText();
+        if(orcidText!=null){
+            return ORCID.fromString(super.getText());
+        }
+        return null;
+    }
+
+    @Override
+    protected void init(CdmFormFactory formFactory, String labelString, ORCID initialObject, Integer textHeight, int style) {
+
+        //label
+        initLabel(formFactory, labelString, false, getLayoutComposite());
+        //uri text
+        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
+        initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
+    }
+
+    @Override
+    protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, ORCID initialObject) {
+        labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
+        int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
+        if(parent.getLayout() instanceof TableWrapLayout){
+            numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
+        }
+        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
+        labelException.setBackground(getPersistentBackground());
+        addControl(labelException);
+        setParsedText(initialObject);
+    }
+    @Override
+    public ORCID parseText(){
+        try {
+            labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
+            labelException.setForeground(getPersistentBackground());
+            labelException.setText(""); //$NON-NLS-1$
+            return getParsedText();
+        } catch (Exception e) {
+            labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
+            labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+            labelException.setText(Messages.OrcidWithLabelElement_DOI_NOT_SAVED+e.getLocalizedMessage());
+            return null;
+        }
+    }
+
+}
+
index 4a1b98a9d1ac595bdc8f15091c02fb9999f9cfa4..d1cba6f2394a5fef9661aa7cf51bac2540a34c7f 100644 (file)
@@ -18,6 +18,7 @@ import eu.etaxonomy.cdm.model.agent.Person;
 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.OrcidWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 
@@ -38,6 +39,7 @@ public class PersonDetailElement extends AbstractIdentifiableEntityDetailElement
        private TextWithLabelElement text_prefix;
        private TextWithLabelElement text_suffix;
        private TextWithLabelElement text_initials;
+       private OrcidWithLabelElement text_orcid;
 
        private Collection<Object> excludeFromIrrelevantToggleableObjects;
 
@@ -80,8 +82,8 @@ public class PersonDetailElement extends AbstractIdentifiableEntityDetailElement
                                "Initials", entity.getInitials(), SWT.NULL);
                text_prefix = formFactory.createTextWithLabelElement(formElement,
                                "Prefix", entity.getPrefix(), SWT.NULL);
-               text_suffix = formFactory.createTextWithLabelElement(formElement,
-                               "Suffix", entity.getSuffix(), SWT.NULL);
+               text_orcid = formFactory.createOrcidWithLabelElement(formElement, "ORCID", entity.getOrcid(), SWT.NULL);
+
        }
 
        /** {@inheritDoc} */
@@ -116,7 +118,9 @@ public class PersonDetailElement extends AbstractIdentifiableEntityDetailElement
                        getEntity().setPrefix(text_prefix.getText());
                } else if (eventSource == text_suffix) {
                        getEntity().setSuffix(text_suffix.getText());
-               }
+               }else if (eventSource == text_orcid) {
+            getEntity().setOrcid(text_orcid.parseText());
+        }
 
                //if (eventSource != toggleable_cache) {
                if (!getEntity().isProtectedTitleCache()){