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
|
package eu.etaxonomy.taxeditor.ui.section.classification;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.apache.commons.lang3.StringUtils;
|
17
|
import org.eclipse.jface.resource.JFaceResources;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.graphics.Font;
|
20
|
import org.eclipse.swt.widgets.Control;
|
21
|
import org.eclipse.swt.widgets.Label;
|
22
|
import org.eclipse.swt.widgets.Text;
|
23
|
|
24
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
25
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
26
|
import eu.etaxonomy.cdm.model.common.Language;
|
27
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
28
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
29
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
30
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
31
|
import eu.etaxonomy.cdm.model.metadata.PublishEnum;
|
32
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
33
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
35
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
36
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
37
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
|
38
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
39
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
40
|
import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
|
41
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
42
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
43
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
44
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
45
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
46
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
47
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
48
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
49
|
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
|
50
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
51
|
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
|
52
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
53
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
54
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSingleSourceElement;
|
55
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
56
|
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
|
57
|
|
58
|
/**
|
59
|
* @author n.hoffmann
|
60
|
* @created Sep 27, 2010
|
61
|
*/
|
62
|
public class TaxonNodeDetailElement extends AbstractSingleSourceElement<TaxonNode> {
|
63
|
|
64
|
private static final String STATUS_NOTES = Messages.TaxonNodeWizardPage_STATUS_NOTES;
|
65
|
private static final String CLASSIFICATION_STR = Messages.TaxonNodeWizardPage_CLASSIFICATION;
|
66
|
private static final String REUSE_EXISTING_TAXON = Messages.TaxonNodeWizardPage_REUSE_EXISTING_TAXON;
|
67
|
private static final String REUSE_EXISTING_NAME = Messages.TaxonNodeWizardPage_REUSE_EXISTING_NAME;
|
68
|
private static final String SECUNDUM_REFERENCE = Messages.TaxonNodeWizardPage_SECUNDUM_REFERENCE;
|
69
|
|
70
|
private static final Font FONT_BOLD = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
|
71
|
|
72
|
private boolean createNew = false;
|
73
|
private Classification classification;
|
74
|
private TaxonNode parentNode;
|
75
|
private Taxon taxon;
|
76
|
private boolean complete;
|
77
|
private TaxonNodeStatus status = null;
|
78
|
private Map<Language, LanguageString> multilanguageTextCache;
|
79
|
|
80
|
private TaxonNodeSelectionElement selection_parentTaxonNode;
|
81
|
private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
|
82
|
private EntitySelectionElement<TaxonName> selection_reuseExistingName;
|
83
|
private EntitySelectionElement<Reference> selection_SecRef;
|
84
|
|
85
|
// private OriginalSourceElement singleSourceSection;
|
86
|
|
87
|
private TextWithLabelElement textTaxonSec;
|
88
|
private TextWithLabelElement microReference;
|
89
|
private TextWithLabelElement textNewTaxonName;
|
90
|
private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
|
91
|
private EnumComboElement<TaxonNodeStatus> combo_status;
|
92
|
private CheckboxElement checkbox_publish;
|
93
|
private MultilanguageTextElement multiLanguageTextStatusNotes;
|
94
|
String defaultPublish;
|
95
|
|
96
|
public TaxonNodeDetailElement(CdmFormFactory formFactory,
|
97
|
ICdmFormElement formElement, boolean isCreateNew) {
|
98
|
super(formFactory, formElement);
|
99
|
createNew = isCreateNew;
|
100
|
}
|
101
|
|
102
|
public Map<Language, LanguageString> getMultiLanguageTextExcludedNotes() {
|
103
|
return multiLanguageTextStatusNotes.getMultilanguageText();
|
104
|
}
|
105
|
|
106
|
public TaxonNodeStatus getTaxonNodeStatus(){
|
107
|
return status;
|
108
|
}
|
109
|
|
110
|
public Reference getRef() {
|
111
|
return getEntity().getCitation();
|
112
|
}
|
113
|
public TaxonName getExistingName() {
|
114
|
return selection_reuseExistingName.getEntity();
|
115
|
}
|
116
|
public String getMicroReference() {
|
117
|
return microReference.getText();
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public void createControls(ICdmFormElement formElement,TaxonNode entity, int style) {
|
122
|
// taxon = entity.getTaxon();
|
123
|
|
124
|
Label taxonTitle = new Label(getLayoutComposite(), SWT.NULL);
|
125
|
taxonTitle.setText(Messages.TaxonNodeWizardPage_TAXON_INFORMATION);
|
126
|
taxonTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
127
|
taxonTitle.setFont(FONT_BOLD);
|
128
|
|
129
|
|
130
|
|
131
|
if (isCreateNew()){
|
132
|
textNewTaxonName = formFactory.createTextWithLabelElement(formElement,
|
133
|
Messages.TaxonNodeWizardPage_NEW_TAXON, "", style);
|
134
|
textNewTaxonName.setFocus();
|
135
|
textNewTaxonName.setIndent(10);
|
136
|
|
137
|
selection_reuseExistingTaxon = formFactory
|
138
|
.createSelectionElement(Taxon.class,//getConversationHolder(),
|
139
|
formElement,
|
140
|
REUSE_EXISTING_TAXON, null,
|
141
|
EntitySelectionElement.SELECTABLE, style);
|
142
|
selection_reuseExistingTaxon.setIndent(10);
|
143
|
selection_reuseExistingName = formFactory
|
144
|
.createSelectionElement(TaxonName.class,//getConversationHolder(),
|
145
|
formElement,
|
146
|
REUSE_EXISTING_NAME, taxon != null? taxon.getName(): null,
|
147
|
EntitySelectionElement.DELETABLE, style);
|
148
|
selection_reuseExistingName.setIndent(10);
|
149
|
selection_SecRef = formFactory
|
150
|
.createSelectionElement(Reference.class,//getConversationHolder(),
|
151
|
formElement, SECUNDUM_REFERENCE, taxon != null? taxon.getSec(): null,
|
152
|
EntitySelectionElement.DELETABLE, style, 100);
|
153
|
selection_SecRef.setIndent(10);
|
154
|
microReference = formFactory.createTextWithLabelElement(formElement, "Secundum Details", "", style);
|
155
|
|
156
|
microReference.setIndent(10);
|
157
|
checkbox_publish = formFactory.createCheckbox(formElement,
|
158
|
Messages.TaxonNodeWizardPage_TAXON_IS_PUBLISH, true, style);
|
159
|
|
160
|
checkbox_publish.setEnabled(isCreateNew());
|
161
|
checkbox_publish.setIndent(10);
|
162
|
Label spacer = new Label(getLayoutComposite(), SWT.NULL);
|
163
|
spacer.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 2));
|
164
|
Label nodeTitle = new Label(getLayoutComposite(), SWT.NULL);
|
165
|
nodeTitle.setText("Taxon Node");
|
166
|
nodeTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
167
|
nodeTitle.setFont(FONT_BOLD);
|
168
|
// LabelElement nodeTitle = formFactory.createLabel(formElement, Messages.TaxonNodeWizardPage_TAXON_INFORMATION);
|
169
|
// nodeTitle.setLayout(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
170
|
// nodeTitle.setBackground(getPersistentBackground());
|
171
|
// nodeTitle.setBold();
|
172
|
|
173
|
selection_parentTaxonNode = formFactory
|
174
|
.createTaxonNodeSelectionElement(getConversationHolder(), formElement, Messages.TaxonNodeWizardPage_PARENT, parentNode,
|
175
|
EntitySelectionElement.SELECTABLE, style, 100);
|
176
|
selection_parentTaxonNode.setIndent(10);
|
177
|
selection_parentTaxonNode.setEnabled(false);
|
178
|
|
179
|
|
180
|
|
181
|
}else{
|
182
|
taxon = getEntity().getTaxon();
|
183
|
selection_reuseExistingTaxon = formFactory
|
184
|
.createSelectionElement(Taxon.class, formElement,
|
185
|
Messages.TaxonNodeWizardPage_TAXON, taxon,
|
186
|
EntitySelectionElement.SELECTABLE, SWT.NULL);
|
187
|
|
188
|
selection_reuseExistingTaxon.setIndent(10);
|
189
|
textTaxonSec = formFactory.createTextWithLabelElement(formElement,SECUNDUM_REFERENCE, "", SWT.NULL);
|
190
|
textTaxonSec.setIndent(10);
|
191
|
microReference = formFactory.createTextWithLabelElement(formElement, "Secundum Details", "", SWT.NULL);
|
192
|
microReference.setIndent(10);
|
193
|
|
194
|
if (entity.getTaxon().getSec() != null){
|
195
|
textTaxonSec.setText(taxon.getSec().getTitleCache());
|
196
|
}
|
197
|
textTaxonSec.setEnabled(false);
|
198
|
microReference.setEnabled(false);
|
199
|
Label spacer = new Label(getLayoutComposite(), SWT.NULL);
|
200
|
spacer.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 2));
|
201
|
|
202
|
Label nodeTitle = new Label(getLayoutComposite(), SWT.NULL);
|
203
|
nodeTitle.setText("Taxon Node");
|
204
|
nodeTitle.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
205
|
nodeTitle.setFont(FONT_BOLD);
|
206
|
|
207
|
// LabelElement nodeTitle = formFactory.createLabel(formElement, "Taxon Node");
|
208
|
// nodeTitle.setLayout(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
209
|
// nodeTitle.setBackground(getPersistentBackground());
|
210
|
// nodeTitle.setBold();
|
211
|
|
212
|
|
213
|
if (entity.getParent().getTaxon() == null){
|
214
|
TextWithLabelElement textParent = formFactory.createTextWithLabelElement(
|
215
|
formElement,CLASSIFICATION_STR, entity.getClassification().getTitleCache(), SWT.NULL);
|
216
|
textParent.setEnabled(false);
|
217
|
textParent.setIndent(10);
|
218
|
}else{
|
219
|
TextWithLabelElement textParent = formFactory.createTextWithLabelElement(
|
220
|
formElement, Messages.TaxonNodeWizardPage_PARENT, entity.getParent().getTaxon().getTitleCache(), SWT.NULL);
|
221
|
textParent.setEnabled(false);
|
222
|
textParent.setIndent(10);
|
223
|
}
|
224
|
}
|
225
|
|
226
|
|
227
|
combo_status = formFactory.createEnumComboElement(TaxonNodeStatus.class, formElement, SWT.NULL, true);
|
228
|
if (!isCreateNew()){
|
229
|
combo_status.setSelection(entity.getStatus());
|
230
|
}
|
231
|
combo_status.setIndent(10);
|
232
|
if(isCreateNew()){
|
233
|
|
234
|
defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
|
235
|
setDefaultPublish();
|
236
|
} else{
|
237
|
setTreeNode(entity);
|
238
|
complete = true;
|
239
|
}
|
240
|
|
241
|
if (isCreateNew()){
|
242
|
preFillTaxonName();
|
243
|
}
|
244
|
|
245
|
multiLanguageTextStatusNotes = formFactory.createMultiLanguageTextElement(formElement, STATUS_NOTES, null, 50, style);
|
246
|
if (!isCreateNew()){
|
247
|
multiLanguageTextStatusNotes.setMultilanguageText(entity.getStatusNote());
|
248
|
multiLanguageTextStatusNotes.setEnabled(entity.getStatus() != null);
|
249
|
}
|
250
|
multiLanguageTextStatusNotes.setIndent(10);
|
251
|
singleSourceSection = formFactory.createOriginalSourceElement(formElement, entity, "");
|
252
|
if (isCreateNew() || entity.getSource() == null){
|
253
|
DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
|
254
|
entity.setSource(source);
|
255
|
singleSourceSection.setEntity(source);
|
256
|
}else{
|
257
|
singleSourceSection.setEntity(entity.getSource());
|
258
|
|
259
|
}
|
260
|
singleSourceSection.setIndent(10);
|
261
|
// singleSourceSection.set
|
262
|
|
263
|
// super.createControls(formElement, entity, style);
|
264
|
|
265
|
setSourceLabel(Messages.TaxonNodeWizardPage_PLACEMENT_SOURCE);
|
266
|
|
267
|
|
268
|
selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), StoreUtil.getSectionStyle(TaxonNodeAgentRelationCollectionSection.class, entity.getClass().getCanonicalName()));
|
269
|
selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
270
|
selectionNodeAgentRelation.setEntity(entity);
|
271
|
selectionNodeAgentRelation.setIndent(10);
|
272
|
selectionNodeAgentRelation.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
|
273
|
setBackground(getPersistentBackground());
|
274
|
|
275
|
}
|
276
|
|
277
|
private void setDefaultPublish() {
|
278
|
if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
|
279
|
checkbox_publish.setSelection(true);
|
280
|
} else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
|
281
|
checkbox_publish.setSelection(false);
|
282
|
}else{
|
283
|
if(this.getParentTreeNode() != null && this.getParentTreeNode().isInstanceOf(TaxonNode.class) && this.getParentTreeNode().getTaxon() != null){
|
284
|
checkbox_publish.setSelection(this.getParentTreeNode().getTaxon().isPublish());
|
285
|
}else{
|
286
|
checkbox_publish.setSelection(true);
|
287
|
}
|
288
|
}
|
289
|
}
|
290
|
|
291
|
private void preFillTaxonName() {
|
292
|
TaxonNode node = parentNode;
|
293
|
if(node != null && node.getTaxon()!=null){
|
294
|
Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
|
295
|
if(taxon.getName()!=null){
|
296
|
TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
|
297
|
if (!isCreateNew()){
|
298
|
textNewTaxonName.setText(name.getNameCache());
|
299
|
} else if( ! name.isSupraGeneric() && name.getRank() != null){
|
300
|
String taxonName = "";
|
301
|
if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
|
302
|
taxonName = name.getGenusOrUninomial();
|
303
|
}
|
304
|
else if(name.isSpecies() || name.isInfraSpecific() ){
|
305
|
taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
|
306
|
}
|
307
|
if (StringUtils.isNotBlank(taxonName)){
|
308
|
textNewTaxonName.setText(taxonName + " ");
|
309
|
if(textNewTaxonName.getMainControl() instanceof Text){
|
310
|
Text text = (Text)textNewTaxonName.getMainControl();
|
311
|
text.setSelection(textNewTaxonName.getText().length());
|
312
|
}
|
313
|
}
|
314
|
}
|
315
|
}
|
316
|
}
|
317
|
}
|
318
|
|
319
|
@Override
|
320
|
public void handleEvent(Object eventSource) {
|
321
|
if (eventSource == selection_parentTaxonNode) {
|
322
|
setParentTreeNode(selection_parentTaxonNode.getEntity());
|
323
|
} else if (eventSource == selection_reuseExistingTaxon) {
|
324
|
if (selection_reuseExistingTaxon.getEntity() != null){
|
325
|
setTaxon(selection_reuseExistingTaxon.getEntity());
|
326
|
if (getTaxon().getSec()!= null){
|
327
|
microReference.setText(getTaxon().getSecMicroReference());
|
328
|
if (isCreateNew()){
|
329
|
selection_SecRef.setEntity(getTaxon().getSec());
|
330
|
|
331
|
}else{
|
332
|
textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
|
333
|
}
|
334
|
}else{
|
335
|
microReference.setText("");
|
336
|
if (isCreateNew()){
|
337
|
selection_SecRef.setEntity(null);
|
338
|
|
339
|
}else{
|
340
|
textTaxonSec.setText("");
|
341
|
}
|
342
|
}
|
343
|
if (checkbox_publish != null){
|
344
|
checkbox_publish.setSelected(getTaxon().isPublish());
|
345
|
}
|
346
|
}else{
|
347
|
if (isCreateNew()){
|
348
|
selection_SecRef.setEntity(null);
|
349
|
}else{
|
350
|
textTaxonSec.setText(null);
|
351
|
}
|
352
|
setDefaultPublish();
|
353
|
}
|
354
|
boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
|
355
|
if (selection_reuseExistingName != null){
|
356
|
selection_reuseExistingName.setEnabled(enabled);
|
357
|
}
|
358
|
if (selection_SecRef != null){
|
359
|
selection_SecRef.setEnabled(enabled);
|
360
|
}
|
361
|
if (textNewTaxonName != null){
|
362
|
textNewTaxonName.setEnabled(enabled);
|
363
|
}
|
364
|
complete = true;
|
365
|
} else if (eventSource == selection_reuseExistingName) {
|
366
|
boolean enabled = selection_reuseExistingName.getEntity() == null;
|
367
|
setTaxon(HibernateProxyHelper.deproxy(selection_reuseExistingName.getEntity()));
|
368
|
if (selection_reuseExistingTaxon != null){
|
369
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
370
|
}
|
371
|
textNewTaxonName.setEnabled(enabled);
|
372
|
if (textNewTaxonName.getText() != null){
|
373
|
complete = !textNewTaxonName.getText().isEmpty();
|
374
|
}else {
|
375
|
complete = false;
|
376
|
}
|
377
|
}
|
378
|
|
379
|
if (eventSource == combo_status) {
|
380
|
status = combo_status.getSelection();
|
381
|
if (status == null){
|
382
|
if (multiLanguageTextStatusNotes.getMultilanguageText() != null && !multiLanguageTextStatusNotes.getMultilanguageText().isEmpty()){
|
383
|
multilanguageTextCache = new HashMap<>();
|
384
|
for (LanguageString langString: multiLanguageTextStatusNotes.getMultilanguageText().values()){
|
385
|
multilanguageTextCache.put(langString.getLanguage(), langString);
|
386
|
}
|
387
|
// multilanguageTextCache = multiLanguageTextStatusNotes.getMultilanguageText();
|
388
|
}
|
389
|
multiLanguageTextStatusNotes.setMultilanguageText(new HashMap<>());
|
390
|
// multiLanguageTextStatusNotes.refresh();
|
391
|
|
392
|
}else if (multilanguageTextCache != null ){
|
393
|
|
394
|
multiLanguageTextStatusNotes.setMultilanguageText(multilanguageTextCache);
|
395
|
multilanguageTextCache = null;
|
396
|
}
|
397
|
if (!isCreateNew()){
|
398
|
getEntity().setStatus(status);
|
399
|
if (status == null){
|
400
|
getEntity().getStatusNote().clear();
|
401
|
multiLanguageTextStatusNotes.setMultilanguageText(new HashMap<>());
|
402
|
multiLanguageTextStatusNotes.refresh();
|
403
|
}else{
|
404
|
if (multiLanguageTextStatusNotes.getMultilanguageText() != null){
|
405
|
for (LanguageString lang:multiLanguageTextStatusNotes.getMultilanguageText().values()){
|
406
|
getEntity().putStatusNote(lang);
|
407
|
}
|
408
|
}
|
409
|
}
|
410
|
}
|
411
|
|
412
|
multiLanguageTextStatusNotes.setEnabled(status != null);
|
413
|
|
414
|
complete = true;
|
415
|
}
|
416
|
|
417
|
if (eventSource == textNewTaxonName) {
|
418
|
boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
|
419
|
if (selection_reuseExistingTaxon != null){
|
420
|
selection_reuseExistingTaxon.setEnabled(enabled);
|
421
|
}
|
422
|
selection_reuseExistingName.setEnabled(enabled);
|
423
|
|
424
|
complete = CdmUtils.isNotBlank(textNewTaxonName.getText());
|
425
|
}
|
426
|
|
427
|
if (eventSource == selectionNodeAgentRelation){
|
428
|
boolean allComplete = true;
|
429
|
for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
|
430
|
allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
|
431
|
}
|
432
|
complete = !isCreateNew() && allComplete;
|
433
|
}
|
434
|
}
|
435
|
|
436
|
public Classification getClassification() {
|
437
|
return classification;
|
438
|
}
|
439
|
|
440
|
public TaxonNode getParentTreeNode() {
|
441
|
return parentNode;
|
442
|
}
|
443
|
|
444
|
public void setParentTreeNode(TaxonNode parentTreeNode) {
|
445
|
this.parentNode = parentTreeNode;
|
446
|
updateContent();
|
447
|
if (parentTreeNode.getTaxon() == null) {
|
448
|
classification = parentTreeNode.getClassification();
|
449
|
if (selection_parentTaxonNode != null){
|
450
|
selection_parentTaxonNode.setEntity(classification.getRootNode());
|
451
|
selection_parentTaxonNode.setClassification(classification);
|
452
|
selection_SecRef.setEntity(classification.getReference());
|
453
|
}
|
454
|
} else {
|
455
|
classification = HibernateProxyHelper
|
456
|
.deproxy(parentTreeNode.getClassification());
|
457
|
if (selection_parentTaxonNode != null){
|
458
|
selection_parentTaxonNode.setEntity(HibernateProxyHelper.deproxy(parentTreeNode));
|
459
|
selection_parentTaxonNode.setClassification(classification);
|
460
|
selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
|
461
|
}
|
462
|
}
|
463
|
}
|
464
|
|
465
|
@Override
|
466
|
protected void updateControlStates(){
|
467
|
Collection<Object> except = new ArrayList<Object>();
|
468
|
for(ICdmFormElement formElement:getElements()){
|
469
|
if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
|
470
|
except.add(formElement);
|
471
|
}
|
472
|
}
|
473
|
if (isCreateNew() ){
|
474
|
enabled = true;
|
475
|
}else{
|
476
|
enabled = getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
|
477
|
}
|
478
|
setEnabled(enabled, except);
|
479
|
}
|
480
|
|
481
|
private void setTreeNode(TaxonNode treeNode) {
|
482
|
classification = HibernateProxyHelper
|
483
|
.deproxy(treeNode.getClassification());
|
484
|
if (isCreateNew()){
|
485
|
selection_parentTaxonNode.setEntity(treeNode.getParent());
|
486
|
selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
|
487
|
selection_SecRef.setEntity(treeNode.getTaxon().getSec());
|
488
|
}
|
489
|
}
|
490
|
|
491
|
private void setTaxon(Taxon taxon) {
|
492
|
this.taxon = taxon;
|
493
|
if (!isCreateNew()){
|
494
|
getEntity().setTaxon(taxon);
|
495
|
}
|
496
|
|
497
|
this.set_publish(taxon.isPublish());
|
498
|
if (isCreateNew()){
|
499
|
textNewTaxonName.setText(taxon.getName().getTitleCache());
|
500
|
if (taxon.getSec() != null){
|
501
|
selection_SecRef.setEntity(taxon.getSec());
|
502
|
}
|
503
|
}else{
|
504
|
if (taxon.getSec() != null) {
|
505
|
this.textTaxonSec.setText(taxon.getSec().getTitleCache());
|
506
|
}
|
507
|
}
|
508
|
}
|
509
|
|
510
|
private void setTaxon(TaxonName taxonName) {
|
511
|
Reference secundum = null;
|
512
|
if (getParentTreeNode() != null) {
|
513
|
if (this.selection_SecRef.getEntity() != null){
|
514
|
secundum = this.selection_SecRef.getEntity();
|
515
|
}
|
516
|
}
|
517
|
if (taxonName != null){
|
518
|
textNewTaxonName.setText(taxonName.getTitleCache());
|
519
|
}else{
|
520
|
textNewTaxonName.setText("");
|
521
|
if (selection_reuseExistingTaxon != null){
|
522
|
selection_reuseExistingTaxon.setEnabled(true);
|
523
|
}
|
524
|
textNewTaxonName.setEnabled(true);
|
525
|
|
526
|
}
|
527
|
|
528
|
}
|
529
|
|
530
|
public String getTaxonName() {
|
531
|
return textNewTaxonName.getText();
|
532
|
}
|
533
|
public Taxon getTaxon() {
|
534
|
return taxon;
|
535
|
}
|
536
|
|
537
|
public Reference getSecReference(){
|
538
|
return selection_SecRef.getSelection();
|
539
|
}
|
540
|
|
541
|
public Control getMainControl(){
|
542
|
return textNewTaxonName.getMainControl();
|
543
|
}
|
544
|
|
545
|
public boolean isComplete() {
|
546
|
boolean allComplete = true;
|
547
|
if (!isCreateNew()){
|
548
|
for (ICdmFormElement element : selectionNodeAgentRelation.getElements()){
|
549
|
allComplete &=((TaxonNodeAgentRelationCollectionElement)element).isComplete();
|
550
|
}
|
551
|
complete = allComplete;
|
552
|
}
|
553
|
return complete;
|
554
|
}
|
555
|
|
556
|
public boolean isCreateNew() {
|
557
|
return createNew;
|
558
|
}
|
559
|
|
560
|
public boolean is_publish() {
|
561
|
boolean isPublishPreference = true;
|
562
|
CdmPreference defaultPublish = CdmPreferenceCache.instance().get(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
|
563
|
if (defaultPublish != null && defaultPublish.getValue()!= null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
|
564
|
isPublishPreference = false;
|
565
|
}
|
566
|
return checkbox_publish!=null?checkbox_publish.getSelection():isPublishPreference;
|
567
|
}
|
568
|
|
569
|
public void set_publish(boolean publish) {
|
570
|
if (checkbox_publish != null){
|
571
|
this.checkbox_publish.setSelection(publish);
|
572
|
}
|
573
|
}
|
574
|
|
575
|
/**
|
576
|
* Updates all widgets to display the latest data
|
577
|
*/
|
578
|
@Override
|
579
|
protected void updateContent() {
|
580
|
removeElements();
|
581
|
if (isCreateNew()){
|
582
|
createControls(this, parentNode, SWT.NONE);
|
583
|
}else{
|
584
|
createControls(this, getEntity(), SWT.NONE);
|
585
|
}
|
586
|
updateControlStates();
|
587
|
}
|
588
|
|
589
|
@Override
|
590
|
public SelectionArbitrator getSelectionArbitrator() {
|
591
|
// TODO Auto-generated method stub
|
592
|
return null;
|
593
|
}
|
594
|
}
|