1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.classification;
|
11
|
|
12
|
import java.util.HashMap;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.eclipse.swt.widgets.Control;
|
16
|
import org.eclipse.swt.widgets.Text;
|
17
|
|
18
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
19
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.common.Language;
|
21
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
22
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
23
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PublishEnum;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
28
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
35
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
36
|
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
|
37
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
38
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
39
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
40
|
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
|
41
|
|
42
|
/**
|
43
|
*
|
44
|
* @author n.hoffmann
|
45
|
* @created Sep 27, 2010
|
46
|
* @version 1.0
|
47
|
*/
|
48
|
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
|
49
|
|
50
|
private boolean createNew = false;
|
51
|
|
52
|
// private EntitySelectionElement<Classification> selection_classification;
|
53
|
|
54
|
private Classification classification;
|
55
|
|
56
|
private TaxonNodeSelectionElement selection_parentTaxonNode;
|
57
|
|
58
|
private TaxonNode parentTreeNode;
|
59
|
|
60
|
private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
|
61
|
private EntitySelectionElement<Reference> selection_SecRef;
|
62
|
private EntitySelectionElement<Reference> selection_Ref;
|
63
|
TextWithLabelElement textTaxonSec;
|
64
|
private TextWithLabelElement microReference;
|
65
|
|
66
|
private Taxon taxon;
|
67
|
|
68
|
private TextWithLabelElement textNewTaxonName;
|
69
|
|
70
|
private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
|
71
|
|
72
|
// private CheckboxElement checkbox_openInEditor;
|
73
|
|
74
|
private CheckboxElement checkbox_unplaced;
|
75
|
|
76
|
private CheckboxElement checkbox_excluded;
|
77
|
private CheckboxElement checkbox_publish;
|
78
|
|
79
|
|
80
|
|
81
|
private MultilanguageTextElement multiLanguageTextExcludedNotes;
|
82
|
|
83
|
// private boolean openInEditor;
|
84
|
|
85
|
private boolean complete;
|
86
|
|
87
|
private boolean excluded = false;
|
88
|
private boolean unplaced = false;
|
89
|
|
90
|
private EntitySelectionElement<TaxonName> selection_reuseExistingName;
|
91
|
|
92
|
public TaxonNodeDetailElement(CdmFormFactory formFactory,
|
93
|
ICdmFormElement formElement, boolean isCreateNew) {
|
94
|
super(formFactory, formElement);
|
95
|
createNew = isCreateNew;
|
96
|
}
|
97
|
|
98
|
|
99
|
|
100
|
/** {@inheritDoc} */
|
101
|
@Override
|
102
|
protected void createControls(ICdmFormElement formElement,
|
103
|
TaxonNode entity, int style) {
|
104
|
taxon = entity.getTaxon();
|
105
|
if (isCreateNew()){
|
106
|
// selection_classification = formFactory
|
107
|
// .createSelectionElement(Classification.class,//getConversationHolder(),
|
108
|
// formElement, "Classification",
|
109
|
// null, EntitySelectionElement.DELETABLE, style);
|
110
|
|
111
|
selection_parentTaxonNode = formFactory
|
112
|
.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
|
113
|
EntitySelectionElement.DELETABLE, style);
|
114
|
|
115
|
|
116
|
|
117
|
selection_Ref = formFactory
|
118
|
.createSelectionElement(Reference.class,
|
119
|
formElement, "Parent Child Relation Source", null,
|
120
|
EntitySelectionElement.DELETABLE, style);
|
121
|
|
122
|
|
123
|
microReference = formFactory.createTextWithLabelElement(formElement,"Detail", "", style);
|
124
|
microReference.setText(getEntity().getMicroReference());
|
125
|
|
126
|
selection_reuseExistingTaxon = formFactory
|
127
|
.createSelectionElement(Taxon.class,//getConversationHolder(),
|
128
|
formElement,
|
129
|
"Reuse existing taxon", null,
|
130
|
EntitySelectionElement.DELETABLE, style);
|
131
|
|
132
|
selection_reuseExistingName = formFactory
|
133
|
.createSelectionElement(TaxonName.class,//getConversationHolder(),
|
134
|
formElement,
|
135
|
"Reuse existing name", taxon.getName(),
|
136
|
EntitySelectionElement.DELETABLE, style);
|
137
|
selection_SecRef = formFactory
|
138
|
.createSelectionElement(Reference.class,//getConversationHolder(),
|
139
|
formElement, "Secundum Reference", taxon.getSec(),
|
140
|
EntitySelectionElement.DELETABLE, style);
|
141
|
|
142
|
if (isCreateNew()){
|
143
|
textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"New Taxon", "", style);
|
144
|
textNewTaxonName.setFocus();
|
145
|
} else{
|
146
|
textNewTaxonName = formFactory.createTextWithLabelElement(formElement,"Taxon", "", style);
|
147
|
|
148
|
}
|
149
|
}else{
|
150
|
if (entity.getParent().getTaxon() == null){
|
151
|
TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
|
152
|
textParent.setEnabled(false);
|
153
|
}else{
|
154
|
TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Parent", entity.getParent().getTaxon().getTitleCache(), style);
|
155
|
textParent.setEnabled(false);
|
156
|
}
|
157
|
// TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
|
158
|
// textTaxon.setEnabled(false);
|
159
|
selection_Ref = formFactory
|
160
|
.createSelectionElement(Reference.class,
|
161
|
formElement, "Parent Child Relation Source", null,
|
162
|
EntitySelectionElement.DELETABLE, style);
|
163
|
|
164
|
selection_reuseExistingTaxon = formFactory
|
165
|
.createSelectionElement(Taxon.class,//getConversationHolder(),
|
166
|
formElement,
|
167
|
"Taxon", taxon,
|
168
|
EntitySelectionElement.DELETABLE, style);
|
169
|
|
170
|
textTaxonSec = formFactory.createTextWithLabelElement(formElement,"Secundum Reference", "", style);
|
171
|
if (entity.getTaxon().getSec() != null){
|
172
|
textTaxonSec.setText(taxon.getSec().getTitleCache());
|
173
|
}
|
174
|
textTaxonSec.setEnabled(false);
|
175
|
|
176
|
|
177
|
|
178
|
}
|
179
|
|
180
|
|
181
|
if (!isCreateNew()){
|
182
|
if (entity.getReference() != null){
|
183
|
selection_Ref.setEntity(entity.getReference());
|
184
|
}
|
185
|
}
|
186
|
parentTreeNode = entity.getParent();
|
187
|
|
188
|
if (entity instanceof TaxonNode ) {
|
189
|
checkbox_publish = formFactory.createCheckbox(formElement,
|
190
|
"Taxon is published", entity.getTaxon().isPublish(), style);
|
191
|
}else{
|
192
|
checkbox_publish = formFactory.createCheckbox(formElement,
|
193
|
"Taxon is published", true, style);
|
194
|
}
|
195
|
|
196
|
checkbox_publish.setEnabled(isCreateNew());
|
197
|
if(isCreateNew()){
|
198
|
setParentTreeNode(entity.getParent());
|
199
|
|
200
|
String defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
|
201
|
if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
|
202
|
checkbox_publish.setSelection(true);
|
203
|
} else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
|
204
|
checkbox_publish.setSelection(false);
|
205
|
}else{
|
206
|
if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
|
207
|
checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
|
208
|
}else{
|
209
|
checkbox_publish.setSelection(true);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
} else{
|
214
|
setTreeNode(entity);
|
215
|
|
216
|
complete = true;
|
217
|
}
|
218
|
if (entity instanceof TaxonNode) {
|
219
|
checkbox_unplaced = formFactory.createCheckbox(formElement,
|
220
|
"Taxon is unplaced", entity.isUnplaced(), style);
|
221
|
}else{
|
222
|
checkbox_unplaced = formFactory.createCheckbox(formElement,
|
223
|
"Taxon is unplaced", false, style);
|
224
|
}
|
225
|
if (isCreateNew()){
|
226
|
preFillTaxonName();
|
227
|
}
|
228
|
|
229
|
if (entity instanceof TaxonNode) {
|
230
|
checkbox_excluded = formFactory.createCheckbox(formElement,
|
231
|
"Taxon is excluded", entity.isExcluded(), style);
|
232
|
multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
|
233
|
multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
|
234
|
}else{
|
235
|
checkbox_excluded = formFactory.createCheckbox(formElement,
|
236
|
"Taxon is excluded", false, style);
|
237
|
multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", new HashMap<Language, LanguageString>(), 50, style);
|
238
|
multiLanguageTextExcludedNotes.setEnabled(false);
|
239
|
}
|
240
|
if (!isCreateNew()){
|
241
|
selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
|
242
|
selectionNodeAgentRelation.setEntity(entity);
|
243
|
selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
244
|
}
|
245
|
|
246
|
}
|
247
|
|
248
|
private void preFillTaxonName() {
|
249
|
if(getEntity() instanceof TaxonNode ){
|
250
|
TaxonNode node = parentTreeNode;
|
251
|
if(node.getTaxon()!=null){
|
252
|
Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
|
253
|
if(taxon.getName()!=null){
|
254
|
TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
|
255
|
if (!isCreateNew()){
|
256
|
textNewTaxonName.setText(name.getNameCache());
|
257
|
} else if( ! name.isSupraGeneric() && name.getRank() != null){
|
258
|
String taxonName = "";
|
259
|
if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
|
260
|
taxonName = name.getGenusOrUninomial();
|
261
|
}
|
262
|
else if(name.isSpecies() || name.isInfraSpecific() ){
|
263
|
taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
|
264
|
}
|
265
|
if (StringUtils.isNotBlank(taxonName)){
|
266
|
textNewTaxonName.setText(taxonName + " ");
|
267
|
if(textNewTaxonName.getMainControl() instanceof Text){
|
268
|
Text text = (Text)textNewTaxonName.getMainControl();
|
269
|
text.setSelection(textNewTaxonName.getText().length());
|
270
|
}
|
271
|
}
|
272
|
}
|
273
|
}
|
274
|
}
|
275
|
}
|
276
|
}
|
277
|
|
278
|
/** {@inheritDoc} */
|
279
|
@Override
|
280
|
public void handleEvent(Object eventSource) {
|
281
|
if (eventSource == selection_parentTaxonNode) {
|
282
|
setParentTreeNode(selection_parentTaxonNode.getEntity());
|
283
|
} else if (eventSource == selection_reuseExistingTaxon) {
|
284
|
if (selection_reuseExistingTaxon.getEntity() != null){
|
285
|
setTaxon(selection_reuseExistingTaxon.getEntity());
|
286
|
if (getTaxon().getSec()!= null){
|
287
|
if (isCreateNew()){
|
288
|
selection_SecRef.setEntity(getTaxon().getSec());
|
289
|
}else{
|
290
|
textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
|
291
|
}
|
292
|
}else{
|
293
|
if (isCreateNew()){
|
294
|
selection_SecRef.setEntity(null);
|
295
|
}else{
|
296
|
textTaxonSec.setText("");
|
297
|
}
|
298
|
}
|
299
|
checkbox_publish.setSelected(getTaxon().isPublish());
|
300
|
}
|
301
|
boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
|
302
|
if (selection_reuseExistingName != null){
|
303
|
selection_reuseExistingName.setEnabled(enabled);
|
304
|
}
|
305
|
textNewTaxonName.setEnabled(enabled);
|
306
|
complete = true;
|
307
|
} else if (eventSource == selection_reuseExistingName) {
|
308
|
boolean enabled = selection_reuseExistingName.getEntity() == null;
|
309
|
setTaxon(HibernateProxyHelper.deproxy(selection_reuseExistingName.getEntity()));
|
310
|
if (selection_reuseExistingTaxon != null){
|
311
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
312
|
}
|
313
|
textNewTaxonName.setEnabled(enabled);
|
314
|
complete = !textNewTaxonName.getText().isEmpty();
|
315
|
}
|
316
|
|
317
|
if (eventSource == selection_Ref) {
|
318
|
getEntity().setReference(selection_Ref.getEntity());
|
319
|
}else if (eventSource == selection_SecRef) {
|
320
|
taxon.setSec(selection_SecRef.getEntity());
|
321
|
}else if (eventSource == microReference) {
|
322
|
getEntity().setMicroReference(microReference.getText());
|
323
|
} else if (eventSource == checkbox_publish) {
|
324
|
taxon.setPublish(checkbox_publish.getSelection());
|
325
|
}
|
326
|
|
327
|
if (eventSource == checkbox_excluded) {
|
328
|
excluded = checkbox_excluded.getSelection();
|
329
|
|
330
|
getEntity().setExcluded(excluded);
|
331
|
|
332
|
multiLanguageTextExcludedNotes.setEnabled(excluded);
|
333
|
}
|
334
|
if (eventSource == checkbox_unplaced) {
|
335
|
unplaced = checkbox_unplaced.getSelection();
|
336
|
getEntity().setUnplaced(unplaced);
|
337
|
|
338
|
}
|
339
|
if (eventSource == textNewTaxonName) {
|
340
|
boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
|
341
|
if (selection_reuseExistingTaxon != null){
|
342
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
343
|
}
|
344
|
selection_reuseExistingName.setEnabled(enabled);
|
345
|
|
346
|
complete = CdmUtils.isNotBlank(textNewTaxonName.getText());
|
347
|
}
|
348
|
|
349
|
if (eventSource == selectionNodeAgentRelation){
|
350
|
boolean allComplete = true;
|
351
|
for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
|
352
|
allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
|
353
|
}
|
354
|
complete = !isCreateNew() && allComplete;
|
355
|
}
|
356
|
}
|
357
|
|
358
|
public Classification getClassification() {
|
359
|
return classification;
|
360
|
}
|
361
|
|
362
|
|
363
|
|
364
|
public ITaxonTreeNode getParentTreeNode() {
|
365
|
return parentTreeNode;
|
366
|
}
|
367
|
|
368
|
private void setClassification(Classification classification) {
|
369
|
this.classification = classification;
|
370
|
//setParentTreeNode(classification);
|
371
|
}
|
372
|
|
373
|
private void setParentTreeNode(TaxonNode parentTreeNode) {
|
374
|
this.parentTreeNode = parentTreeNode;
|
375
|
|
376
|
if (parentTreeNode.getTaxon() == null) {
|
377
|
classification = parentTreeNode.getClassification();
|
378
|
// if (selection_classification != null){
|
379
|
// selection_classification.setEntity(classification);
|
380
|
// }
|
381
|
selection_parentTaxonNode.setEntity(classification.getRootNode());
|
382
|
selection_parentTaxonNode.setClassification(classification);
|
383
|
selection_SecRef.setEntity(classification.getReference());
|
384
|
} else {
|
385
|
classification = HibernateProxyHelper
|
386
|
.deproxy(parentTreeNode.getClassification());
|
387
|
// if (selection_classification != null){
|
388
|
// selection_classification.setEntity(classification);
|
389
|
// }
|
390
|
selection_parentTaxonNode.setEntity(HibernateProxyHelper
|
391
|
.deproxy(parentTreeNode));
|
392
|
selection_parentTaxonNode.setClassification(classification);
|
393
|
selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
|
394
|
|
395
|
}
|
396
|
}
|
397
|
|
398
|
private void setTreeNode(TaxonNode treeNode) {
|
399
|
classification = HibernateProxyHelper
|
400
|
.deproxy(treeNode.getClassification());
|
401
|
if (isCreateNew()){
|
402
|
//selection_classification.setEntity(classification);
|
403
|
selection_parentTaxonNode.setEntity(treeNode.getParent());
|
404
|
selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
|
405
|
selection_SecRef.setEntity(treeNode.getTaxon().getSec());
|
406
|
}
|
407
|
}
|
408
|
|
409
|
private void setTaxon(Taxon taxon) {
|
410
|
this.taxon = taxon;
|
411
|
getEntity().setTaxon(taxon);
|
412
|
this.set_publish(taxon.isPublish());
|
413
|
if (isCreateNew()){
|
414
|
textNewTaxonName.setText(taxon.getName().getTitleCache());
|
415
|
if (taxon.getSec() != null){
|
416
|
selection_SecRef.setEntity(taxon.getSec());
|
417
|
}
|
418
|
}else{
|
419
|
if (taxon.getSec() != null) {
|
420
|
this.textTaxonSec.setText(taxon.getSec().getTitleCache());
|
421
|
}
|
422
|
}
|
423
|
|
424
|
|
425
|
}
|
426
|
|
427
|
private void setTaxon(TaxonName taxonName) {
|
428
|
Reference secundum = null;
|
429
|
if (getParentTreeNode() != null) {
|
430
|
if (this.selection_SecRef.getEntity() != null){
|
431
|
secundum = this.selection_SecRef.getEntity();
|
432
|
}
|
433
|
}
|
434
|
if (taxonName != null){
|
435
|
taxon = Taxon.NewInstance(taxonName, secundum);
|
436
|
if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
|
437
|
textNewTaxonName.setText(taxonName.getTitleCache());
|
438
|
}
|
439
|
getEntity().setTaxon(taxon);
|
440
|
// if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
|
441
|
// textNewTaxonName.setText(taxonName.getTitleCache());
|
442
|
// }
|
443
|
} else {
|
444
|
textNewTaxonName.setText(null);
|
445
|
}
|
446
|
}
|
447
|
|
448
|
// private void setOpenInEditor(boolean openInEditor) {
|
449
|
// this.openInEditor = openInEditor;
|
450
|
// }
|
451
|
|
452
|
public String getTaxonName() {
|
453
|
return textNewTaxonName.getText();
|
454
|
}
|
455
|
public Taxon getTaxon() {
|
456
|
return taxon;
|
457
|
}
|
458
|
|
459
|
public Reference getReference(){
|
460
|
return selection_SecRef.getSelection();
|
461
|
}
|
462
|
|
463
|
public Control getMainControl(){
|
464
|
return textNewTaxonName.getMainControl();
|
465
|
}
|
466
|
|
467
|
public boolean isComplete() {
|
468
|
boolean allComplete = true;
|
469
|
if (!isCreateNew()){
|
470
|
for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
|
471
|
allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
|
472
|
}
|
473
|
complete = allComplete;
|
474
|
}
|
475
|
return complete;
|
476
|
}
|
477
|
|
478
|
public boolean isCreateNew() {
|
479
|
return createNew;
|
480
|
}
|
481
|
|
482
|
public boolean isExcluded() {
|
483
|
return excluded;
|
484
|
}
|
485
|
|
486
|
public boolean isUnplaced() {
|
487
|
return unplaced;
|
488
|
}
|
489
|
|
490
|
public boolean is_publish() {
|
491
|
boolean isPublishPreference = true;
|
492
|
CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
|
493
|
if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
|
494
|
isPublishPreference = false;
|
495
|
}
|
496
|
return checkbox_publish!=null?checkbox_publish.getSelection():isPublishPreference;
|
497
|
}
|
498
|
|
499
|
public void set_publish(boolean publish) {
|
500
|
this.checkbox_publish.setSelection(publish);
|
501
|
}
|
502
|
|
503
|
|
504
|
}
|