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.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.ISelectableElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
35
|
|
36
|
/**
|
37
|
* @author n.hoffmann
|
38
|
* @date Dec 1, 2011
|
39
|
*
|
40
|
*/
|
41
|
public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
|
42
|
|
43
|
// private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
|
44
|
//
|
45
|
// private EntitySelectionElement<Taxon> selection_relatedTaxon;
|
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
|
// combo_taxonRelationshipType = formFactory.createTermComboElement(
|
73
|
// TaxonRelationshipTypeInverseContainer.class,
|
74
|
// formElement, "Relationship Type",
|
75
|
// getTaxonRelationshipTypeInverseContainer(), style);
|
76
|
// combo_taxonRelationshipType.setEnabled(false);
|
77
|
// selection_relatedTaxon = formFactory.createSelectionElement(
|
78
|
// Taxon.class, getConversationHolder(),
|
79
|
// formElement, "Related Taxon", getRelatedTaxon(),
|
80
|
// EntitySelectionElement.SELECTABLE, style);
|
81
|
taxon = entity.getFromTaxon();
|
82
|
toggleable_cache = formFactory.createToggleableTextField(formElement,
|
83
|
"Title Cache", taxon.getTitleCache(),
|
84
|
taxon.isProtectedTitleCache(), style);
|
85
|
|
86
|
text_appendedPhrase = formFactory.createTextWithLabelElement(
|
87
|
formElement, "Appended Phrase", taxon.getAppendedPhrase(),
|
88
|
SWT.WRAP);
|
89
|
|
90
|
|
91
|
sensuReference = formFactory.createSelectionElement(Reference.class,
|
92
|
getConversationHolder(), formElement, "Sensu",
|
93
|
taxon.getSec(), EntitySelectionElement.ALL,
|
94
|
style);
|
95
|
|
96
|
text_sensu_microreference = formFactory.createTextWithLabelElement(
|
97
|
formElement, "Detail",
|
98
|
taxon.getSecMicroReference(),null,
|
99
|
SWT.WRAP);
|
100
|
|
101
|
|
102
|
|
103
|
|
104
|
checkbox_published = formFactory.createCheckbox(formElement,
|
105
|
"Published", taxon.isPublish(), style);
|
106
|
|
107
|
|
108
|
secReference = formFactory.createSelectionElement(Reference.class,
|
109
|
getConversationHolder(), formElement, "Misappl. Sec.",
|
110
|
entity.getCitation(), EntitySelectionElement.ALL,
|
111
|
style);
|
112
|
|
113
|
text_secundum_microreference = formFactory.createTextWithLabelElement(
|
114
|
formElement, "Detail",
|
115
|
entity.getCitationMicroReference(),null,
|
116
|
SWT.WRAP);
|
117
|
checkbox_doubtful = formFactory.createCheckbox(formElement,
|
118
|
"Misappl. Doubtful", entity.isDoubtful(), style);
|
119
|
|
120
|
|
121
|
}
|
122
|
|
123
|
private Taxon getRelatedTaxon() {
|
124
|
return TaxonRelationshipTypeInverseContainer.RelatedTaxon(getSourceTaxon(), getEntity());
|
125
|
}
|
126
|
|
127
|
private TaxonRelationshipTypeInverseContainer getTaxonRelationshipTypeInverseContainer(){
|
128
|
return TaxonRelationshipTypeInverseContainer.CreateFromSource(getSourceTaxon(), getEntity());
|
129
|
}
|
130
|
|
131
|
private Taxon getSourceTaxon(){
|
132
|
IEditorInput editorInput = StoreUtil.getActiveEditorInput();
|
133
|
return (Taxon) editorInput.getAdapter(Taxon.class);
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
public void handleEvent(Object eventSource) {
|
138
|
if (eventSource== toggleable_cache) {
|
139
|
handleToggleableCacheField();
|
140
|
} else if (eventSource == checkbox_doubtful) {
|
141
|
taxon.setDoubtful(checkbox_doubtful.getSelection());
|
142
|
} else if (eventSource == secReference) {
|
143
|
getEntity().setCitation(secReference.getSelection());
|
144
|
} else if (eventSource == text_appendedPhrase) {
|
145
|
taxon.setAppendedPhrase(text_appendedPhrase.getText());
|
146
|
} else if (eventSource == text_secundum_microreference) {
|
147
|
getEntity().setCitationMicroReference(text_secundum_microreference.getText());
|
148
|
} else if (eventSource == checkbox_published) {
|
149
|
taxon.setPublish(checkbox_published.getSelection());
|
150
|
} else if (eventSource == text_sensu_microreference) {
|
151
|
taxon.setSecMicroReference(text_sensu_microreference.getText());
|
152
|
}else if (eventSource == sensuReference) {
|
153
|
taxon.setSec(sensuReference.getSelection());
|
154
|
}
|
155
|
}
|
156
|
|
157
|
protected void handleToggleableCacheField() {
|
158
|
boolean pushedState = toggleable_cache.getState();
|
159
|
|
160
|
taxon.setTitleCache(toggleable_cache.getText(), pushedState);
|
161
|
setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
|
162
|
updateToggleableCacheField();
|
163
|
}
|
164
|
|
165
|
public void updateToggleableCacheField() {
|
166
|
if (toggleable_cache != null){
|
167
|
if (!taxon.isProtectedTitleCache()) {
|
168
|
toggleable_cache.setText(taxon.generateTitle());
|
169
|
}
|
170
|
}
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
protected void updateContent() {
|
175
|
super.updateContent();
|
176
|
toggleable_cache.setEnabled(taxon.isProtectedTitleCache());
|
177
|
setIrrelevant(toggleable_cache.getState(),
|
178
|
Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
|
179
|
}
|
180
|
@Override
|
181
|
protected void updateControlStates() {
|
182
|
super.updateControlStates();
|
183
|
|
184
|
}
|
185
|
@Override
|
186
|
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
|
187
|
String title = taxon.generateTitle();
|
188
|
taxon.setTitleCache(title);
|
189
|
super.handleTitleCacheRelevantChange(event);
|
190
|
}
|
191
|
|
192
|
@Override
|
193
|
public void refresh(){
|
194
|
updateContent();
|
195
|
updateToggleableCacheField();
|
196
|
}
|
197
|
|
198
|
|
199
|
|
200
|
|
201
|
}
|