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