Project

General

Profile

Download (2.83 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 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.taxon;
11

    
12
import org.eclipse.ui.IEditorInput;
13

    
14
import eu.etaxonomy.cdm.model.taxon.Taxon;
15
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
16
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
17
import eu.etaxonomy.taxeditor.store.StoreUtil;
18
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
21
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
23
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
24

    
25
/**
26
 * @author n.hoffmann
27
 * @date Dec 1, 2011
28
 *
29
 */
30
public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
31

    
32
	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
33
	
34
	private EntitySelectionElement<Taxon> selection_relatedTaxon;
35
	
36
	public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
37
			ICdmFormElement formElement) {
38
		super(formFactory, formElement);
39
	}
40

    
41
	@Override
42
	protected void createControls(ICdmFormElement formElement,
43
			TaxonRelationship entity, int style) {
44
		combo_taxonRelationshipType = formFactory.createTermComboElement(
45
				TaxonRelationshipTypeInverseContainer.class, 
46
				formElement, "Relationship Type", 
47
				getTaxonRelationshipTypeInverseContainer(), style);
48
		combo_taxonRelationshipType.setEnabled(false);
49
		selection_relatedTaxon = formFactory.createSelectionElement(
50
				Taxon.class, getConversationHolder(), 
51
				formElement, "Related Taxon", getRelatedTaxon(), 
52
				EntitySelectionElement.SELECTABLE, style);
53
	}
54
	
55
	private Taxon getRelatedTaxon() {
56
		return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
57
	}
58

    
59
	private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
60
		return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
61
	}
62
	
63
	private Taxon getSourceTaxon(){
64
		IEditorInput editorInput = StoreUtil.getActiveEditorInput();
65
		return (Taxon) editorInput.getAdapter(Taxon.class);
66
	}
67

    
68
	@Override
69
	public void handleEvent(Object eventSource) {
70
		if (eventSource == selection_relatedTaxon){
71
			boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
72
			Taxon relatedTaxon = selection_relatedTaxon.getEntity();
73
			if(inverse){
74
				getEntity().setFromTaxon(relatedTaxon);
75
			}else{
76
				getEntity().setToTaxon(relatedTaxon);
77
			}
78
		}
79
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
80
	}
81
}
(6-6/7)