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(),
|
47
|
this, "Person", null,
|
48
|
EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE,
|
49
|
style);
|
50
|
}
|
51
|
|
52
|
/** {@inheritDoc} */
|
53
|
@Override
|
54
|
public void setEntity(Person entity) {
|
55
|
this.entity = entity;
|
56
|
selection_person.setEntity(entity);
|
57
|
}
|
58
|
|
59
|
/** {@inheritDoc} */
|
60
|
@Override
|
61
|
public void handleEvent(Object eventSource) {
|
62
|
if (eventSource == selection_person) {
|
63
|
if (getParentElement() instanceof TeamMemberSection) {
|
64
|
TeamMemberSection teamMemberSection = (TeamMemberSection) getParentElement();
|
65
|
Team team = teamMemberSection.getEntity();
|
66
|
|
67
|
int index = team.getTeamMembers().indexOf(getEntity());
|
68
|
|
69
|
if(index==-1){
|
70
|
team.addTeamMember(selection_person.getEntity());
|
71
|
}
|
72
|
else{
|
73
|
//first remove the edited team member and then add it again
|
74
|
//because the model allows the same person multiple time in on team
|
75
|
team.removeTeamMember(getEntity());
|
76
|
team.addTeamMember(selection_person.getEntity(), index);
|
77
|
}
|
78
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(teamMemberSection, eventSource));
|
79
|
}
|
80
|
entity = selection_person.getEntity();
|
81
|
}
|
82
|
}
|
83
|
}
|