Project

General

Profile

Download (7.94 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.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
21
import eu.etaxonomy.taxeditor.event.EventUtility;
22
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
23
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
27
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
28
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
29
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
30
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
31
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
32
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
33
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
34

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

    
42
	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
43

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

    
52
	private TextWithLabelElement text_secundum_microreference;
53

    
54
	private TextWithLabelElement text_appendedPhrase;
55

    
56
	private CheckboxElement checkbox_published;
57

    
58
	private SelectionArbitrator selectionArbitrator;
59

    
60

    
61
	private Taxon taxon;
62

    
63
	public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
64
			ICdmFormElement formElement) {
65
		super(formFactory, formElement);
66

    
67
	}
68

    
69
	@Override
70
	protected void createControls(ICdmFormElement formElement,
71
			TaxonRelationship entity, int style) {
72
		if (!entity.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
73
			combo_taxonRelationshipType = formFactory.createTermComboElement(
74
					TaxonRelationshipTypeInverseContainer.class,
75
					formElement, "Relationship Type",
76
					getTaxonRelationshipTypeInverseContainer(), style);
77
			combo_taxonRelationshipType.setEnabled(false);
78
			selection_relatedTaxon = formFactory.createSelectionElement(
79
					Taxon.class, getConversationHolder(),
80
					formElement, "Related Taxon", getRelatedTaxon(),
81
					EntitySelectionElement.SELECTABLE, style);
82
			checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation is doubtful", entity.isDoubtful(), style);
83
		}else{
84
			taxon = entity.getFromTaxon();
85
			toggleable_cache = formFactory.createToggleableTextField(formElement,
86
					"Title Cache", taxon.getTitleCache(),
87
					taxon.isProtectedTitleCache(), style);
88

    
89
			text_appendedPhrase = formFactory.createTextWithLabelElement(
90
					formElement, "Appended Phrase", taxon.getAppendedPhrase(),
91
					SWT.WRAP);
92

    
93

    
94
			sensuReference = formFactory.createSelectionElement(Reference.class,
95
				getConversationHolder(), formElement, "Sensu",
96
				taxon.getSec(), EntitySelectionElement.ALL,
97
				style);
98

    
99
			text_sensu_microreference = formFactory.createTextWithLabelElement(
100
					formElement, "Detail",
101
					taxon.getSecMicroReference(),null,
102
					SWT.WRAP);
103

    
104

    
105

    
106

    
107
			checkbox_published = formFactory.createCheckbox(formElement,
108
						"Published", taxon.isPublish(), style);
109

    
110

    
111
			secReference = formFactory.createSelectionElement(Reference.class,
112
					getConversationHolder(), formElement, "Misappl. Sec.",
113
					entity.getCitation(), EntitySelectionElement.ALL,
114
					style);
115

    
116
			text_secundum_microreference = formFactory.createTextWithLabelElement(
117
		            formElement, "Detail",
118
		            entity.getCitationMicroReference(),null,
119
		            SWT.WRAP);
120
			checkbox_doubtful = formFactory.createCheckbox(formElement,
121
					"Misappl. Doubtful", entity.isDoubtful(), style);
122
		}
123

    
124
	}
125

    
126
	private Taxon getRelatedTaxon() {
127
		return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
128
	}
129

    
130
	private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
131
		return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
132
	}
133

    
134
	private Taxon getSourceTaxon(){
135
	    IEditorInput input = StoreUtil.getActiveEditorInput();
136
	    if(input!=null){
137
	        return input.getAdapter(Taxon.class);
138
	    }
139
		return EventUtility.getCurrentTaxon();
140
	}
141

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

    
178
	protected void handleToggleableCacheField() {
179
        boolean pushedState = toggleable_cache.getState();
180

    
181
        taxon.setTitleCache(toggleable_cache.getText(), pushedState);
182
        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
183
        updateToggleableCacheField();
184
    }
185

    
186
	 public void updateToggleableCacheField() {
187
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
188
	        if (toggleable_cache != null){
189
	            if (!taxon.isProtectedTitleCache()) {
190
	                toggleable_cache.setText(taxon.generateTitle());
191
	            }
192
	        }
193
		 }
194
	    }
195

    
196
	 @Override
197
		protected void updateContent() {
198
		 super.updateContent();
199
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
200

    
201
			toggleable_cache.setEnabled(taxon.isProtectedTitleCache());
202
			setIrrelevant(toggleable_cache.getState(),
203
					Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
204
		 }
205
		}
206
	 @Override
207
	    protected void updateControlStates() {
208
	        super.updateControlStates();
209

    
210
	    }
211
	 @Override
212
	 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
213
		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
214
			String title = taxon.generateTitle();
215
			taxon.setTitleCache(title);
216
			super.handleTitleCacheRelevantChange(event);
217
		 }
218
	 }
219

    
220
	@Override
221
	public void refresh(){
222
		 updateContent();
223
		 updateToggleableCacheField();
224
	 }
225

    
226

    
227

    
228

    
229
}
(6-6/8)