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.e4.container;
|
11
|
|
12
|
import org.apache.commons.lang.StringUtils;
|
13
|
import org.eclipse.swt.graphics.Font;
|
14
|
|
15
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
16
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
17
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
19
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation;
|
21
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
22
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
23
|
import eu.etaxonomy.taxeditor.model.NameHelper;
|
24
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
* @author pplitzner
|
29
|
* @date Aug 24, 2017
|
30
|
*
|
31
|
*/
|
32
|
public class ConceptContainerE4 extends AbstractGroupedContainerE4<Taxon> {
|
33
|
TaxonRelationship relationship;
|
34
|
private boolean isMisapplication;
|
35
|
|
36
|
public ConceptContainerE4(AbstractGroupE4 group, Taxon misappliedName, boolean isMisapplication) {
|
37
|
super(group, misappliedName);
|
38
|
this.isMisapplication = isMisapplication;
|
39
|
|
40
|
}
|
41
|
|
42
|
/** {@inheritDoc} */
|
43
|
@Override
|
44
|
protected void initializeComposite() {
|
45
|
setIsDraggable(true);
|
46
|
setFont(getViewerFont());
|
47
|
TaxonNameEditorE4 editor = getEditor();
|
48
|
Taxon taxon = editor.getTaxon();
|
49
|
for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
|
50
|
if (rel.getType().isAnyMisappliedName() && isMisapplication){
|
51
|
relationship = rel;
|
52
|
break;
|
53
|
}else if (rel.getType().isAnySynonym() && !isMisapplication){
|
54
|
relationship = rel;
|
55
|
break;
|
56
|
}
|
57
|
}
|
58
|
showSec();
|
59
|
|
60
|
initTextViewer();
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
protected void updateIcon() {
|
65
|
if (relationship.getType().isAnyMisappliedName()){
|
66
|
setIcon(MISAPPLIEDNAME_ICON);
|
67
|
}else if (relationship.getType().isProParte()){
|
68
|
setIcon(PRO_PARTE_SYNONYM_ICON);
|
69
|
}else {
|
70
|
setIcon(PARTIAL_SYNONYM_ICON);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
private void showSec() {
|
75
|
if (getMisappliedName() == null) {
|
76
|
return;
|
77
|
}
|
78
|
String title = "";
|
79
|
String author = "";
|
80
|
TaxonName conceptName = HibernateProxyHelper.deproxy(getMisappliedName().getName());
|
81
|
if (isMisapplication && StringUtils.isNotBlank(conceptName.getAuthorshipCache())){
|
82
|
author = ", non " + conceptName.getAuthorshipCache();
|
83
|
}
|
84
|
if ((isMisapplication &&getMisappliedName().getSec() == null) || (!isMisapplication && relationship.getCitation() == null)) {
|
85
|
if (getMisappliedName().getAppendedPhrase() != null ){
|
86
|
title = getMisappliedName().getAppendedPhrase();
|
87
|
}else if (isMisapplication){
|
88
|
title = "auct.";
|
89
|
|
90
|
}
|
91
|
|
92
|
} else {
|
93
|
String sec ;
|
94
|
if (isMisapplication){
|
95
|
sec = " sensu ";
|
96
|
}else{
|
97
|
sec = " syn. sec. ";
|
98
|
}
|
99
|
if (getMisappliedName().getAppendedPhrase() != null ){
|
100
|
sec = getMisappliedName().getAppendedPhrase() + " " + sec;
|
101
|
}
|
102
|
if (isMisapplication){
|
103
|
title += sec + getMisappliedName().getSec().getCacheStrategy().getCitation(getMisappliedName().getSec());
|
104
|
}else{
|
105
|
title += sec + relationship.getCitation().getCacheStrategy().getCitation(relationship.getCitation());
|
106
|
}
|
107
|
}
|
108
|
if (relationship.getType().isProParte() && isMisapplication){
|
109
|
title += " p.p. ";
|
110
|
}
|
111
|
title += author;
|
112
|
title = title.replace("&", "&&");
|
113
|
setNonEditableInfo(title, false);
|
114
|
}
|
115
|
|
116
|
public Taxon getMisappliedName() {
|
117
|
return getTaxonBase();
|
118
|
}
|
119
|
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
protected Font getViewerFont() {
|
123
|
return AbstractUtility.getFont(Resources.MISAPPLIEDNAME_FONT);
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
public void showAnnotations() {
|
128
|
if(getData().getSec() == null){
|
129
|
getNameViewer().addAnnotation(
|
130
|
new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
|
131
|
}
|
132
|
super.showAnnotations();
|
133
|
}
|
134
|
|
135
|
|
136
|
/** {@inheritDoc} */
|
137
|
@Override
|
138
|
protected void updateNonEditableInfo() {
|
139
|
showSec();
|
140
|
}
|
141
|
|
142
|
@Override
|
143
|
protected void updateIndent() {
|
144
|
setIndent(MISAPPLIEDNAME_INDENT);
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
protected void initTextViewer() {
|
149
|
|
150
|
// showNameRelations();
|
151
|
|
152
|
updateIndent();
|
153
|
|
154
|
updateIcon();
|
155
|
String text;
|
156
|
if (isMisapplication){
|
157
|
text = NameHelper.getDisplayNameCache(getData());
|
158
|
}else{
|
159
|
text = NameHelper.getDisplayName(getData());
|
160
|
}
|
161
|
|
162
|
if (text.length() == 0) {
|
163
|
initEmptyText();
|
164
|
} else {
|
165
|
getNameViewer().setText(text);
|
166
|
placeCursor();
|
167
|
}
|
168
|
calculateAnnotations();
|
169
|
}
|
170
|
|
171
|
@Override
|
172
|
public void refresh() {
|
173
|
// showNameRelations();
|
174
|
if (relationship.getType().isAnyMisappliedName()){
|
175
|
isMisapplication = true;
|
176
|
}else{
|
177
|
isMisapplication = false;
|
178
|
}
|
179
|
String text;
|
180
|
if (isMisapplication){
|
181
|
text = NameHelper.getDisplayNameCache(getData());
|
182
|
}else{
|
183
|
text = NameHelper.getDisplayName(getData());
|
184
|
}
|
185
|
|
186
|
|
187
|
if (getNameViewer().getTextWidget() == null) {
|
188
|
// we might get here via dnd. Look slike it can be ignored
|
189
|
return;
|
190
|
}
|
191
|
|
192
|
if (text.length() == 0) {
|
193
|
initEmptyText();
|
194
|
} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
|
195
|
removeListener();
|
196
|
getNameViewer().getTextWidget().setText(text);
|
197
|
addListener();
|
198
|
}
|
199
|
|
200
|
updateNonEditableInfo();
|
201
|
|
202
|
updateIcon();
|
203
|
// placeCursor();
|
204
|
updateIndent();
|
205
|
|
206
|
enableFreeText();
|
207
|
}
|
208
|
|
209
|
}
|