Fixed a problem with updating views and editors after an import has run; Correcting...
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / SynonymContainer.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.name;
11
12 import java.util.Set;
13
14 import org.eclipse.swt.graphics.Font;
15
16 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
17 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
18 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
19 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
20 import eu.etaxonomy.cdm.model.taxon.Synonym;
21 import eu.etaxonomy.taxeditor.editor.EditorUtil;
22 import eu.etaxonomy.taxeditor.preference.Resources;
23
24 /**
25 * <p>SynonymContainer class.</p>
26 *
27 * @author p.ciardelli
28 * @created 13.01.2009
29 * @version 1.0
30 */
31 public class SynonymContainer extends AbstractGroupedContainer<Synonym> {
32
33 /**
34 * <p>Constructor for SynonymContainer.</p>
35 *
36 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
37 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.AbstractGroup} object.
38 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
39 */
40 public SynonymContainer(TaxonNameEditor editor, AbstractGroup group, Synonym synonym) {
41 super(editor, group, synonym);
42 }
43
44 /* (non-Javadoc)
45 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
46 */
47 /** {@inheritDoc} */
48 @Override
49 protected void initializeComposite() {
50 setIsDraggable(true);
51 setFont(getViewerFont());
52
53 if(getName() == null){
54 EditorUtil.warn(getClass(), "Synonym with a null name detected. This should never happen.");
55 }
56
57 initTextViewer();
58 }
59
60 protected void updateIcon(){
61 TaxonNameBase name = getName();
62
63 if (isHomotypic()) {
64 if (name.isGroupsBasionym()) {
65 setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
66 } else {
67 setIcon(HOMOTYPIC_SYNONYM_ICON);
68 }
69
70 return;
71 }
72
73 if(! name.getStatus().isEmpty()){
74
75 Set<NomenclaturalStatus> allStatus = name.getStatus();
76
77 for (NomenclaturalStatus status : allStatus){
78 if(status.getType() != null && (status.getType().equals(NomenclaturalStatusType.INVALID()) || status.getType().equals(NomenclaturalStatusType.NUDUM()))){
79 setIcon(INVALID_OR_NUDUM_NAME_ICON);
80 return;
81 }
82 }
83 }
84
85 if (name.getHomotypicalGroup().getBasionyms().isEmpty()) {
86 setIcon(HETEROTYPIC_SYNONYM_ICON);
87 }else{
88 if (name.isGroupsBasionym()) {
89 setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
90 } else {
91 setIcon(HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_ICON);
92 }
93 }
94
95
96 }
97
98 private boolean isHomotypic() {
99 HomotypicalGroup group = getSynonym().getHomotypicGroup();
100 return group.equals(editor.getTaxon().getHomotypicGroup());
101 }
102
103 /**
104 * <p>getSynonym</p>
105 *
106 * @return a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
107 */
108 public Synonym getSynonym() {
109 return getTaxonBase();
110 }
111
112
113 /**
114 * <p>getViewerFont</p>
115 *
116 * @return a {@link org.eclipse.swt.graphics.Font} object.
117 */
118 protected Font getViewerFont() {
119 return EditorUtil.getFont(Resources.SYNONYM_FONT);
120 }
121
122 /** {@inheritDoc} */
123 @Override
124 protected void updateNonEditableInfo() {
125 // not needed
126 }
127
128 /* (non-Javadoc)
129 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
130 */
131 @Override
132 protected void updateIndent() {
133 TaxonNameBase name = getName();
134
135 if (!isHomotypic() && !name.getHomotypicalGroup().getBasionyms().isEmpty() && !name.isGroupsBasionym()) {
136 setIndent(HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_INDENT);
137 return;
138 }
139
140 setIndent(SYNONYM_INDENT);
141 }
142 }