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
.editor
.description
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.swt
.graphics
.Font
;
18 import org
.eclipse
.swt
.graphics
.Image
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.ui
.forms
.IManagedForm
;
21 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
23 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
24 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
26 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
27 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
28 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
29 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
30 import eu
.etaxonomy
.taxeditor
.editor
.ContextMenu
;
31 import eu
.etaxonomy
.taxeditor
.editor
.GroupedComposite
;
32 import eu
.etaxonomy
.taxeditor
.operations
.description
.RemoveElementOperation
;
33 import eu
.etaxonomy
.taxeditor
.propertysheet
.description
.DescriptionElementPropertySource
;
40 public class DescriptionElementComposite
extends GroupedComposite
{
41 private static final Logger logger
= Logger
.getLogger(DescriptionElementComposite
.class);
44 * ************ COMPOSITE TYPES ************
46 public static final String TEXT_DATA
= "text_data";
47 public static final String COMMON_TAXON_NAME
= "common_taxon_name";
48 public static final String DISTRIBUTION
= "distribution";
51 * ************ FONTS ************
53 public static final Font ELEMENT_FONT
= TaxEditorPlugin
.getDefault()
54 .getFont(ITaxEditorConstants
.SYNONYM_FONT
);
57 * ************ ICONS ************
59 public static final Image BLACK_SQUARE_ICON
= TaxEditorPlugin
.getDefault()
60 .getImage(ITaxEditorConstants
.BLACK_SQUARE_ICON
);
62 private DescriptionElementBase element
;
64 private IUndoContext undoContext
;
66 private static final String EMPTY_NAME_PROMPT
= "Click to add descriptive element text";
68 public DescriptionElementComposite(Composite parent
, IManagedForm managedForm
,
69 DescriptionElementBase element
) {
70 super(parent
, managedForm
);
72 this.element
= element
;
74 this.undoContext
= EditorController
.getUndoContext(taxon
);
77 createBorderSupport();
78 createLineWrapSupport();
81 createEmptyViewerPrompt(EMPTY_NAME_PROMPT
);
83 setIsDraggable(false);
84 setIcon(BLACK_SQUARE_ICON
);
85 setFont(getViewerFont());
92 private void initTextViewer() {
95 if (element
instanceof TextData
) {
96 text
= ((TextData
) element
).getText(Language
.DEFAULT());
102 textViewer
.getTextWidget().setText(text
);
105 public DescriptionElementBase
getElement() {
109 protected void parse(String text
) {
111 if (getElement() instanceof TextData
) {
112 ((TextData
) getElement()).putText(text
, Language
.DEFAULT());
118 private void createMenu() {
119 ContextMenu contextMenu
= createContextMenu();
121 // Delete this description element
122 String text
= "Delete description element";
123 ImageDescriptor image
= TaxEditorPlugin
.getDefault()
124 .getImageDescriptor(ITaxEditorConstants
.ACTIVE_DELETE_ICON
);
125 contextMenu
.addAction(new Action(text
, image
){
128 IUndoableOperation operation
= new RemoveElementOperation
129 (this.getText(), undoContext
, taxon
, element
);
131 GlobalController
.executeOperation(operation
);
137 public IPropertySource
getPropertySource() {
138 return new DescriptionElementPropertySource(getElement());
142 protected Font
getViewerFont() {
146 public Object
getData () {