fix Ticket #5642
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / container / MisapplicationContainer.java
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 org.eclipse.swt.graphics.Font;
13
14 import eu.etaxonomy.cdm.model.taxon.Taxon;
15 import eu.etaxonomy.taxeditor.editor.EditorUtil;
16 import eu.etaxonomy.taxeditor.preference.Resources;
17
18 /**
19 * <p>MisapplicationContainer class.</p>
20 *
21 * @author p.ciardelli
22 * @created 13.01.2009
23 * @version 1.0
24 */
25 public class MisapplicationContainer extends AbstractGroupedContainer<Taxon> {
26
27 /**
28 * <p>Constructor for MisapplicationContainer.</p>
29 *
30 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
31 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
32 * @param misappliedName a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
33 */
34 public MisapplicationContainer(AbstractGroup group, Taxon misappliedName) {
35 super(misappliedName);
36 }
37
38
39 /* (non-Javadoc)
40 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
41 */
42 /** {@inheritDoc} */
43 @Override
44 protected void initializeComposite() {
45 setIsDraggable(true);
46 setFont(getViewerFont());
47
48 showSec();
49
50 initTextViewer();
51 }
52
53 @Override
54 protected void updateIcon() {
55 setIcon(MISAPPLIEDNAME_ICON);
56 }
57
58 private void showSec() {
59 if (getMisappliedName() == null) {
60 return;
61 }
62
63 if (getMisappliedName().getSec() == null) {
64 if (getMisappliedName().getAppendedPhrase() != null ){
65 setNonEditableInfo(getMisappliedName().getAppendedPhrase(), false);
66 }else{
67 setNonEditableInfo("sec. ???", false);
68 }
69 } else {
70 String title = getMisappliedName().getSec().getTitleCache();
71 title = title.replace("&", "&&");
72 String sec = "sec. ";
73 if (getMisappliedName().getAppendedPhrase() != null ){
74 sec = getMisappliedName().getAppendedPhrase() + " "+sec;
75 }
76 setNonEditableInfo(sec + title, false);
77 }
78 }
79
80 /**
81 * <p>getMisappliedName</p>
82 *
83 * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
84 */
85 public Taxon getMisappliedName() {
86 return getTaxonBase();
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 protected Font getViewerFont() {
92 return EditorUtil.getFont(Resources.MISAPPLIEDNAME_FONT);
93 }
94
95 /* (non-Javadoc)
96 * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
97 */
98 @Override
99 public void showAnnotations() {
100 if(getData().getSec() == null){
101 getNameViewer().addAnnotation(
102 new EditorAnnotation(0, "This misapplication requires a sec. reference."));
103 }
104 super.showAnnotations();
105 }
106
107
108 /** {@inheritDoc} */
109 @Override
110 protected void updateNonEditableInfo() {
111 showSec();
112 }
113
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
117 */
118 @Override
119 protected void updateIndent() {
120 setIndent(MISAPPLIEDNAME_INDENT);
121 }
122
123 }