Project

General

Profile

Download (8.04 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 java.util.Arrays;
12

    
13
import org.eclipse.jface.util.PropertyChangeEvent;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.ui.IEditorInput;
16

    
17
import eu.etaxonomy.cdm.model.reference.Reference;
18
import eu.etaxonomy.cdm.model.taxon.Synonym;
19
import eu.etaxonomy.cdm.model.taxon.SynonymType;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
24
import eu.etaxonomy.taxeditor.store.StoreUtil;
25
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
26
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
27
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
28
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
29
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
31
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
32
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
33
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
34
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
35
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
36

    
37
/**
38
 * @author n.hoffmann
39
 * @date Dec 1, 2011
40
 *
41
 */
42
public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
43

    
44
	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
45
	
46
	private EntitySelectionElement<Taxon> selection_relatedTaxon;
47
	private CheckboxElement checkBoxDoubtful;
48
	 protected ToggleableTextElement toggleable_cache;
49
	private  EntitySelectionElement<Reference> secReference;
50
	private  EntitySelectionElement<Reference> sensuReference;
51
	private TextWithLabelElement text_sensu_microreference;
52
	private CheckboxElement checkbox_doubtful;
53

    
54
	private TextWithLabelElement text_secundum_microreference;
55

    
56
	private TextWithLabelElement text_appendedPhrase;
57

    
58
	private CheckboxElement checkbox_published;
59
	
60
	private SelectionArbitrator selectionArbitrator;
61
	
62

    
63
	private Taxon taxon; 
64

    
65
	public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
66
			ICdmFormElement formElement) {
67
		super(formFactory, formElement);
68
		
69
	}
70

    
71
	@Override
72
	protected void createControls(ICdmFormElement formElement,
73
			TaxonRelationship entity, int style) {
74
		if (!entity.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
75
			combo_taxonRelationshipType = formFactory.createTermComboElement(
76
					TaxonRelationshipTypeInverseContainer.class, 
77
					formElement, "Relationship Type", 
78
					getTaxonRelationshipTypeInverseContainer(), style);
79
			combo_taxonRelationshipType.setEnabled(false);
80
			selection_relatedTaxon = formFactory.createSelectionElement(
81
					Taxon.class, getConversationHolder(), 
82
					formElement, "Related Taxon", getRelatedTaxon(), 
83
					EntitySelectionElement.SELECTABLE, style);
84
			checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation is doubtful", entity.isDoubtful(), style);
85
		}else{
86
			taxon = entity.getFromTaxon();
87
			toggleable_cache = formFactory.createToggleableTextField(formElement,
88
					"Title Cache", taxon.getTitleCache(),
89
					taxon.isProtectedTitleCache(), style);
90
	
91
			text_appendedPhrase = formFactory.createTextWithLabelElement(
92
					formElement, "Appended Phrase", taxon.getAppendedPhrase(),
93
					SWT.WRAP);
94
	
95
	
96
			sensuReference = formFactory.createSelectionElement(Reference.class,
97
				getConversationHolder(), formElement, "Sensu",
98
				taxon.getSec(), EntitySelectionElement.ALL,
99
				style);
100
	
101
			text_sensu_microreference = formFactory.createTextWithLabelElement(
102
					formElement, "Detail",
103
					taxon.getSecMicroReference(),null,
104
					SWT.WRAP);
105
	
106
			
107
		
108
		
109
			checkbox_published = formFactory.createCheckbox(formElement,
110
						"Published", taxon.isPublish(), style);
111
				
112
				
113
			secReference = formFactory.createSelectionElement(Reference.class,
114
					getConversationHolder(), formElement, "Misappl. Sec.",
115
					entity.getCitation(), EntitySelectionElement.ALL,
116
					style);
117
		
118
			text_secundum_microreference = formFactory.createTextWithLabelElement(
119
		            formElement, "Detail",
120
		            entity.getCitationMicroReference(),null,
121
		            SWT.WRAP);
122
			checkbox_doubtful = formFactory.createCheckbox(formElement,
123
					"Misappl. Doubtful", entity.isDoubtful(), style);
124
		}
125
		
126
	}
127
	
128
	private Taxon getRelatedTaxon() {
129
		return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
130
	}
131

    
132
	private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
133
		return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
134
	}
135
	
136
	private Taxon getSourceTaxon(){
137
		IEditorInput editorInput = StoreUtil.getActiveEditorInput();
138
		return (Taxon) editorInput.getAdapter(Taxon.class);
139
	}
140

    
141
	@Override
142
	public void handleEvent(Object eventSource) {
143
		if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
144
			if (eventSource== toggleable_cache) {
145
				handleToggleableCacheField();
146
			} else if (eventSource == checkbox_doubtful) {
147
				taxon.setDoubtful(checkbox_doubtful.getSelection());
148
			}  else if (eventSource == secReference) {
149
				getEntity().setCitation(secReference.getSelection());
150
			} else if (eventSource == text_appendedPhrase) {
151
				taxon.setAppendedPhrase(text_appendedPhrase.getText());
152
			} else if (eventSource == text_secundum_microreference) {
153
				getEntity().setCitationMicroReference(text_secundum_microreference.getText());
154
			} else if (eventSource == checkbox_published) {
155
			    taxon.setPublish(checkbox_published.getSelection());
156
			} else if (eventSource == text_sensu_microreference) {
157
		        taxon.setSecMicroReference(text_sensu_microreference.getText());
158
			}else if (eventSource == sensuReference) {
159
				taxon.setSec(sensuReference.getSelection());
160
			}
161
		}else{
162
			if (eventSource == selection_relatedTaxon){
163
				boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
164
				Taxon relatedTaxon = selection_relatedTaxon.getEntity();
165
				if(inverse){
166
					getEntity().setFromTaxon(relatedTaxon);
167
				}else{
168
					getEntity().setToTaxon(relatedTaxon);
169
				}
170
			}else if(eventSource==checkBoxDoubtful){
171
			    getEntity().setDoubtful(checkBoxDoubtful.getSelection());
172
			}
173
		}	
174
		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
175
	}
176
	
177
	protected void handleToggleableCacheField() {
178
        boolean pushedState = toggleable_cache.getState();
179

    
180
        taxon.setTitleCache(toggleable_cache.getText(), pushedState);
181
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
182
        updateToggleableCacheField();
183
    }
184
	
185
	 public void updateToggleableCacheField() {
186
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
187
	        if (toggleable_cache != null){
188
	            if (!taxon.isProtectedTitleCache()) {
189
	                toggleable_cache.setText(taxon.generateTitle());
190
	            }
191
	        }
192
		 }
193
	    }
194
	 
195
	 @Override
196
		protected void updateContent() {
197
		 super.updateContent();
198
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
199
			
200
			toggleable_cache.setEnabled(taxon.isProtectedTitleCache());
201
			setIrrelevant(toggleable_cache.getState(),
202
					Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
203
		 }
204
		}
205
	 @Override
206
	    protected void updateControlStates() {
207
	        super.updateControlStates();
208
	       
209
	    }
210
	 @Override
211
	 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
212
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
213
			String title = taxon.generateTitle();
214
			taxon.setTitleCache(title);
215
			super.handleTitleCacheRelevantChange(event);
216
		 }
217
	 }
218
	 
219
	@Override
220
	public void refresh(){
221
		 updateContent();
222
		 updateToggleableCacheField();
223
	 }
224

    
225
	
226
	
227
	
228
}
(6-6/8)