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.editor.name.container;
|
11
|
|
12
|
import javax.naming.OperationNotSupportedException;
|
13
|
|
14
|
import org.eclipse.swt.graphics.Font;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
19
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
21
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
22
|
import eu.etaxonomy.taxeditor.singlesource.editor.name.container.EditorAnnotationFacade;
|
23
|
|
24
|
/**
|
25
|
* <p>ConceptContainer class.</p>
|
26
|
*
|
27
|
* @author p.ciardelli
|
28
|
* @created 26.01.2009
|
29
|
* @version 1.0
|
30
|
*/
|
31
|
public class ConceptContainer extends AbstractGroupedContainer<Taxon> {
|
32
|
|
33
|
private final TaxonRelationshipType relationshipType;
|
34
|
|
35
|
|
36
|
private ConceptContainer(TaxonNameEditor editor, AbstractGroup group,
|
37
|
Taxon relatedTaxon, TaxonRelationshipType relationshipType,
|
38
|
boolean acceptedTaxonIsFromTaxon) {
|
39
|
super(relatedTaxon);
|
40
|
|
41
|
// FIXME the acceptedTaxonIsFromTaxon is never used and
|
42
|
// I can't remember what is was used for in the first place
|
43
|
|
44
|
this.relationshipType = relationshipType;
|
45
|
try {
|
46
|
showRelationshipType();
|
47
|
} catch (OperationNotSupportedException e) {
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
|
53
|
*/
|
54
|
/** {@inheritDoc} */
|
55
|
@Override
|
56
|
protected void initializeComposite() {
|
57
|
|
58
|
setIsDraggable(true);
|
59
|
setFont(getViewerFont());
|
60
|
|
61
|
try {
|
62
|
showSec();
|
63
|
} catch (OperationNotSupportedException e) {
|
64
|
}
|
65
|
|
66
|
initTextViewer();
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
protected void updateIcon() {
|
71
|
setIcon(CONCEPT_ICON);
|
72
|
}
|
73
|
|
74
|
private void showRelationshipType() throws OperationNotSupportedException {
|
75
|
setNonEditableInfo(relationshipType.getLabel(), true);
|
76
|
}
|
77
|
|
78
|
private void showSec() throws OperationNotSupportedException {
|
79
|
if (getTaxonBase() == null) {
|
80
|
return;
|
81
|
}
|
82
|
|
83
|
if (getTaxonBase().getSec() == null) {
|
84
|
setNonEditableInfo("sec. ???", false);
|
85
|
} else {
|
86
|
setNonEditableInfo("sec. " + getTaxonBase().getSec().getTitleCache(), false);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* <p>getNewInstance</p>
|
92
|
*
|
93
|
* @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
|
94
|
* @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
|
95
|
* @param relationship a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationship} object.
|
96
|
* @return a {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptContainer} object.
|
97
|
*/
|
98
|
public static ConceptContainer getNewInstance(TaxonNameEditor editor, AbstractGroup group, TaxonRelationship relationship){
|
99
|
|
100
|
TaxonRelationshipType relationshipType = relationship.getType();
|
101
|
|
102
|
if (relationship.getToTaxon().equals(editor.getTaxon())) {
|
103
|
return new ConceptContainer (editor, group,
|
104
|
relationship.getFromTaxon(), relationshipType, false);
|
105
|
} else {
|
106
|
return new ConceptContainer (editor, group,
|
107
|
relationship.getToTaxon(), relationshipType, true);
|
108
|
}
|
109
|
}
|
110
|
|
111
|
/* (non-Javadoc)
|
112
|
* @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
|
113
|
*/
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
protected Font getViewerFont() {
|
117
|
return EditorUtil.getFont(Resources.CONCEPT_FONT);
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* <p>getRelatedTaxon</p>
|
122
|
*
|
123
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
124
|
*/
|
125
|
public Taxon getRelatedTaxon() {
|
126
|
return getTaxonBase();
|
127
|
}
|
128
|
|
129
|
/* (non-Javadoc)
|
130
|
* @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
|
131
|
*/
|
132
|
@Override
|
133
|
public void showAnnotations() throws OperationNotSupportedException {
|
134
|
if(getData().getSec() == null){
|
135
|
getNameViewer().addAnnotation(
|
136
|
new EditorAnnotationFacade(0, "This taxon requires a sec. reference."));
|
137
|
}
|
138
|
super.showAnnotations();
|
139
|
}
|
140
|
|
141
|
/** {@inheritDoc}
|
142
|
* @throws OperationNotSupportedException */
|
143
|
@Override
|
144
|
protected void updateNonEditableInfo() {
|
145
|
try {
|
146
|
showSec();
|
147
|
showRelationshipType();
|
148
|
} catch (OperationNotSupportedException e) {
|
149
|
}
|
150
|
}
|
151
|
|
152
|
/* (non-Javadoc)
|
153
|
* @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
|
154
|
*/
|
155
|
@Override
|
156
|
protected void updateIndent() {
|
157
|
setIndent(CONCEPT_INDENT);
|
158
|
}
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
|
165
|
|