1 |
f8ee2720
|
Patrick Plitzner
|
/**
|
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 |
a45e3c4a
|
Patrick Plitzner
|
import org.eclipse.swt.widgets.Composite;
|
15 |
f8ee2720
|
Patrick Plitzner
|
import org.eclipse.swt.widgets.Display;
|
16 |
|
|
import org.eclipse.swt.widgets.Label;
|
17 |
|
|
import org.eclipse.ui.forms.widgets.TableWrapLayout;
|
18 |
|
|
|
19 |
a86dbf9a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
20 |
f8ee2720
|
Patrick Plitzner
|
|
21 |
|
|
/**
|
22 |
|
|
*
|
23 |
|
|
* @author pplitzner
|
24 |
|
|
* @date Sep 21, 2015
|
25 |
|
|
*
|
26 |
|
|
*/
|
27 |
a45e3c4a
|
Patrick Plitzner
|
public abstract class AbstractUriWithExceptionLabelElement <T> extends TextWithLabelElement {
|
28 |
f8ee2720
|
Patrick Plitzner
|
|
29 |
|
|
protected Label labelException;
|
30 |
|
|
|
31 |
a45e3c4a
|
Patrick Plitzner
|
protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory,
|
32 |
f8ee2720
|
Patrick Plitzner
|
ICdmFormElement parentElement, String labelString,
|
33 |
|
|
T initialObject, Integer textHeight, int style) {
|
34 |
|
|
super(formFactory, parentElement, false);
|
35 |
|
|
|
36 |
a45e3c4a
|
Patrick Plitzner
|
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 |
f8ee2720
|
Patrick Plitzner
|
initLabel(formFactory, labelString, false, getLayoutComposite());
|
42 |
|
|
|
43 |
|
|
//uri text
|
44 |
|
|
initText(formFactory, null, textHeight, null, false, style, getLayoutComposite());
|
45 |
|
|
|
46 |
|
|
//exceptionLabel
|
47 |
a45e3c4a
|
Patrick Plitzner
|
initExceptionLabel(getLayoutComposite(), formFactory, initialObject);
|
48 |
|
|
}
|
49 |
f8ee2720
|
Patrick Plitzner
|
|
50 |
a45e3c4a
|
Patrick Plitzner
|
protected void initExceptionLabel(Composite parent, CdmFormFactory formFactory, T initialObject) {
|
51 |
|
|
labelException = formFactory.createLabel(parent, "", SWT.WRAP); //$NON-NLS-1$
|
52 |
f8ee2720
|
Patrick Plitzner
|
int numColumns = AbstractFormSection.DEFAULT_NUM_COLUMNS;
|
53 |
a45e3c4a
|
Patrick Plitzner
|
if(parent.getLayout() instanceof TableWrapLayout){
|
54 |
|
|
numColumns = ((TableWrapLayout)parent.getLayout()).numColumns;
|
55 |
f8ee2720
|
Patrick Plitzner
|
}
|
56 |
|
|
labelException.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(numColumns, 1));
|
57 |
d3bbc6c1
|
Katja Luther
|
labelException.setBackground(getPersistentBackground());
|
58 |
f8ee2720
|
Patrick Plitzner
|
addControl(labelException);
|
59 |
|
|
setParsedText(initialObject);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
public abstract void setParsedText(T object);
|
64 |
|
|
|
65 |
a45e3c4a
|
Patrick Plitzner
|
protected abstract T getParsedText() throws Exception;
|
66 |
f8ee2720
|
Patrick Plitzner
|
|
67 |
a45e3c4a
|
Patrick Plitzner
|
public T parseText(){
|
68 |
|
|
try {
|
69 |
f8ee2720
|
Patrick Plitzner
|
labelException.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
|
70 |
|
|
labelException.setForeground(getPersistentBackground());
|
71 |
|
|
labelException.setText(""); //$NON-NLS-1$
|
72 |
a45e3c4a
|
Patrick Plitzner
|
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 |
f8ee2720
|
Patrick Plitzner
|
}
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
}
|