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
.name
;
14 import org
.eclipse
.jface
.action
.Action
;
15 import org
.eclipse
.swt
.graphics
.Font
;
16 import org
.eclipse
.swt
.graphics
.Image
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
25 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
27 import eu
.etaxonomy
.taxeditor
.editor
.AbstractTaxonEditor
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.editor
.GroupedComposite
;
30 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
31 import eu
.etaxonomy
.taxeditor
.model
.NameRelationsUtil
;
32 import eu
.etaxonomy
.taxeditor
.model
.NameUtil
;
33 import eu
.etaxonomy
.taxeditor
.model
.Resources
;
34 import eu
.etaxonomy
.taxeditor
.operations
.CreateSynonymInNewGroupOperation
;
35 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.BotanicalNamePropertySource
;
36 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.NonViralNamePropertySource
;
37 import eu
.etaxonomy
.taxeditor
.propertysheet
.name
.ZoologicalNamePropertySource
;
40 * Formats an <code>GroupedComposite</code> to display <code>TaxonNameBase</code> elements
41 * in a <code>NameViewer</code>.
47 public abstract class NameComposite
extends GroupedComposite
{
50 * ************ COMPOSITE TYPES ************
52 public String compositeType
;
53 public static final String ACCEPTED_TAXON
= "accepted_name_composite";
54 public static final String HOMOTYPIC_SYNONYM
= "homotypic_name_composite";
55 public static final String HETEROTYPIC_SYNONYM
= "heterotypic_name_composite";
56 public static final String MISAPPLIED_NAME
= "misappliedname_name_composite";
57 public static final String CONCEPTRELATION
= "concept_name_comcposite";
60 * ************ INDENTATIONS ************
62 public static final int ACCEPTED_INDENT
= 0;
63 public static final int SYNONYM_INDENT
= 15;
64 public static final int MISAPPLIEDNAME_INDENT
= 15;
65 public static final int CONCEPT_INDENT
= 15;
68 * ************ FONTS ************
70 public static final Font ACCEPTED_FONT
= Resources
71 .getFont(Resources
.ACCEPTED_TAXON_FONT
);
72 public static final Font SYNONYM_FONT
= Resources
73 .getFont(Resources
.SYNONYM_FONT
);
74 public static final Font MISAPPLIEDNAME_FONT
= Resources
75 .getFont(Resources
.MISAPPLIEDNAME_FONT
);
76 public static final Font CONCEPT_FONT
= Resources
77 .getFont(Resources
.CONCEPT_FONT
);
80 * ************ ICONS ************
82 public static final Image ACCEPTED_ICON
= ImageResources
83 .getImage(ImageResources
.BLACK_SQUARE_ICON
);
84 public static final Image HOMOTYPIC_SYNONYM_ICON
= ImageResources
.getImage(ImageResources
.HOMOTYPIC_SYN_ICON
);
85 public static final Image HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
= ImageResources
.getImage(
86 ImageResources
.HOMOTYPIC_SYN_ORIGINAL_ICON
);
87 public static final Image HETEROTYPIC_SYNONYM_ICON
= ImageResources
.getImage(ImageResources
.HETEROTYPIC_SYN_ICON
);
88 public static final Image HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON
= ImageResources
.getImage(
89 ImageResources
.HETEROTYPIC_SYN_ORIGINAL_ICON
);
90 public static final Image MISAPPLIEDNAME_ICON
= ImageResources
.getImage(ImageResources
.MISAPPLIED_NAME_ICON
);
91 public static final Image CONCEPT_ICON
= ImageResources
.getImage(ImageResources
.CONCEPT_ICON
);
92 public static final Image AUTONYM_ICON
= ImageResources
93 .getImage(ImageResources
.AUTONYM_ICON
);
94 public static final Image BASIONYM_ICON
= ImageResources
95 .getImage(ImageResources
.BASIONYM_ICON
);
96 public static final Image MOVE
= ImageResources
.getImage(ImageResources
.MOVE_ICON
);
99 * ************ TRANSFORMATIONS ************
101 public static final String ADD_GROUP_BASIONYM
= "add_group_basionym";
102 public static final String REMOVE_GROUP_BASIONYM
= "remove_group_basionym";
105 * ************ MENU ACTIONS ************
107 public Action CHANGE_TAXON_TO_SYNONYM_ACTION
;
109 private static final String EMPTY_NAME_PROMPT
= "Click to add name";
112 * Used to turn parser on and off.
114 * @see activateParser
115 * @see deactivateParser
117 private boolean isUseParser
= false;
119 protected boolean isParsing
;
122 * The constructor for a DescriptionElementComposite. Takes a parent Composite on which to
123 * create itself, and an IManagedForm for Composite life cycle methods, i.e.
124 * drawing borders, creating other Composites, creating line wrap support,
130 public NameComposite(AbstractTaxonEditor editor
, Composite parent
,
131 String compositeType
, TaxonBase
<?
> taxonBase
) {
132 super(editor
, parent
);
135 createBorderSupport();
136 createLineWrapSupport();
137 createLineBreakListener();
139 this.setMenu(editor
.getMenu());
141 setDraggableControl(textViewer
.getRulerControl());
144 createEmptyViewerPrompt(EMPTY_NAME_PROMPT
);
147 protected String
getEmptyTextPrompt() {
148 return EMPTY_NAME_PROMPT
;
154 private void showNameRelations() {
155 TaxonNameBase
<?
, ?
> name
= getName();
159 Set
<NameRelationship
> nameRelations
= name
.getNameRelations();
160 if (nameRelations
.size() == 0) {
163 for (NameRelationship nameRelation
: nameRelations
) {
164 String typeLabel
= null;
165 TaxonNameBase
<?
, ?
> relatedName
= null;
167 boolean isZoological
= name
instanceof ZoologicalName ?
true : false;
169 if (name
.equals(nameRelation
.getFromName())) {
170 typeLabel
= NameRelationsUtil
.getNameRelationTypeLabel(
171 nameRelation
.getType(), isZoological
);
172 relatedName
= nameRelation
.getToName();
174 typeLabel
= NameRelationsUtil
.getNameRelationInverseTypeLabel(
175 nameRelation
.getType(), isZoological
);
176 relatedName
= nameRelation
.getFromName();
179 setNonEditableInfo(typeLabel
+ " " + NameUtil
.getDisplayName(relatedName
));
183 protected void initTextViewer(TaxonBase
<?
> taxonBase
) {
187 String text
= NameUtil
.getDisplayNameWithRef(taxonBase
);
189 if (text
.length() == 0) {
192 textViewer
.getTextWidget().setText(text
);
193 textViewer
.setCursorToEOL();
199 protected void parse(String text
) {
201 // Either composite is not yet fully built, or
202 // the property sheet is writing to it
207 // Let others know the parser is active
210 // Parse the name and paint the text field w any errors
211 if (getName() != null) {
212 // TODO change to HibernateProxyImpl.deproxy() once it is available
213 CdmParserController
.parseFullReference(CdmBase
.deproxy(getName(), NonViralName
.class), text
);
216 // Any entry of text means the taxon has been changed
219 // The parser is no longer active
222 // // Manually refresh the property sheet to reflect changes
225 // Show any errors in the name viewer
229 private void activateParser() {
233 // FIXME we do have a naming conflict here
234 protected abstract TaxonNameBase
<?
, ?
> getName();
236 protected void calculateErrors() {
237 textViewer
.clearErrors();
238 textViewer
.setShowParsingError(getName());
241 protected void handleSplitText(String text
) {
242 // Create a synonym in a new homotypic group using text as name
243 EditorUtil
.executeOperation(new CreateSynonymInNewGroupOperation
244 ("New Heterotypic Synonym", editor
.getUndoContext(), editor
.getTaxon(), text
, editor
));
247 protected IPropertySource
getPropertySourceByName(TaxonNameBase
<?
, ?
> name
) {
252 if (name
.getClass() == BotanicalName
.class) {
253 return new BotanicalNamePropertySource((BotanicalName
) name
);
255 if (name
.getClass() == ZoologicalName
.class) {
256 return new ZoologicalNamePropertySource((ZoologicalName
) name
);
258 if (name
instanceof NonViralName
) {
259 return new NonViralNamePropertySource((NonViralName
<?
>) name
);
266 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#refresh()
269 public void refresh() {
271 // initTextViewer((TaxonBase) getData());
273 // FIXME this is copied from initTextViewer().
277 String text
= NameUtil
.getDisplayNameWithRef((TaxonBase
) getData());
279 if (text
.length() == 0) {
282 textViewer
.getTextWidget().setText(text
);
283 // textViewer.setCursorToEOL();
285 // calculateErrors();
289 public boolean isDirty(){
291 TaxonNameBase
<?
, ?
> name
= getName();