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