Project

General

Profile

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

    
11
package eu.etaxonomy.taxeditor.ui.element;
12

    
13
import org.eclipse.jface.resource.JFaceResources;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.ui.forms.widgets.TableWrapLayout;
19

    
20
import eu.etaxonomy.taxeditor.Messages;
21

    
22
/**
23
 *
24
 * @author pplitzner
25
 * @date Sep 21, 2015
26
 *
27
 */
28
public abstract class AbstractUriWithExceptionLabelElement <T> extends TextWithLabelElement {
29

    
30
    protected Label labelException;
31

    
32
	protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory,
33
			ICdmFormElement parentElement, String labelString,
34
			T initialObject, Integer textHeight, int style) {
35
		super(formFactory, parentElement, false);
36

    
37
        init(formFactory, labelString, initialObject, textHeight, style);
38
    }
39

    
40
    protected void init(CdmFormFactory formFactory, String labelString, T initialObject, Integer textHeight, int style) {
41
        //label
42
        initLabel(formFactory, labelString, false, getLayoutComposite());
43

    
44
        //uri text
45
        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
46

    
47
        //exceptionLabel
48
        initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
49
    }
50

    
51
    protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, T initialObject) {
52
        labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
53
		int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
54
		if(parent.getLayout() instanceof TableWrapLayout){
55
		    numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
56
		}
57
        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
58
		addControl(labelException);
59
		setParsedText(initialObject);
60
    }
61

    
62

    
63
    public abstract void setParsedText(T object);
64

    
65
    protected abstract T getParsedText() throws Exception;
66

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

    
81
}
(5-5/42)