3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.agent
;
13 import org
.eclipse
.swt
.events
.SelectionListener
;
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
;
26 * @created Apr 30, 2010
29 public class TeamMemberElement
extends AbstractEntityCollectionElement
<Person
> {
31 private EntitySelectionElement
<Person
> selection_person
;
32 private final boolean isNomenclatural
;
34 public TeamMemberElement(CdmFormFactory cdmFormFactory
,
35 AbstractFormSection section
, Person entity
,
36 SelectionListener removeListener
, int style
, boolean isNomenclatural
) {
37 super(cdmFormFactory
, section
, entity
, removeListener
, null, style
);
38 this.isNomenclatural
=isNomenclatural
;
44 public void createControls(ICdmFormElement element
, int style
) {
45 selection_person
= formFactory
46 .createSelectionElement(Person
.class,
47 getConversationHolder(), this, "Person", null,
48 EntitySelectionElement
.EDITABLE
| EntitySelectionElement
.SELECTABLE
,
54 public void setEntity(Person entity
) {
56 selection_person
.setEntity(entity
);
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();
67 int index
= team
.getTeamMembers().indexOf(getEntity());
70 team
.addTeamMember(selection_person
.getEntity());
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
);
78 firePropertyChangeEvent(new CdmPropertyChangeEvent(teamMemberSection
, eventSource
));
80 entity
= selection_person
.getEntity();