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