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