Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / LabelElement.java
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.swt.SWT;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.ui.forms.widgets.TableWrapData;
16
17 import eu.etaxonomy.cdm.common.CdmUtils;
18
19 /**
20 * <p>LabelElement class.</p>
21 *
22 * @author n.hoffmann
23 * @created Jun 1, 2010
24 * @version 1.0
25 */
26 public class LabelElement extends AbstractCdmFormElement {
27
28 private Label label;
29
30 /**
31 * <p>Constructor for LabelElement.</p>
32 *
33 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
34 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
35 * @param text a {@link java.lang.String} object.
36 */
37 public LabelElement(CdmFormFactory formFactory, ICdmFormElement formElement, String text) {
38 super(formFactory, formElement);
39
40 label = formFactory.createLabel(getLayoutComposite(), text, SWT.WRAP);
41 label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
42 addControl(label);
43 }
44
45 /**
46 * <p>setText</p>
47 *
48 * @param text a {@link java.lang.String} object.
49 */
50 public void setText(String text) {
51 String pattern = "(.*[^&])&([^&].*)";
52 if(text.matches(pattern)){
53 text = text.replaceAll(pattern, "$1&&$2");
54 }
55 label.setText(CdmUtils.Nz(text));
56 }
57
58 public void setLayout(TableWrapData layoutConstants){
59 label.setLayoutData(layoutConstants);
60 }
61
62 public void setForeground(Color color){
63 label.setForeground(color);
64 }
65
66 public void setVisible(boolean setVisible){
67 label.setVisible(setVisible);
68 }
69 }