Project

General

Profile

Download (1.99 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.taxeditor.editor.name.TaxonNameEditor;
19

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

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

    
36
		createContent();
37
	}
38

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

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

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