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
|
|
14
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
15
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
16
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
18
|
import eu.etaxonomy.taxeditor.event.EventUtility;
|
19
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
20
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.MisappliedRelationshipComboElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
32
|
|
33
|
/**
|
34
|
* @author n.hoffmann
|
35
|
* @date Dec 1, 2011
|
36
|
*
|
37
|
*/
|
38
|
public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
|
39
|
|
40
|
private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
|
41
|
private MisappliedRelationshipComboElement combo_misappliedRelationshipType;
|
42
|
|
43
|
private EntitySelectionElement<Taxon> selection_relatedTaxon;
|
44
|
private CheckboxElement checkBoxDoubtful;
|
45
|
protected ToggleableTextElement toggleable_cache;
|
46
|
private EntitySelectionElement<Reference> secReference;
|
47
|
private EntitySelectionElement<Reference> sensuReference;
|
48
|
private TextWithLabelElement text_sensu_microreference;
|
49
|
|
50
|
|
51
|
private TextWithLabelElement text_secundum_microreference;
|
52
|
|
53
|
private TextWithLabelElement text_appendedPhrase;
|
54
|
|
55
|
private Taxon taxon;
|
56
|
|
57
|
private TaxonDetailSection taxonElement;
|
58
|
|
59
|
public TaxonDetailSection getTaxonElement() {
|
60
|
return taxonElement;
|
61
|
}
|
62
|
|
63
|
public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
|
64
|
ICdmFormElement formElement) {
|
65
|
super(formFactory, formElement);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
protected void createControls(ICdmFormElement formElement,
|
70
|
TaxonRelationship entity, int style) {
|
71
|
if ((entity.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) || entity.getType().equals(TaxonRelationshipType.PRO_PARTE_MISAPPLIED_NAME_FOR())) ){
|
72
|
|
73
|
taxon = entity.getFromTaxon();
|
74
|
|
75
|
taxonElement = formFactory.createTaxonDetailSection(getConversationHolder(), formElement, null, style);
|
76
|
taxonElement.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
77
|
addControl(taxonElement);
|
78
|
addElement(taxonElement);
|
79
|
combo_misappliedRelationshipType = formFactory.createMisappliedRelationshipComboElement(formElement, "Relationship Type",
|
80
|
entity.getType(), style);
|
81
|
|
82
|
combo_misappliedRelationshipType.setEnabled(true);
|
83
|
|
84
|
sensuReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
85
|
formElement, "Sensu",
|
86
|
taxon.getSec(), EntitySelectionElement.ALL,
|
87
|
style);
|
88
|
|
89
|
text_sensu_microreference = formFactory.createTextWithLabelElement(
|
90
|
formElement, "Detail",
|
91
|
taxon.getSecMicroReference(),null,
|
92
|
SWT.WRAP);
|
93
|
|
94
|
secReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
95
|
formElement, "Misappl. Sec.",
|
96
|
entity.getCitation(), EntitySelectionElement.ALL,
|
97
|
style);
|
98
|
|
99
|
text_secundum_microreference = formFactory.createTextWithLabelElement(
|
100
|
formElement, "Detail",
|
101
|
entity.getCitationMicroReference(),null,
|
102
|
SWT.WRAP);
|
103
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, "Misapplication Doubtful", entity.isDoubtful(), style);
|
104
|
}else if ((entity.getType().equals(TaxonRelationshipType.PRO_PARTE_SYNONYM_FOR()) || entity.getType().equals(TaxonRelationshipType.PARTIAL_SYNONYM_FOR())) ){
|
105
|
taxon = entity.getFromTaxon();
|
106
|
|
107
|
taxonElement = formFactory.createTaxonDetailSection(getConversationHolder(), formElement, null, style);
|
108
|
taxonElement.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
109
|
addControl(taxonElement);
|
110
|
addElement(taxonElement);
|
111
|
combo_misappliedRelationshipType = formFactory.createMisappliedRelationshipComboElement(formElement, "Relationship Type",
|
112
|
entity.getType(), style);
|
113
|
|
114
|
combo_misappliedRelationshipType.setEnabled(true);
|
115
|
|
116
|
sensuReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
117
|
formElement, "Sensu",
|
118
|
taxon.getSec(), EntitySelectionElement.ALL,
|
119
|
style);
|
120
|
|
121
|
text_sensu_microreference = formFactory.createTextWithLabelElement(
|
122
|
formElement, "Detail",
|
123
|
taxon.getSecMicroReference(),null,
|
124
|
SWT.WRAP);
|
125
|
|
126
|
secReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
127
|
formElement, "Syn Sec.",
|
128
|
entity.getCitation(), EntitySelectionElement.ALL,
|
129
|
style);
|
130
|
|
131
|
text_secundum_microreference = formFactory.createTextWithLabelElement(
|
132
|
formElement, "Detail",
|
133
|
entity.getCitationMicroReference(),null,
|
134
|
SWT.WRAP);
|
135
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, "PP Doubtful", entity.isDoubtful(), style);
|
136
|
|
137
|
}else{
|
138
|
combo_taxonRelationshipType = formFactory.createTermComboElement(
|
139
|
TaxonRelationshipTypeInverseContainer.class,
|
140
|
formElement, "Relationship Type",
|
141
|
getTaxonRelationshipTypeInverseContainer(), style);
|
142
|
|
143
|
combo_taxonRelationshipType.setEnabled(false);
|
144
|
selection_relatedTaxon = formFactory.createSelectionElement(
|
145
|
Taxon.class, //getConversationHolder(),
|
146
|
formElement, "Related Taxon", getRelatedTaxon(),
|
147
|
EntitySelectionElement.SELECTABLE, style);
|
148
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation Doubtful", entity.isDoubtful(), style);
|
149
|
|
150
|
|
151
|
}
|
152
|
|
153
|
}
|
154
|
|
155
|
private Taxon getRelatedTaxon() {
|
156
|
return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
|
157
|
}
|
158
|
|
159
|
private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
|
160
|
return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
|
161
|
}
|
162
|
|
163
|
private Taxon getSourceTaxon(){
|
164
|
return EventUtility.getCurrentTaxon();
|
165
|
}
|
166
|
|
167
|
@Override
|
168
|
public void handleEvent(Object eventSource) {
|
169
|
if (getEntity().getType().isAnyMisappliedName() || getEntity().getType().isAnySynonym()){
|
170
|
if (eventSource == secReference) {
|
171
|
getEntity().setCitation(secReference.getSelection());
|
172
|
} else if (eventSource == text_secundum_microreference) {
|
173
|
getEntity().setCitationMicroReference(text_secundum_microreference.getText());
|
174
|
} else if (eventSource == text_sensu_microreference) {
|
175
|
taxon.setSecMicroReference(text_sensu_microreference.getText());
|
176
|
} else if (eventSource == sensuReference) {
|
177
|
taxon.setSec(sensuReference.getSelection());
|
178
|
} else if (eventSource == combo_taxonRelationshipType ) {
|
179
|
getEntity().setType(combo_taxonRelationshipType.getSelection().getType());
|
180
|
} else if ( eventSource == combo_misappliedRelationshipType) {
|
181
|
getEntity().setType(combo_misappliedRelationshipType.getSelection());
|
182
|
}
|
183
|
}else{
|
184
|
if (eventSource == selection_relatedTaxon){
|
185
|
boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
|
186
|
Taxon relatedTaxon = selection_relatedTaxon.getEntity();
|
187
|
if(inverse){
|
188
|
getEntity().setFromTaxon(relatedTaxon);
|
189
|
}else{
|
190
|
getEntity().setToTaxon(relatedTaxon);
|
191
|
}
|
192
|
}
|
193
|
}
|
194
|
if(eventSource==checkBoxDoubtful){
|
195
|
getEntity().setDoubtful(checkBoxDoubtful.getSelection());
|
196
|
}
|
197
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
198
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, getEntity().getToTaxon());
|
199
|
}
|
200
|
|
201
|
@Override
|
202
|
protected void updateControlStates() {
|
203
|
super.updateControlStates();
|
204
|
|
205
|
}
|
206
|
@Override
|
207
|
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
|
208
|
if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
|
209
|
String title = taxon.generateTitle();
|
210
|
taxon.setTitleCache(title);
|
211
|
super.handleTitleCacheRelevantChange(event);
|
212
|
}
|
213
|
}
|
214
|
|
215
|
@Override
|
216
|
public void refresh(){
|
217
|
updateContent();
|
218
|
|
219
|
}
|
220
|
|
221
|
@Override
|
222
|
public void setEntity(TaxonRelationship entity) {
|
223
|
super.setEntity(entity);
|
224
|
if (taxonElement!=null) {
|
225
|
taxonElement.setEntity(entity.getFromTaxon());
|
226
|
}
|
227
|
|
228
|
}
|
229
|
|
230
|
|
231
|
|
232
|
}
|