Project

General

Profile

Download (3.31 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.ui.section.agent;
11

    
12
import java.util.Collection;
13
import java.util.Comparator;
14
import java.util.List;
15

    
16
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.agent.Team;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractUnboundEntityCollectionSection;
22

    
23
/**
24
 * <p>TeamMemberSection class.</p>
25
 *
26
 * @author n.hoffmann
27
 * @created Apr 30, 2010
28
 * @version 1.0
29
 */
30
public class TeamMemberSection extends AbstractUnboundEntityCollectionSection<Team, Person> {
31

    
32
    private boolean isNomenclaturalTeam = false;
33

    
34
	/**
35
	 * <p>Constructor for TeamMemberSection.</p>
36
	 *
37
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
38
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
39
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
40
	 * @param style a int.
41
	 */
42
	public TeamMemberSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural) {
43
		super(cdmFormFactory, conversation, parentElement, null, style);
44
		isNomenclaturalTeam = isNomenclatural;
45
	}
46

    
47
	/** {@inheritDoc} */
48
	@Override
49
	public String getTitleString() {
50
		return "Team Members";
51
	}
52

    
53
	/** {@inheritDoc} */
54
	@Override
55
	public void addElement(Person element) {
56
		getEntity().addTeamMember(element);
57
	}
58

    
59
	/** {@inheritDoc} */
60
	@Override
61
	public Person createNewElement() {
62
		return Person.NewTitledInstance("");
63
	}
64

    
65
	/** {@inheritDoc} */
66
	@Override
67
	public String getEmptyString() {
68
		return "No persons yet.";
69
	}
70

    
71
	/** {@inheritDoc} */
72
	@Override
73
	protected String getTooltipString() {
74
		return "Add a member to this team";
75
	}
76

    
77
	/** {@inheritDoc} */
78
	@Override
79
	public void removeElement(Person element) {
80
		getEntity().removeTeamMember(element);
81
	}
82

    
83
    @Override
84
    protected Collection<Person> getEntityCollection(Team entity) {
85
        return getEntity().getTeamMembers();
86
    }
87

    
88
    @Override
89
    public Comparator<Person> getComparator() {
90
        return (p1, p2) -> {
91
            if(p1==null){
92
                return -1;
93
            }
94
            if(p2==null){
95
                return 1;
96
            }
97
            List<Person> teamMembers = getEntity().getTeamMembers();
98
            int indexOfP1 = teamMembers.indexOf(p1);
99
            int indexOfP2 = teamMembers.indexOf(p2);
100
            if(indexOfP1==-1){
101
                return 1;
102
            }
103
            if(indexOfP2==-1){
104
                return -1;
105
            }
106
            return indexOfP1 - indexOfP2;
107
        };
108
    }
109

    
110
    /**
111
     * @return
112
     */
113
    public boolean isNomenclaturalTeam() {
114
       return isNomenclaturalTeam;
115
    }
116

    
117
    /**
118
     * {@inheritDoc}
119
     */
120
    @Override
121
    public Person addExisting() {
122
        return null;
123
    }
124

    
125
    /**
126
     * {@inheritDoc}
127
     */
128
    @Override
129
    public boolean allowAddExisting() {
130
        return false;
131
    }
132

    
133
}
(10-10/12)