Project

General

Profile

Download (2.85 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 org.eclipse.swt.events.SelectionListener;
13

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

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

    
30
	private EntitySelectionElement<Person> selection_person;
31
	private final boolean isNomenclatural;
32

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

    
39
	}
40

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

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

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

    
66
                int index = team.getTeamMembers().indexOf(getEntity());
67

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