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 java.util.ArrayList;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.swt.graphics.Font;
|
16
|
|
17
|
import eu.etaxonomy.cdm.format.taxon.TaxonRelationshipFormatter;
|
18
|
import eu.etaxonomy.cdm.model.common.Language;
|
19
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
21
|
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper;
|
22
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
23
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
24
|
import eu.etaxonomy.taxeditor.editor.name.container.EditorAnnotation;
|
25
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4.ConceptType;
|
27
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
28
|
import eu.etaxonomy.taxeditor.model.NameHelper;
|
29
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
30
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
31
|
|
32
|
/**
|
33
|
* @author pplitzner
|
34
|
* @date Aug 24, 2017
|
35
|
*/
|
36
|
public class ConceptContainerE4 extends AbstractGroupedContainerE4<Taxon> {
|
37
|
TaxonRelationship relationship;
|
38
|
TaxonRelationshipFormatter misappliedFormatter;
|
39
|
ConceptType conceptType;
|
40
|
|
41
|
public ConceptContainerE4(AbstractGroupE4 group, Taxon misappliedName, ConceptType conceptType) {
|
42
|
super(group, misappliedName);
|
43
|
this.conceptType = conceptType;
|
44
|
misappliedFormatter = new TaxonRelationshipFormatter();
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
protected void initializeComposite() {
|
49
|
setIsDraggable(true);
|
50
|
setFont(getViewerFont());
|
51
|
TaxonNameEditorE4 editor = getEditor();
|
52
|
Taxon taxon = editor.getTaxon();
|
53
|
for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
|
54
|
if (rel.getType().isAnyMisappliedName() && this.conceptType.equals(ConceptType.Misapplication)){
|
55
|
relationship = rel;
|
56
|
break;
|
57
|
}else if (rel.getType().isAnySynonym() && this.conceptType.equals(ConceptType.Synonym)){
|
58
|
relationship = rel;
|
59
|
break;
|
60
|
} else if (rel.getType().isInvalidDesignation() && this.conceptType.equals(ConceptType.InvalidDesignation)){
|
61
|
relationship = rel;
|
62
|
break;
|
63
|
}
|
64
|
}
|
65
|
showSec();
|
66
|
initTextViewer();
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
protected void updateIcon() {
|
71
|
if (relationship.getType().isAnyMisappliedName() ){
|
72
|
setIcon(MISAPPLIEDNAME_ICON);
|
73
|
}else if (relationship.getType().isInvalidDesignation()){
|
74
|
setIcon(INVALID_TYPE_DESIGNATION_ICON);
|
75
|
}else if (relationship.getType().isProParte()){
|
76
|
setIcon(PRO_PARTE_SYNONYM_ICON);
|
77
|
}else if (relationship.getType().isAnySynonym()){
|
78
|
setIcon(PARTIAL_SYNONYM_ICON);
|
79
|
}
|
80
|
}
|
81
|
|
82
|
private void showSec() {
|
83
|
if (getMisappliedName() == null) {
|
84
|
return;
|
85
|
}
|
86
|
List<Language> languages = new ArrayList<>();
|
87
|
languages.add(CdmStore.getDefaultLanguage());
|
88
|
List<TaggedText> taggedText = misappliedFormatter.getTaggedText(relationship, true, languages, true);
|
89
|
|
90
|
if (taggedText != null){
|
91
|
String title = TaggedCacheHelper.createString(taggedText);
|
92
|
title = title.replace("&", "&&");
|
93
|
setNonEditableInfo(title, false);
|
94
|
}
|
95
|
|
96
|
}
|
97
|
|
98
|
public Taxon getMisappliedName() {
|
99
|
return getTaxonBase();
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
protected Font getViewerFont() {
|
104
|
return AbstractUtility.getFont(Resources.MISAPPLIEDNAME_FONT);
|
105
|
}
|
106
|
|
107
|
@Override
|
108
|
public void showAnnotations() {
|
109
|
if(getData().getSec() == null){
|
110
|
getNameViewer().addAnnotation(
|
111
|
new EditorAnnotation(0, Messages.MisapplicationContainer_SEC_REF_REQUIRED));
|
112
|
}
|
113
|
super.showAnnotations();
|
114
|
}
|
115
|
|
116
|
@Override
|
117
|
protected void updateNonEditableInfo() {
|
118
|
showSec();
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
protected void updateIndent() {
|
123
|
setIndent(MISAPPLIEDNAME_INDENT);
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
protected void initTextViewer() {
|
128
|
updateIndent();
|
129
|
|
130
|
updateIcon();
|
131
|
String text;
|
132
|
if (!conceptType.equals(ConceptType.Synonym) ){
|
133
|
text = NameHelper.getDisplayNameCache(getData());
|
134
|
}else{
|
135
|
text = NameHelper.getDisplayName(getData());
|
136
|
}
|
137
|
|
138
|
if (text.length() == 0) {
|
139
|
initEmptyText();
|
140
|
} else {
|
141
|
getNameViewer().setText(text);
|
142
|
placeCursor();
|
143
|
}
|
144
|
calculateAnnotations();
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
public void refresh() {
|
149
|
// showNameRelations();
|
150
|
if (relationship.getType().isAnyMisappliedName()){
|
151
|
conceptType = ConceptType.Misapplication;
|
152
|
}else if (relationship.getType().isAnySynonym()){
|
153
|
conceptType = ConceptType.Synonym;
|
154
|
}else{
|
155
|
conceptType = ConceptType.InvalidDesignation;
|
156
|
}
|
157
|
|
158
|
String text;
|
159
|
if (!conceptType.equals(ConceptType.Synonym) ){
|
160
|
text = NameHelper.getDisplayNameCache(getData());
|
161
|
}else{
|
162
|
text = NameHelper.getDisplayName(getData());
|
163
|
}
|
164
|
|
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
|
setDelayedSelection();
|
185
|
|
186
|
enableFreeText();
|
187
|
}
|
188
|
}
|