Project

General

Profile

Download (2.06 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.editor.name.container;
12

    
13
import java.util.ArrayList;
14
import java.util.List;
15

    
16
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
17
import eu.etaxonomy.cdm.model.taxon.Synonym;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
20

    
21
/**
22
 * @author n.hoffmann
23
 * @created Jan 21, 2011
24
 * @version 1.0
25
 */
26
public abstract class AbstractHomotypicalGroupContainer extends AbstractGroup {
27

    
28
	private HomotypicalGroup group;
29
	
30
	/**
31
	 * @param editor
32
	 */
33
	public AbstractHomotypicalGroupContainer(TaxonNameEditor editor, HomotypicalGroup group) {
34
		super(editor);
35
		this.group = group;
36

    
37
		createContent();
38
	}
39

    
40
	protected abstract void createSynonymContainer();
41
	
42
	protected List<Synonym> getSynonyms(){
43
		Taxon taxon = getEditor().getTaxon();
44
		return taxon.getSynonymsInGroup(getGroup());
45
	}
46
	
47
	/**
48
	 * @param group the group to set
49
	 */
50
	public void setGroup(HomotypicalGroup group) {
51
		this.group = group;
52
	}
53

    
54
	public void redraw(HomotypicalGroup homotypicalGroup){
55
		if(redrawNeeded(homotypicalGroup)){
56
			setGroup(homotypicalGroup);
57
			redraw();
58
		}
59
	}
60

    
61
	/**
62
	 * 
63
	 * @param homotypicalGroup
64
	 * @return
65
	 */
66
	protected boolean redrawNeeded(HomotypicalGroup homotypicalGroup) {
67
		Taxon taxon = getEditor().getTaxon();
68
		List<Synonym> synonyms = taxon.getSynonymsInGroup(homotypicalGroup);
69
		
70
		List<Synonym> presentSynonyms = new ArrayList<Synonym>();
71
		
72
		for(AbstractGroupedContainer container : getGroupedContainers()){
73
			if(container.getData() instanceof Synonym){
74
				presentSynonyms.add((Synonym) container.getData());
75
			}
76
		}
77
				
78
		boolean result = ! (presentSynonyms.containsAll(synonyms) && synonyms.containsAll(presentSynonyms));
79
		
80
		return result;
81
	}
82
	
83
	/**
84
	 * @return the group
85
	 */
86
	public HomotypicalGroup getGroup() {
87
		return group;
88
	}
89
}
(3-3/19)