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