implemented user management, fixes #803. Minor refactorings.
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / description / DescriptionElementComposite.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.editor.description;
11
12 import org.eclipse.swt.graphics.Font;
13 import org.eclipse.swt.graphics.Image;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.ui.views.properties.IPropertySource;
16
17 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
18 import eu.etaxonomy.taxeditor.editor.GroupedComposite;
19 import eu.etaxonomy.taxeditor.model.DescriptionHelper;
20 import eu.etaxonomy.taxeditor.model.ImageResources;
21 import eu.etaxonomy.taxeditor.model.Resources;
22 import eu.etaxonomy.taxeditor.propertysheet.description.DescriptionElementPropertySource;
23
24 /**
25 * @author p.ciardelli
26 * @created 02.06.2008
27 * @version 1.0
28 */
29 public class DescriptionElementComposite extends GroupedComposite {
30
31 /**
32 * ************ COMPOSITE TYPES ************
33 */
34 public static final String TEXT_DATA = "text_data";
35 public static final String COMMON_TAXON_NAME = "common_taxon_name";
36 public static final String DISTRIBUTION = "distribution";
37
38 /**
39 * ************ FONTS ************
40 */
41 public static final Font ELEMENT_FONT = Resources
42 .getFont(Resources.SYNONYM_FONT);
43
44 /**
45 * ************ ICONS ************
46 */
47 public static final Image BLACK_SQUARE_ICON = ImageResources
48 .getImage(ImageResources.BLACK_SQUARE_ICON);
49
50 protected DescriptionElementBase element;
51
52 private static final String EMPTY_NAME_PROMPT = "Click to add descriptive element text";
53
54 public DescriptionElementComposite(TaxonDescriptionEditor editor, Composite parent, DescriptionElementBase element) {
55 super(editor, parent);
56
57 this.element = element;
58
59
60 createTextViewer();
61 createBorderSupport();
62 createLineWrapSupport();
63
64 createParser();
65 createEmptyViewerPrompt(EMPTY_NAME_PROMPT);
66
67 setIsDraggable(false);
68 setIcon(BLACK_SQUARE_ICON);
69 setFont(getViewerFont());
70
71 //createMenu();
72 this.setMenu(editor.getMenu());
73
74 initTextViewer();
75 }
76
77 protected void initTextViewer() {
78
79 String text = null;
80
81 text = DescriptionHelper.getCache(element);
82
83 if (text.length() == 0) {
84 initEmptyText();
85 } else {
86 textViewer.getTextWidget().setText(text);
87 }
88 }
89
90 public DescriptionElementBase getElement() {
91 return element;
92 }
93
94 protected void parse(String text) {
95
96 DescriptionHelper.setCache(getElement(), text);
97
98 // Manually refresh the property sheet to reflect changes
99 setSelection();
100
101 setDirty(true);
102 }
103
104 public IPropertySource getPropertySource() {
105 return new DescriptionElementPropertySource(getElement());
106 }
107
108 @Override
109 protected Font getViewerFont() {
110 return ELEMENT_FONT;
111 }
112
113 public Object getData () {
114 return getElement();
115 }
116 }