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.element.LayoutConstants;
|
26
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
28
|
|
29
|
/**
|
30
|
* <p>NameRelationshipDetailElement class.</p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Mar 18, 2010
|
34
|
*/
|
35
|
public class NameRelationshipDetailElement extends AbstractSourcedEntityElement<NameRelationship>{
|
36
|
|
37
|
private RuleConsideredElement ruleConsidered;
|
38
|
private EntitySelectionElement<?> selection_toName;
|
39
|
private TermComboElement<NameRelationshipType> combo_relationshipType;
|
40
|
private LabelElement labelElement;
|
41
|
|
42
|
// private OriginalSourceElement sourceElement;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for NameRelationshipDetailElement.</p>
|
46
|
*
|
47
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
48
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
49
|
* @param entity a {@link eu.etaxonomy.cdm.model.name.NameRelationship} object.
|
50
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
51
|
* @param style a int.
|
52
|
*/
|
53
|
public NameRelationshipDetailElement(CdmFormFactory cdmFormFactory,
|
54
|
AbstractFormSection formElement,
|
55
|
NameRelationship entity, SelectionListener removeListener, int style){
|
56
|
super(cdmFormFactory, formElement, entity, removeListener, "Source", style);
|
57
|
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
public void createControls(ICdmFormElement element, int style) {
|
62
|
|
63
|
NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
|
64
|
labelElement = formFactory.createLabel(element, null);
|
65
|
|
66
|
if (config == null || config.isNameRelationsRuleConsideredActivated()){
|
67
|
ruleConsidered = formFactory.createRuleConsideredElement(
|
68
|
element, "Rule Considered", config == null
|
69
|
|| config.isNameRelationsRuleConsideredCodeEditionActivated(), style);
|
70
|
}
|
71
|
LabelElement spacer = formFactory.createLabel(element, null);
|
72
|
spacer.getLayoutComposite().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
73
|
addElement(spacer);
|
74
|
super.createControls(element, style);
|
75
|
setSourceLabel("Source");
|
76
|
if (entity != null){
|
77
|
setEntity(entity);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public void setEntity(NameRelationship entity) {
|
83
|
if (labelElement != null){
|
84
|
String text = (entity.getFromName() == null? "-":entity.getFromName().getTitleCache())
|
85
|
+ " " +(entity.getType()==null?"(no type)":entity.getType().getLabel())
|
86
|
+ " " + (entity.getToName()==null?"-":entity.getToName().getTitleCache());
|
87
|
labelElement.setText(text);
|
88
|
if (ruleConsidered != null){
|
89
|
ruleConsidered.setElement(entity);
|
90
|
}
|
91
|
}
|
92
|
|
93
|
super.setEntity(entity);
|
94
|
}
|
95
|
|
96
|
@Override
|
97
|
public void handleEvent(Object eventSource) {
|
98
|
if(eventSource == combo_relationshipType){
|
99
|
getEntity().setType(combo_relationshipType.getSelection());
|
100
|
}
|
101
|
else if(eventSource == selection_toName){
|
102
|
MessagingUtils.error(getClass(), "No API call available.", null);
|
103
|
}
|
104
|
|
105
|
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public void setBackground(Color color) {
|
110
|
if(labelElement != null) {
|
111
|
labelElement.setBackground(color);
|
112
|
}
|
113
|
super.setBackground(color);
|
114
|
}
|
115
|
|
116
|
|
117
|
}
|