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.taxeditor.event.EventUtility;
|
18
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
19
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
20
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.MisappliedRelationshipComboElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.combo.term.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.SelectionArbitrator;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSingleSourceElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
33
|
|
34
|
/**
|
35
|
* @author n.hoffmann
|
36
|
* @date Dec 1, 2011
|
37
|
*
|
38
|
*/
|
39
|
public class TaxonRelationshipDetailElement extends AbstractSingleSourceElement<TaxonRelationship> {//TODO: use AbstractSingleSourcedElement
|
40
|
|
41
|
private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
|
42
|
private MisappliedRelationshipComboElement combo_misappliedRelationshipType;
|
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
|
|
51
|
|
52
|
// private TextWithLabelElement text_secundum_microreference;
|
53
|
|
54
|
private TextWithLabelElement text_appendedPhrase;
|
55
|
|
56
|
private CheckboxElement checkbox_published;
|
57
|
|
58
|
private Taxon taxon;
|
59
|
|
60
|
private TaxonDetailSection taxonElement;
|
61
|
|
62
|
public TaxonDetailSection getTaxonElement() {
|
63
|
return taxonElement;
|
64
|
}
|
65
|
|
66
|
public TaxonRelationshipDetailElement(CdmFormFactory formFactory,
|
67
|
ICdmFormElement formElement) {
|
68
|
|
69
|
super(formFactory, formElement);
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public void createControls(ICdmFormElement formElement,
|
74
|
TaxonRelationship entity, int style) {
|
75
|
if ((entity.getType().isMisappliedNameOrInvalidDesignation()) ){
|
76
|
|
77
|
taxon = entity.getFromTaxon();
|
78
|
|
79
|
taxonElement = formFactory.createTaxonDetailSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(TaxonDetailSection.class, Taxon.class.getCanonicalName()));
|
80
|
taxonElement.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
81
|
addControl(taxonElement);
|
82
|
addElement(taxonElement);
|
83
|
String label;
|
84
|
if (entity.getType().isAnyMisappliedName()) {
|
85
|
label = "Sensu";
|
86
|
}else{
|
87
|
label = "Sec.";
|
88
|
}
|
89
|
text_appendedPhrase = formFactory.createTextWithLabelElement(
|
90
|
this, "Appended Phrase", taxon.getAppendedPhrase(),
|
91
|
SWT.WRAP);
|
92
|
|
93
|
checkbox_published = formFactory.createCheckbox(this,
|
94
|
"Published", taxon.isPublish(), style);
|
95
|
sensuReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
96
|
formElement, label,
|
97
|
taxon.getSec(), EntitySelectionElement.ALL,
|
98
|
style);
|
99
|
|
100
|
text_sensu_microreference = formFactory.createTextWithLabelElement(
|
101
|
formElement, "Detail",
|
102
|
taxon.getSecMicroReference(),null,
|
103
|
SWT.WRAP);
|
104
|
|
105
|
if (entity.getType().isAnyMisappliedName()) {
|
106
|
label = "Misapplication Type";
|
107
|
}else{
|
108
|
label = "Relationship Type";
|
109
|
}
|
110
|
combo_misappliedRelationshipType = formFactory.createMisappliedRelationshipComboElement(formElement, label,
|
111
|
entity.getType(), style);
|
112
|
|
113
|
if (entity.getType().isInvalidDesignation()){
|
114
|
combo_misappliedRelationshipType.setEnabled(false);
|
115
|
}else{
|
116
|
combo_misappliedRelationshipType.setEnabled(true);
|
117
|
}
|
118
|
if (entity.getType().isAnyMisappliedName()) {
|
119
|
label = "Misappl. Sec.";
|
120
|
}else{
|
121
|
label = "Err. Sec.";
|
122
|
}
|
123
|
|
124
|
/*TODO: use super.createControls(); to create single source element
|
125
|
secReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
126
|
formElement, label,
|
127
|
entity.getCitation(), EntitySelectionElement.ALL,
|
128
|
style);
|
129
|
|
130
|
text_secundum_microreference = formFactory.createTextWithLabelElement(
|
131
|
formElement, "Detail",
|
132
|
entity.getCitationMicroReference(),null,
|
133
|
SWT.WRAP);
|
134
|
*/
|
135
|
super.createControls(formElement, entity, style);
|
136
|
setSourceLabel(label);
|
137
|
|
138
|
if (entity.getType().isAnyMisappliedName()) {
|
139
|
label = "Misapplication Doubtful";
|
140
|
}else{
|
141
|
label = "Relationship Doubtful";
|
142
|
}
|
143
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, label, entity.isDoubtful(), style);
|
144
|
}else if (entity.getType().isAnySynonym() ){
|
145
|
taxon = entity.getFromTaxon();
|
146
|
|
147
|
taxonElement = formFactory.createTaxonDetailSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(TaxonDetailSection.class, Taxon.class.getCanonicalName()));
|
148
|
taxonElement.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
149
|
addControl(taxonElement);
|
150
|
addElement(taxonElement);
|
151
|
|
152
|
|
153
|
text_appendedPhrase = formFactory.createTextWithLabelElement(
|
154
|
this, "Appended Phrase", taxon.getAppendedPhrase(),
|
155
|
SWT.WRAP);
|
156
|
|
157
|
checkbox_published = formFactory.createCheckbox(this,
|
158
|
"Published", taxon.isPublish(), style);
|
159
|
/*
|
160
|
* secReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
161
|
|
162
|
formElement, "Syn. Sec.",
|
163
|
entity.getCitation(), EntitySelectionElement.ALL,
|
164
|
style);
|
165
|
|
166
|
text_secundum_microreference = formFactory.createTextWithLabelElement(
|
167
|
formElement, "Detail",
|
168
|
entity.getCitationMicroReference(),null,
|
169
|
SWT.WRAP);
|
170
|
*/
|
171
|
|
172
|
super.createControls(formElement, entity, style);
|
173
|
setSourceLabel("Syn. Sec.");
|
174
|
sensuReference = formFactory.createSelectionElement(Reference.class,//getConversationHolder(),
|
175
|
formElement, "Sec",
|
176
|
taxon.getSec(), EntitySelectionElement.ALL,
|
177
|
style);
|
178
|
|
179
|
text_sensu_microreference = formFactory.createTextWithLabelElement(
|
180
|
formElement, "Detail",
|
181
|
taxon.getSecMicroReference(),null,
|
182
|
SWT.WRAP);
|
183
|
|
184
|
combo_misappliedRelationshipType = formFactory.createMisappliedRelationshipComboElement(formElement, "Synonym Type",
|
185
|
entity.getType(), style);
|
186
|
|
187
|
combo_misappliedRelationshipType.setEnabled(true);
|
188
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, "Syn. Doubtful", entity.isDoubtful(), style);
|
189
|
|
190
|
}else{
|
191
|
combo_taxonRelationshipType = formFactory.createTermComboElement(
|
192
|
TaxonRelationshipTypeInverseContainer.class,
|
193
|
formElement, "Relationship Type",
|
194
|
getTaxonRelationshipTypeInverseContainer(), style);
|
195
|
|
196
|
combo_taxonRelationshipType.setEnabled(false);
|
197
|
selection_relatedTaxon = formFactory.createSelectionElement(
|
198
|
Taxon.class, //getConversationHolder(),
|
199
|
formElement, "Related Taxon", getRelatedTaxon(),
|
200
|
EntitySelectionElement.SELECTABLE, style);
|
201
|
checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation Doubtful", entity.isDoubtful(), style);
|
202
|
|
203
|
|
204
|
}
|
205
|
|
206
|
}
|
207
|
|
208
|
private Taxon getRelatedTaxon() {
|
209
|
return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
|
210
|
}
|
211
|
|
212
|
private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
|
213
|
return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
|
214
|
}
|
215
|
|
216
|
private Taxon getSourceTaxon(){
|
217
|
return EventUtility.getCurrentTaxon();
|
218
|
}
|
219
|
|
220
|
@Override
|
221
|
public void handleEvent(Object eventSource) {
|
222
|
if (getEntity().getType().isMisappliedNameOrInvalidDesignation() || getEntity().getType().isAnySynonym()){
|
223
|
/* if (eventSource == secReference) {
|
224
|
getEntity().setCitation(secReference.getSelection());
|
225
|
} else if (eventSource == text_secundum_microreference) {
|
226
|
getEntity().setCitationMicroReference(text_secundum_microreference.getText());
|
227
|
} else
|
228
|
*/
|
229
|
if (eventSource == text_sensu_microreference) {
|
230
|
taxon.setSecMicroReference(text_sensu_microreference.getText());
|
231
|
} else if (eventSource == sensuReference) {
|
232
|
taxon.setSec(sensuReference.getSelection());
|
233
|
} else if (eventSource == combo_taxonRelationshipType ) {
|
234
|
getEntity().setType(combo_taxonRelationshipType.getSelection().getType());
|
235
|
} else if ( eventSource == combo_misappliedRelationshipType) {
|
236
|
getEntity().setType(combo_misappliedRelationshipType.getSelection());
|
237
|
} else if (eventSource == text_appendedPhrase) {
|
238
|
taxon.setAppendedPhrase(text_appendedPhrase.getText());
|
239
|
} else if (eventSource == checkbox_published) {
|
240
|
taxon.setPublish(checkbox_published.getSelection());
|
241
|
}
|
242
|
}else{
|
243
|
if (eventSource == selection_relatedTaxon){
|
244
|
boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
|
245
|
Taxon relatedTaxon = selection_relatedTaxon.getEntity();
|
246
|
if(inverse){
|
247
|
getEntity().setFromTaxon(relatedTaxon);
|
248
|
}else{
|
249
|
getEntity().setToTaxon(relatedTaxon);
|
250
|
}
|
251
|
}
|
252
|
}
|
253
|
if(eventSource==checkBoxDoubtful){
|
254
|
getEntity().setDoubtful(checkBoxDoubtful.getSelection());
|
255
|
}
|
256
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
257
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, getEntity().getToTaxon());
|
258
|
taxonElement.updateTitle();
|
259
|
}
|
260
|
|
261
|
@Override
|
262
|
protected void updateControlStates() {
|
263
|
super.updateControlStates();
|
264
|
|
265
|
}
|
266
|
@Override
|
267
|
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
|
268
|
if (getEntity().getType().isAnyMisappliedName() || getEntity().getType().isAnySynonym()){
|
269
|
String title = taxon.generateTitle();
|
270
|
taxon.setTitleCache(title);
|
271
|
super.handleTitleCacheRelevantChange(event);
|
272
|
}
|
273
|
}
|
274
|
|
275
|
@Override
|
276
|
public void refresh(){
|
277
|
updateContent();
|
278
|
|
279
|
}
|
280
|
|
281
|
@Override
|
282
|
public void setEntity(TaxonRelationship entity) {
|
283
|
super.setEntity(entity);
|
284
|
if (taxonElement!=null) {
|
285
|
taxonElement.setEntity(entity.getFromTaxon());
|
286
|
}
|
287
|
|
288
|
}
|
289
|
|
290
|
@Override
|
291
|
public SelectionArbitrator getSelectionArbitrator() {
|
292
|
// TODO Auto-generated method stub
|
293
|
return null;
|
294
|
}
|
295
|
|
296
|
|
297
|
|
298
|
}
|