Project

General

Profile

Download (2.75 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
		if (entity != null){
44
			setEntity(entity);
45
		}
46
	}
47

    
48
	@Override
49
	public void setEntity(Person entity) {
50
		this.entity = entity;
51
		if (selection_person != null){
52
			selection_person.setEntity(entity);
53
		}
54
	}
55

    
56
    @Override
57
    public void handleEvent(Object eventSource) {
58
        if (eventSource == selection_person) {
59
            if (getParentElement() instanceof TeamMemberSection) {
60
                TeamMemberSection teamMemberSection = (TeamMemberSection) getParentElement();
61
                Team team = teamMemberSection.getEntity();
62

    
63
                int index = team.getTeamMembers().indexOf(getEntity());
64

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