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.persistence.GenerationType;
|
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.l10n.Messages;
|
21
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
22
|
import eu.etaxonomy.taxeditor.model.NameHelper;
|
23
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
24
|
|
25
|
/**
|
26
|
* <p>MisapplicationContainer class.</p>
|
27
|
*
|
28
|
* @author p.ciardelli
|
29
|
* @created 13.01.2009
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
public class MisapplicationContainer extends AbstractGroupedContainer<Taxon> {
|
33
|
TaxonRelationship misapplication;
|
34
|
|
35
|
/**
|
36
|
* <p>Constructor for MisapplicationContainer.</p>
|
37
|
*
|
38
|
* @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
|
39
|
* @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
|
40
|
* @param misappliedName a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
41
|
*/
|
42
|
public MisapplicationContainer(AbstractGroup group, Taxon misappliedName) {
|
43
|
super(misappliedName);
|
44
|
|
45
|
}
|
46
|
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
|
50
|
*/
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
protected void initializeComposite() {
|
54
|
setIsDraggable(true);
|
55
|
setFont(getViewerFont());
|
56
|
TaxonNameEditor editor = getEditor();
|
57
|
Taxon taxon = editor.getTaxon();
|
58
|
for (TaxonRelationship rel: taxon.getTaxonRelations(getMisappliedName())){
|
59
|
if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
|
60
|
misapplication = rel;
|
61
|
break;
|
62
|
}
|
63
|
}
|
64
|
showSec();
|
65
|
|
66
|
initTextViewer();
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
protected void updateIcon() {
|
71
|
setIcon(MISAPPLIEDNAME_ICON);
|
72
|
}
|
73
|
|
74
|
private void showSec() {
|
75
|
if (getMisappliedName() == null) {
|
76
|
return;
|
77
|
}
|
78
|
String title = "";
|
79
|
if (getMisappliedName().getName().getAuthorshipCache() != null && getMisappliedName().getAppendedPhrase() == null){
|
80
|
title += "non " + getMisappliedName().getName().getAuthorshipCache();
|
81
|
}
|
82
|
if (misapplication.getCitation() == null) {
|
83
|
if (getMisappliedName().getAppendedPhrase() != null ){
|
84
|
setNonEditableInfo(getMisappliedName().getAppendedPhrase(), false);
|
85
|
}else{
|
86
|
setNonEditableInfo("auct.", false); //$NON-NLS-1$
|
87
|
}
|
88
|
} else {
|
89
|
String sec = " sensu "; //$NON-NLS-1$
|
90
|
if (getMisappliedName().getAppendedPhrase() != null ){
|
91
|
sec = getMisappliedName().getAppendedPhrase() + " "+sec; //$NON-NLS-1$
|
92
|
}
|
93
|
title += sec + misapplication.getCitation().getTitleCache();
|
94
|
title = title.replace("&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
|
95
|
|
96
|
|
97
|
setNonEditableInfo(title, false);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* <p>getMisappliedName</p>
|
103
|
*
|
104
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
105
|
*/
|
106
|
public Taxon getMisappliedName() {
|
107
|
return getTaxonBase();
|
108
|
}
|
109
|
|
110
|
/** {@inheritDoc} */
|
111
|
@Override
|
112
|
protected Font getViewerFont() {
|
113
|
return EditorUtil.getFont(Resources.MISAPPLIEDNAME_FONT);
|
114
|
}
|
115
|
|
116
|
/* (non-Javadoc)
|
117
|
* @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
|
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
|
|
136
|
/* (non-Javadoc)
|
137
|
* @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
|
138
|
*/
|
139
|
@Override
|
140
|
protected void updateIndent() {
|
141
|
setIndent(MISAPPLIEDNAME_INDENT);
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* <p>
|
146
|
* initTextViewer
|
147
|
* </p>
|
148
|
*/
|
149
|
@Override
|
150
|
protected void initTextViewer() {
|
151
|
|
152
|
// showNameRelations();
|
153
|
|
154
|
updateIndent();
|
155
|
|
156
|
updateIcon();
|
157
|
|
158
|
String text = NameHelper.getDisplayNameCache(getData());
|
159
|
|
160
|
if (text.length() == 0) {
|
161
|
initEmptyText();
|
162
|
} else {
|
163
|
getNameViewer().setText(text);
|
164
|
placeCursor();
|
165
|
}
|
166
|
calculateAnnotations();
|
167
|
}
|
168
|
|
169
|
@Override
|
170
|
public void refresh() {
|
171
|
// showNameRelations();
|
172
|
|
173
|
String text = NameHelper.getDisplayNameCache(getData());
|
174
|
|
175
|
if (getNameViewer().getTextWidget() == null) {
|
176
|
// we might get here via dnd. Look slike it can be ignored
|
177
|
return;
|
178
|
}
|
179
|
|
180
|
if (text.length() == 0) {
|
181
|
initEmptyText();
|
182
|
} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
|
183
|
removeListener();
|
184
|
getNameViewer().getTextWidget().setText(text);
|
185
|
addListener();
|
186
|
}
|
187
|
|
188
|
updateNonEditableInfo();
|
189
|
|
190
|
updateIcon();
|
191
|
// placeCursor();
|
192
|
updateIndent();
|
193
|
|
194
|
enableFreeText();
|
195
|
}
|
196
|
|
197
|
}
|