Project

General

Profile

Download (2.96 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.swt.widgets.Label;
16
import org.eclipse.ui.forms.widgets.TableWrapLayout;
17

    
18
/**
19
 * @author pplitzner
20
 * @date Sep 21, 2015
21
 */
22
public abstract class AbstractUriWithExceptionLabelElement <T> extends TextWithLabelElement {
23

    
24
    protected Label labelException;
25

    
26
    protected String exceptionString;
27

    
28
	protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory,
29
			ICdmFormElement parentElement, String labelString,
30
			T initialObject, Integer textHeight, int style) {
31
		super(formFactory, parentElement, false);
32

    
33
        init(formFactory, labelString, initialObject, textHeight, style);
34
    }
35

    
36
    protected void init(CdmFormFactory formFactory, String labelString, T initialObject, Integer textHeight, int style) {
37
        //label
38
        initLabel(formFactory, labelString, false, getLayoutComposite());
39

    
40
        //uri text
41
        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
42
        setParsedText(initialObject);
43
        //exceptionLabel
44
        initExceptionLabel(getLayoutComposite(), formFactory);
45
    }
46

    
47
    protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory) {
48
        labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
49
		int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
50
		if(parent.getLayout() instanceof TableWrapLayout){
51
		    numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
52
		}
53
        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
54
        labelException.setBackground(getPersistentBackground());
55
        labelException.setSize(1, 0);
56
        addControl(labelException);
57
		this.getLayoutComposite().layout();
58
    }
59

    
60
    public abstract void setParsedText(T object);
61

    
62
    protected abstract T getParsedText() throws Exception;
63

    
64
    public T parseText(){
65
        try {
66
            labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
67
            labelException.setForeground(getPersistentBackground());
68
            labelException.setText("");
69
            labelException.requestLayout();//$NON-NLS-1$
70
            return getParsedText();
71
        } catch (Exception e) {
72
            labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
73
            labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
74
            labelException.setText(exceptionString + e.getLocalizedMessage());
75
            labelException.requestLayout();
76
            return null;
77
        }
78
    }
79

    
80

    
81
}
(6-6/57)