Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.element;
10

    
11
import org.eclipse.jface.resource.JFaceResources;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Display;
15
import org.eclipse.ui.forms.widgets.TableWrapLayout;
16

    
17
import eu.etaxonomy.cdm.common.DOI;
18
import eu.etaxonomy.taxeditor.l10n.Messages;
19

    
20
/**
21
 * @author k.luther
22
 * @since 27.11.2018
23
 *
24
 */
25
public class DoiWithLabelElement extends AbstractUriWithExceptionLabelElement<DOI> {
26

    
27
    /**
28
     * @param formFactory
29
     * @param parentElement
30
     * @param labelString
31
     * @param initialObject
32
     * @param textHeight
33
     * @param style
34
     */
35
    protected DoiWithLabelElement(CdmFormFactory formFactory, ICdmFormElement parentElement, String labelString,
36
            DOI initialObject, Integer textHeight, int style) {
37
        super(formFactory, parentElement, labelString, initialObject, textHeight, style);
38
        // TODO Auto-generated constructor stub
39
    }
40

    
41
    /**
42
     * {@inheritDoc}
43
     */
44
    @Override
45
    public void setParsedText(DOI object) {
46
        if(object != null){
47
            super.setText(object.toString());
48
        }
49

    
50
    }
51

    
52
    /**
53
     * {@inheritDoc}
54
     */
55
    @Override
56
    protected DOI getParsedText() throws Exception {
57
        String doiText = super.getText();
58
        if(doiText!=null){
59
            return DOI.fromString(super.getText());
60
        }
61
        return null;
62
    }
63

    
64
    @Override
65
    protected void init(CdmFormFactory formFactory, String labelString, DOI initialObject, Integer textHeight, int style) {
66

    
67
        //label
68
        initLabel(formFactory, labelString, false, getLayoutComposite());
69
        //uri text
70
        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
71
        initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
72
    }
73

    
74
    @Override
75
    protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, DOI initialObject) {
76
        labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
77
        int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
78
        if(parent.getLayout() instanceof TableWrapLayout){
79
            numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
80
        }
81
        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
82
        labelException.setBackground(getPersistentBackground());
83
        addControl(labelException);
84
        setParsedText(initialObject);
85
    }
86
    @Override
87
    public DOI parseText(){
88
        try {
89
            labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
90
            labelException.setForeground(getPersistentBackground());
91
            labelException.setText(""); //$NON-NLS-1$
92
            return getParsedText();
93
        } catch (Exception e) {
94
            labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
95
            labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
96
            labelException.setText(Messages.DoiWithLabelElement_DOI_NOT_SAVED+e.getLocalizedMessage());
97
            return null;
98
        }
99
    }
100

    
101
}
(12-12/48)