Project

General

Profile

Download (2.67 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
package eu.etaxonomy.taxeditor.ui.section.agent;
10

    
11
import org.eclipse.swt.events.SelectionListener;
12

    
13
import eu.etaxonomy.cdm.model.agent.Person;
14
import eu.etaxonomy.cdm.model.agent.Team;
15
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
18
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
19
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
20
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
21

    
22
/**
23
 * @author n.hoffmann
24
 * @created Apr 30, 2010
25
 */
26
public class TeamMemberElement extends AbstractEntityCollectionElement<Person> {
27

    
28
	private EntitySelectionElement<Person> selection_person;
29

    
30
	public TeamMemberElement(CdmFormFactory cdmFormFactory,
31
			AbstractFormSection section, Person entity,
32
			SelectionListener removeListener, int style, boolean isNomenclatural) {
33
		super(cdmFormFactory, section, entity, removeListener, null, style);
34
	}
35

    
36
	@Override
37
	public void createControls(ICdmFormElement element, int style) {
38
		selection_person = formFactory
39
				.createSelectionElement(Person.class,
40
				        this, "Person", null,
41
						EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE,
42
						style);
43
	}
44

    
45
	@Override
46
	public void setEntity(Person entity) {
47
		this.entity = entity;
48
		selection_person.setEntity(entity);
49
	}
50

    
51
    @Override
52
    public void handleEvent(Object eventSource) {
53
        if (eventSource == selection_person) {
54
            if (getParentElement() instanceof TeamMemberSection) {
55
                TeamMemberSection teamMemberSection = (TeamMemberSection) getParentElement();
56
                Team team = teamMemberSection.getEntity();
57

    
58
                int index = team.getTeamMembers().indexOf(getEntity());
59

    
60
                if(index==-1){
61
                    team.addTeamMember(selection_person.getEntity());
62
                }
63
                else{
64
                    //first remove the edited team member and then add it again
65
                    //because the model allows the same person multiple time in one team
66
                    team.removeTeamMember(getEntity());
67
                    team.addTeamMember(selection_person.getEntity(), index);
68
                }
69
                firePropertyChangeEvent(new CdmPropertyChangeEvent(teamMemberSection, eventSource));
70
            }
71
            entity = selection_person.getEntity();
72
        }
73
    }
74
}
(9-9/12)