Project

General

Profile

Download (2.2 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.hibernate.HibernateProxyHelper;
17
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
18
import eu.etaxonomy.cdm.model.taxon.Synonym;
19
import eu.etaxonomy.cdm.model.taxon.Taxon;
20
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
21

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

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

    
38
		createContent();
39
	}
40

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

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

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