Merge branch 'release/5.11.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / OrcidWithLabelElement.java
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..29a1f3a
--- /dev/null
@@ -0,0 +1,102 @@
+/**
+* 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, 2));
+        labelException.setBackground(getPersistentBackground());
+        labelException.setText("\n\n"); //$NON-NLS-1$
+        addControl(labelException);
+        setParsedText(initialObject);
+    }
+    @Override
+    public ORCID parseText(){
+        try {
+            labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
+            labelException.setForeground(getPersistentBackground());
+            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_ORCID_NOT_SAVED + " " + e.getLocalizedMessage());
+            labelException.requestLayout();
+            return null;
+        }
+    }
+
+}
+