Project

General

Profile

Download (3.59 KB) Statistics
| Branch: | Tag: | Revision:
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.model.MessagingUtils;
24
import eu.etaxonomy.taxeditor.preference.Resources;
25

    
26
/**
27
 * <p>SynonymContainer class.</p>
28
 *
29
 * @author p.ciardelli
30
 * @created 13.01.2009
31
 * @version 1.0
32
 */
33
public class SynonymContainer extends AbstractGroupedContainer<Synonym> {
34

    
35
	private int indent = SYNONYM_INDENT;
36
	private Image icon = HETEROTYPIC_SYNONYM_ICON;
37

    
38
	/**
39
	 * <p>Constructor for SynonymContainer.</p>
40
	 *
41
	 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
42
	 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
43
	 * @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
44
	 */
45
	public SynonymContainer(AbstractHomotypicalGroupContainer group, Synonym synonym) {
46
		super(synonym);
47
	}
48
	
49
	public SynonymContainer(AbstractHomotypicalGroupContainer group, Synonym synonym, int indent, Image icon){
50
		super(synonym);
51
		this.indent = indent;
52
		this.icon = icon;
53
	}
54
	
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
57
	 */
58
	/** {@inheritDoc} */
59
	@Override
60
	protected void initializeComposite() {
61
		setIsDraggable(true);
62
		setFont(getViewerFont());
63
		
64
		if(getName() == null){
65
			MessagingUtils.warn(getClass(), "Synonym with a null name detected. This should never happen.");
66
		}
67
		
68
		initTextViewer();
69
	}
70
	
71
	protected void updateIcon(){
72
		TaxonNameBase name = getName();
73
		
74
		if(! name.getStatus().isEmpty()){
75
			
76
			Set<NomenclaturalStatus> allStatus = name.getStatus();
77
			
78
			for (NomenclaturalStatus status : allStatus){
79
				if(status.getType() != null && (status.getType().equals(NomenclaturalStatusType.INVALID()) || status.getType().equals(NomenclaturalStatusType.NUDUM()))){
80
					setIcon(INVALID_OR_NUDUM_NAME_ICON);
81
					return;
82
				}
83
			}
84
		}
85
		
86
		if (isHomotypic()) {
87
			if(name.isGroupsBasionym()){
88
				setIcon(HOMOTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
89
			}else{
90
				setIcon(HOMOTYPIC_SYNONYM_ICON);
91
			}
92
			
93
			return;
94
		} else{
95
			if(name.isGroupsBasionym()){
96
				setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);
97
				return;
98
			}
99
		}	
100
				
101
		setIcon(icon);
102
		
103
	}
104
	
105
	private boolean isHomotypic() {
106
		HomotypicalGroup group = getSynonym().getHomotypicGroup();
107
		return group.equals(getEditor().getTaxon().getHomotypicGroup()); 
108
	}
109
	
110
	/**
111
	 * <p>getSynonym</p>
112
	 *
113
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
114
	 */
115
	public Synonym getSynonym() {
116
		return getTaxonBase();
117
	}
118
		
119

    
120
	/**
121
	 * <p>getViewerFont</p>
122
	 *
123
	 * @return a {@link org.eclipse.swt.graphics.Font} object.
124
	 */
125
	protected Font getViewerFont() {
126
		return EditorUtil.getFont(Resources.SYNONYM_FONT);
127
	}
128

    
129
	/** {@inheritDoc} */
130
	@Override
131
	protected void updateNonEditableInfo() {
132
		// not needed
133
	}
134

    
135
	/* (non-Javadoc)
136
	 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
137
	 */
138
	@Override
139
	protected void updateIndent() {		
140
		setIndent(this.indent );
141
	}
142
}
(19-19/19)