2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.container
;
12 import javax
.persistence
.GenerationType
;
14 import org
.apache
.commons
.lang
.StringUtils
;
15 import org
.eclipse
.swt
.graphics
.Font
;
17 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
22 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
23 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
25 import eu
.etaxonomy
.taxeditor
.model
.NameHelper
;
26 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
29 * <p>MisapplicationContainer class.</p>
35 public class MisapplicationContainer
extends AbstractGroupedContainer
<Taxon
> {
36 TaxonRelationship misapplication
;
39 * <p>Constructor for MisapplicationContainer.</p>
41 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
42 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
43 * @param misappliedName a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
45 public MisapplicationContainer(AbstractGroup group
, Taxon misappliedName
) {
46 super(misappliedName
);
52 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
56 protected void initializeComposite() {
58 setFont(getViewerFont());
59 TaxonNameEditor editor
= getEditor();
60 Taxon taxon
= editor
.getTaxon();
61 for (TaxonRelationship rel
: taxon
.getTaxonRelations(getMisappliedName())){
62 if (rel
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR())){
73 protected void updateIcon() {
74 setIcon(MISAPPLIEDNAME_ICON
);
77 private void showSec() {
78 if (getMisappliedName() == null) {
83 TaxonName misappliedNameName
= HibernateProxyHelper
.deproxy(getMisappliedName().getName(), TaxonName
.class);
84 if (misappliedNameName
.getAuthorshipCache() != null && !StringUtils
.isBlank(misappliedNameName
.getAuthorshipCache())&& getMisappliedName().getAppendedPhrase() == null){
85 author
= ", non " + misappliedNameName
.getAuthorshipCache();
87 if (misapplication
.getCitation() == null) {
88 if (getMisappliedName().getAppendedPhrase() != null ){
89 title
= getMisappliedName().getAppendedPhrase();
91 title
= "auct."; //$NON-NLS-1$
96 String sec
= " sensu "; //$NON-NLS-1$
97 if (getMisappliedName().getAppendedPhrase() != null ){
98 sec
= getMisappliedName().getAppendedPhrase() + " "+sec
; //$NON-NLS-1$
100 title
+= sec
+ getMisappliedName().getSec().getTitleCache();
107 title
= title
.replace("&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
108 setNonEditableInfo(title
, false);
112 * <p>getMisappliedName</p>
114 * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
116 public Taxon
getMisappliedName() {
117 return getTaxonBase();
122 protected Font
getViewerFont() {
123 return EditorUtil
.getFont(Resources
.MISAPPLIEDNAME_FONT
);
127 * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
130 public void showAnnotations() {
131 if(getData().getSec() == null){
132 getNameViewer().addAnnotation(
133 new EditorAnnotation(0, Messages
.MisapplicationContainer_SEC_REF_REQUIRED
));
135 super.showAnnotations();
141 protected void updateNonEditableInfo() {
147 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
150 protected void updateIndent() {
151 setIndent(MISAPPLIEDNAME_INDENT
);
160 protected void initTextViewer() {
162 // showNameRelations();
168 String text
= NameHelper
.getDisplayNameCache(getData());
170 if (text
.length() == 0) {
173 getNameViewer().setText(text
);
176 calculateAnnotations();
180 public void refresh() {
181 // showNameRelations();
183 String text
= NameHelper
.getDisplayNameCache(getData());
185 if (getNameViewer().getTextWidget() == null) {
186 // we might get here via dnd. Look slike it can be ignored
190 if (text
.length() == 0) {
192 } else if (!getNameViewer().getTextWidget().getText().equals(text
)) {
194 getNameViewer().getTextWidget().setText(text
);
198 updateNonEditableInfo();