Project

General

Profile

Download (2.47 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.Display;
16
import org.eclipse.swt.widgets.Label;
17
import org.eclipse.ui.forms.widgets.TableWrapLayout;
18

    
19
import eu.etaxonomy.taxeditor.Messages;
20

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

    
29
    protected Label labelException;
30

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

    
36
		//label
37
        initLabel(formFactory, labelString, false, getLayoutComposite());
38

    
39
        //uri text
40
        initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
41

    
42
        //exceptionLabel
43
		initExceptionLabel(formFactory, initialObject);
44
	}
45

    
46
    private void initExceptionLabel(CdmFormFactory formFactory, T initialObject) {
47
        labelException = formFactory.createLabel(getLayoutComposite(), "", SWT.WRAP); //$NON-NLS-1$
48
		int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
49
		if(getLayoutComposite().getLayout() instanceof TableWrapLayout){
50
		    numColumns = ((TableWrapLayout)getLayoutComposite().getLayout()).numColumns;
51
		}
52
        labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
53
		addControl(labelException);
54
		setParsedText(initialObject);
55
    }
56

    
57

    
58
    public abstract void setParsedText(T object);
59

    
60
    public abstract T parseText();
61

    
62
    protected void updateExceptionLabel(Exception e){
63
        if(e!=null){
64
            labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
65
            labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
66
            labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getLocalizedMessage());
67
        }
68
        else{
69
            labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
70
            labelException.setForeground(getPersistentBackground());
71
            labelException.setText(""); //$NON-NLS-1$
72
        }
73
    }
74

    
75
}
(41-41/42)