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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.element;
|
11
|
|
12
|
import org.eclipse.jface.resource.JFaceResources;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.widgets.Composite;
|
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.l10n.Messages;
|
20
|
|
21
|
/**
|
22
|
*
|
23
|
* @author pplitzner
|
24
|
* @date Sep 21, 2015
|
25
|
*
|
26
|
*/
|
27
|
public abstract class AbstractUriWithExceptionLabelElement <T> extends TextWithLabelElement {
|
28
|
|
29
|
protected Label labelException;
|
30
|
|
31
|
protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory,
|
32
|
ICdmFormElement parentElement, String labelString,
|
33
|
T initialObject, Integer textHeight, int style) {
|
34
|
super(formFactory, parentElement, false);
|
35
|
|
36
|
init(formFactory, labelString, initialObject, textHeight, style);
|
37
|
}
|
38
|
|
39
|
protected void init(CdmFormFactory formFactory, String labelString, T initialObject, Integer textHeight, int style) {
|
40
|
//label
|
41
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
42
|
|
43
|
//uri text
|
44
|
initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
|
45
|
|
46
|
//exceptionLabel
|
47
|
initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
|
48
|
}
|
49
|
|
50
|
protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, T initialObject) {
|
51
|
labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
|
52
|
int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
|
53
|
if(parent.getLayout() instanceof TableWrapLayout){
|
54
|
numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
|
55
|
}
|
56
|
labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
|
57
|
addControl(labelException);
|
58
|
setParsedText(initialObject);
|
59
|
}
|
60
|
|
61
|
|
62
|
public abstract void setParsedText(T object);
|
63
|
|
64
|
protected abstract T getParsedText() throws Exception;
|
65
|
|
66
|
public T parseText(){
|
67
|
try {
|
68
|
labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
|
69
|
labelException.setForeground(getPersistentBackground());
|
70
|
labelException.setText(""); //$NON-NLS-1$
|
71
|
return getParsedText();
|
72
|
} catch (Exception e) {
|
73
|
labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
|
74
|
labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
|
75
|
labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+e.getLocalizedMessage());
|
76
|
return null;
|
77
|
}
|
78
|
}
|
79
|
|
80
|
}
|