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