Project

General

Profile

Download (2.75 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.ui.section.agent;
12

    
13
import org.eclipse.swt.events.SelectionListener;
14

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

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

    
31
	private EntitySelectionElement<Person> selection_person;
32

    
33
	public TeamMemberElement(CdmFormFactory cdmFormFactory,
34
			AbstractFormSection section, Person entity,
35
			SelectionListener removeListener, int style) {
36
		super(cdmFormFactory, section, entity, removeListener, null, style);
37
	}
38

    
39
	/** {@inheritDoc} */
40
	@Override
41
	public void createControls(ICdmFormElement element, int style) {
42
		selection_person = formFactory
43
				.createSelectionElement(Person.class,
44
						getConversationHolder(), this, "Person", null,
45
						EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE,
46
						style);
47
	}
48

    
49
	/** {@inheritDoc} */
50
	@Override
51
	public void setEntity(Person entity) {
52
		this.entity = entity;
53
		selection_person.setEntity(entity);
54
	}
55

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

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

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