2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.element
;
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
;
19 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
27 public abstract class AbstractUriWithExceptionLabelElement
<T
> extends TextWithLabelElement
{
29 protected Label labelException
;
31 protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory
,
32 ICdmFormElement parentElement
, String labelString
,
33 T initialObject
, Integer textHeight
, int style
) {
34 super(formFactory
, parentElement
, false);
36 init(formFactory
, labelString
, initialObject
, textHeight
, style
);
39 protected void init(CdmFormFactory formFactory
, String labelString
, T initialObject
, Integer textHeight
, int style
) {
41 initLabel(formFactory
, labelString
, false, getLayoutComposite());
44 initText(formFactory
, null, textHeight
, null, false, style
, getLayoutComposite());
47 initExceptionLabel(getLayoutComposite(), formFactory
, initialObject
);
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
;
56 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(numColumns
, 1));
57 addControl(labelException
);
58 setParsedText(initialObject
);
62 public abstract void setParsedText(T object
);
64 protected abstract T
getParsedText() throws Exception
;
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());