3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.element
;
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
;
20 import eu
.etaxonomy
.taxeditor
.Messages
;
28 public abstract class AbstractUriWithExceptionLabelElement
<T
> extends TextWithLabelElement
{
30 protected Label labelException
;
32 protected AbstractUriWithExceptionLabelElement(CdmFormFactory formFactory
,
33 ICdmFormElement parentElement
, String labelString
,
34 T initialObject
, Integer textHeight
, int style
) {
35 super(formFactory
, parentElement
, false);
37 init(formFactory
, labelString
, initialObject
, textHeight
, style
);
40 protected void init(CdmFormFactory formFactory
, String labelString
, T initialObject
, Integer textHeight
, int style
) {
42 initLabel(formFactory
, labelString
, false, getLayoutComposite());
45 initText(formFactory
, null, textHeight
, null, false, style
, getLayoutComposite());
48 initExceptionLabel(getLayoutComposite(), formFactory
, initialObject
);
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
;
57 labelException
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(numColumns
, 1));
58 addControl(labelException
);
59 setParsedText(initialObject
);
63 public abstract void setParsedText(T object
);
65 protected abstract T
getParsedText() throws Exception
;
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());