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
;
33 public TeamMemberElement(CdmFormFactory cdmFormFactory
,
34 AbstractFormSection section
, Person entity
,
35 SelectionListener removeListener
, int style
) {
36 super(cdmFormFactory
, section
, entity
, removeListener
, null, style
);
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
,
51 public void setEntity(Person entity
) {
53 selection_person
.setEntity(entity
);
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();
64 int index
= team
.getTeamMembers().indexOf(getEntity());
67 team
.addTeamMember(selection_person
.getEntity());
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
);
75 firePropertyChangeEvent(new CdmPropertyChangeEvent(teamMemberSection
, eventSource
));
77 entity
= selection_person
.getEntity();