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.name;
|
11
|
|
12
|
import org.eclipse.swt.events.SelectionListener;
|
13
|
import org.eclipse.swt.graphics.Color;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
16
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
17
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
18
|
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
|
19
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
20
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.LabelElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractReferencedEntityElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
27
|
|
28
|
/**
|
29
|
* <p>NameRelationshipDetailElement class.</p>
|
30
|
*
|
31
|
* @author n.hoffmann
|
32
|
* @created Mar 18, 2010
|
33
|
*/
|
34
|
public class NameRelationshipDetailElement extends AbstractReferencedEntityElement<NameRelationship>{
|
35
|
|
36
|
private RuleConsideredElement ruleConsidered;
|
37
|
private EntitySelectionElement<?> selection_toName;
|
38
|
private TermComboElement<NameRelationshipType> combo_relationshipType;
|
39
|
private LabelElement label;
|
40
|
|
41
|
/**
|
42
|
* <p>Constructor for NameRelationshipDetailElement.</p>
|
43
|
*
|
44
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
45
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
46
|
* @param entity a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
|
47
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
48
|
* @param style a int.
|
49
|
*/
|
50
|
public NameRelationshipDetailElement(CdmFormFactory cdmFormFactory,
|
51
|
AbstractFormSection formElement,
|
52
|
NameRelationship entity, SelectionListener removeListener, int style) {
|
53
|
super(cdmFormFactory, formElement, entity, removeListener, style);
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public void createControls(ICdmFormElement element, int style) {
|
58
|
NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
|
59
|
label = formFactory.createLabel(element, null);
|
60
|
if (config == null || config.isNameRelationsRuleConsideredActivated()){
|
61
|
ruleConsidered = formFactory.createRuleConsideredElement(
|
62
|
element, "Rule Considered", config == null
|
63
|
|| config.isNameRelationsRuleConsideredCodeEditionActivated(), style);
|
64
|
}
|
65
|
super.createControls(element, style);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public void setEntity(NameRelationship entity) {
|
70
|
String text = (entity.getFromName() == null? "-":entity.getFromName().getTitleCache())
|
71
|
+ " is " + (entity.getType()==null?"(no type)":entity.getType().getLabel())
|
72
|
+ " " + (entity.getToName()==null?"-":entity.getToName().getTitleCache());
|
73
|
label.setText(text);
|
74
|
if (ruleConsidered != null){
|
75
|
ruleConsidered.setElement(entity);
|
76
|
}
|
77
|
super.setEntity(entity);
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public void handleEvent(Object eventSource) {
|
82
|
if(eventSource == combo_relationshipType){
|
83
|
getEntity().setType(combo_relationshipType.getSelection());
|
84
|
}
|
85
|
else if(eventSource == selection_toName){
|
86
|
MessagingUtils.error(getClass(), "No API call available.", null);
|
87
|
}
|
88
|
else if(eventSource == selection_reference){
|
89
|
getEntity().setCitation(selection_reference.getSelection());
|
90
|
}
|
91
|
else if(eventSource == text_referenceDetail){
|
92
|
getEntity().setCitationMicroReference(text_referenceDetail.getText());
|
93
|
}
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void setBackground(Color color) {
|
98
|
if(label != null) {
|
99
|
label.setBackground(color);
|
100
|
}
|
101
|
super.setBackground(color);
|
102
|
}
|
103
|
}
|