change sec reference micro reference to detail
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / agent / TeamMemberElement.java
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 private final boolean isNomenclatural;
33
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;
39
40 }
41
42 /** {@inheritDoc} */
43 @Override
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,
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 }