ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / classification / TaxonNodeAgentRelationCollectionElement.java
1 /**
2 * Copyright (C) 2016 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 package eu.etaxonomy.taxeditor.ui.section.classification;
10
11 import org.eclipse.swt.events.SelectionListener;
12 import org.eclipse.swt.graphics.Color;
13
14 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
15 import eu.etaxonomy.cdm.model.common.DefinedTerm;
16 import eu.etaxonomy.cdm.model.common.TermType;
17 import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
18 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
19 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
20 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.element.LabelElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
24 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
25
26 /**
27 * @author k.luther
28 * @date 22.03.2016
29 *
30 */
31 public class TaxonNodeAgentRelationCollectionElement extends AbstractEntityCollectionElement<TaxonNodeAgentRelation> {
32
33
34 /**
35 * @param formFactory
36 * @param section
37 * @param entity
38 * @param removeListener
39 * @param backgroundColor
40 * @param style
41 */
42 public TaxonNodeAgentRelationCollectionElement(CdmFormFactory formFactory, AbstractFormSection section,
43 TaxonNodeAgentRelation entity, SelectionListener removeListener, Color backgroundColor, int style) {
44 super(formFactory, section, entity, removeListener, backgroundColor, style);
45 }
46
47
48
49
50 private EntitySelectionElement<TeamOrPersonBase> selection_toPerson;
51 private TermComboElement<DefinedTerm> combo_relationshipType;
52 private LabelElement label;
53
54
55
56 @Override
57 public void setEntity(TaxonNodeAgentRelation entity) {
58
59 if(entity.getId()!=0){
60 combo_relationshipType.setSelection(entity.getType());
61 selection_toPerson.setEntity(entity.getAgent());
62 }
63 this.entity = entity;
64 }
65
66 @Override
67 public void handleEvent(Object eventSource) {
68 if(eventSource==combo_relationshipType){
69
70 entity.setType(combo_relationshipType.getSelection());
71
72 }else if (eventSource == selection_toPerson){
73 entity.setAgent(selection_toPerson.getEntity());
74 }
75 }
76
77 @Override
78 public void createControls(ICdmFormElement element, int style) {
79 combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.TaxonNodeAgentRelationType, element, "Relation type", null, style);
80 if (entity != null){
81 selection_toPerson = formFactory
82 .createSelectionElement(TeamOrPersonBase.class,
83 getConversationHolder(), element, "Agent", entity.getAgent(),
84 EntitySelectionElement.ALL, style);
85 } else{
86 selection_toPerson = formFactory
87 .createSelectionElement(TeamOrPersonBase.class,
88 getConversationHolder(), element, "Agent", null,
89 EntitySelectionElement.ALL, style);
90 }
91 label = formFactory.createLabel(element, null);
92
93 }
94
95 public boolean isComplete(){
96 if (selection_toPerson.getSelection()!= null && combo_relationshipType.getSelection() != null){
97 return true;
98 }
99 return false;
100
101 }
102
103 }