Project

General

Profile

Download (6.22 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.taxon;
10

    
11
import org.eclipse.jface.util.PropertyChangeEvent;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.ui.IEditorInput;
14

    
15
import eu.etaxonomy.cdm.model.reference.Reference;
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
17
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
18
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
19
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
20
import eu.etaxonomy.taxeditor.store.StoreUtil;
21
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
24
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
29
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
30
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
31

    
32
/**
33
 * @author n.hoffmann
34
 * @date Dec 1, 2011
35
 *
36
 */
37
public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
38

    
39
	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
40

    
41
	private EntitySelectionElement<Taxon> selection_relatedTaxon;
42
	private CheckboxElement checkBoxDoubtful;
43
	protected ToggleableTextElement toggleable_cache;
44
	private  EntitySelectionElement<Reference> secReference;
45
	private  EntitySelectionElement<Reference> sensuReference;
46
	private TextWithLabelElement text_sensu_microreference;
47

    
48

    
49
	private TextWithLabelElement text_secundum_microreference;
50

    
51
	private TextWithLabelElement text_appendedPhrase;
52
	private TaxonDetailSection taxonElement;
53

    
54

    
55

    
56
	private Taxon taxon;
57

    
58
	public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
59
			ICdmFormElement formElement) {
60
		super(formFactory, formElement);
61

    
62

    
63
	}
64

    
65
	@Override
66
	protected void createControls(ICdmFormElement formElement,
67
			TaxonRelationship entity, int style) {
68
		if (!entity.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
69
			combo_taxonRelationshipType = formFactory.createTermComboElement(
70
					TaxonRelationshipTypeInverseContainer.class,
71
					formElement, "Relationship Type",
72
					getTaxonRelationshipTypeInverseContainer(), style);
73
			combo_taxonRelationshipType.setEnabled(false);
74
			selection_relatedTaxon = formFactory.createSelectionElement(
75
					Taxon.class, getConversationHolder(),
76
					formElement, "Related Taxon", getRelatedTaxon(),
77
					EntitySelectionElement.SELECTABLE, style);
78
			checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation is doubtful", entity.isDoubtful(), style);
79
		}else{
80
			taxon = entity.getFromTaxon();
81
			taxonElement = formFactory.createTaxonDetailSection(getConversationHolder(), formElement, null, style);
82
			taxonElement.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
83
			addControl(taxonElement);
84
			addElement(taxonElement);
85

    
86
			sensuReference = formFactory.createSelectionElement(Reference.class,
87
				getConversationHolder(), formElement, "Sensu",
88
				taxon.getSec(), EntitySelectionElement.ALL,
89
				style);
90

    
91
			text_sensu_microreference = formFactory.createTextWithLabelElement(
92
					formElement, "Detail",
93
					taxon.getSecMicroReference(),null,
94
					SWT.WRAP);
95

    
96

    
97

    
98

    
99

    
100

    
101
			secReference = formFactory.createSelectionElement(Reference.class,
102
					getConversationHolder(), formElement, "Misappl. Sec.",
103
					entity.getCitation(), EntitySelectionElement.ALL,
104
					style);
105

    
106
			text_secundum_microreference = formFactory.createTextWithLabelElement(
107
		            formElement, "Detail",
108
		            entity.getCitationMicroReference(),null,
109
		            SWT.WRAP);
110

    
111
		}
112

    
113
	}
114

    
115
	private Taxon getRelatedTaxon() {
116
		return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
117
	}
118

    
119
	private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
120
		return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
121
	}
122

    
123
	private Taxon getSourceTaxon(){
124
		IEditorInput editorInput = StoreUtil.getActiveEditorInput();
125
		if(editorInput!=null){
126
		    return editorInput.getAdapter(Taxon.class);
127
		}
128
		return null;
129
	}
130

    
131
	@Override
132
	public void handleEvent(Object eventSource) {
133
		if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
134
			 if (eventSource == secReference) {
135
				getEntity().setCitation(secReference.getSelection());
136
			} else if (eventSource == text_secundum_microreference) {
137
				getEntity().setCitationMicroReference(text_secundum_microreference.getText());
138
			}  else if (eventSource == text_sensu_microreference) {
139
		        taxon.setSecMicroReference(text_sensu_microreference.getText());
140
			}else if (eventSource == sensuReference) {
141
				taxon.setSec(sensuReference.getSelection());
142
			}
143
		}else{
144
			if (eventSource == selection_relatedTaxon){
145
				boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
146
				Taxon relatedTaxon = selection_relatedTaxon.getEntity();
147
				if(inverse){
148
					getEntity().setFromTaxon(relatedTaxon);
149
				}else{
150
					getEntity().setToTaxon(relatedTaxon);
151
				}
152
			}else if(eventSource==checkBoxDoubtful){
153
			    getEntity().setDoubtful(checkBoxDoubtful.getSelection());
154
			}
155
		}
156
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
157
	}
158

    
159

    
160

    
161

    
162
	 @Override
163
	    protected void updateControlStates() {
164
	        super.updateControlStates();
165

    
166
	    }
167
	 @Override
168
	 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
169
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
170
			String title = taxon.generateTitle();
171
			taxon.setTitleCache(title);
172
			super.handleTitleCacheRelevantChange(event);
173
		 }
174
	 }
175

    
176
	@Override
177
	public void refresh(){
178
		 updateContent();
179

    
180
	 }
181

    
182
	@Override
183
	public void setEntity(TaxonRelationship entity) {
184
		super.setEntity(entity);
185
		if (taxonElement!=null) {
186
			taxonElement.setEntity(entity.getFromTaxon());
187
        }
188

    
189
	}
190

    
191
}
(8-8/10)