minor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / name / container / ConceptContainer.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.cdm.model.taxon.TaxonRelationship;
16 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
17 import eu.etaxonomy.taxeditor.editor.EditorUtil;
18 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
19 import eu.etaxonomy.taxeditor.preference.Resources;
20
21 /**
22 * <p>ConceptContainer class.</p>
23 *
24 * @author p.ciardelli
25 * @created 26.01.2009
26 * @version 1.0
27 */
28 public class ConceptContainer extends AbstractGroupedContainer<Taxon> {
29
30 private final TaxonRelationshipType relationshipType;
31
32
33 private ConceptContainer(TaxonNameEditor editor, AbstractGroup group,
34 Taxon relatedTaxon, TaxonRelationshipType relationshipType,
35 boolean acceptedTaxonIsFromTaxon) {
36 super(relatedTaxon);
37
38 // FIXME the acceptedTaxonIsFromTaxon is never used and
39 // I can't remember what is was used for in the first place
40
41 this.relationshipType = relationshipType;
42 showRelationshipType();
43 }
44
45 /* (non-Javadoc)
46 * @see eu.etaxonomy.taxeditor.editor.name.NameComposite#initializeComposite()
47 */
48 /** {@inheritDoc} */
49 @Override
50 protected void initializeComposite() {
51
52 setIsDraggable(true);
53 setFont(getViewerFont());
54
55 showSec();
56
57 initTextViewer();
58 }
59
60 @Override
61 protected void updateIcon() {
62 setIcon(CONCEPT_ICON);
63 }
64
65 private void showRelationshipType() {
66 setNonEditableInfo(relationshipType.getLabel(), true);
67 }
68
69 private void showSec() {
70 if (getTaxonBase() == null) {
71 return;
72 }
73
74 if (getTaxonBase().getSec() == null) {
75 setNonEditableInfo("sec. ???", false);
76 } else {
77 setNonEditableInfo("sec. " + getTaxonBase().getSec().getTitleCache(), false);
78 }
79 }
80
81 /**
82 * <p>getNewInstance</p>
83 *
84 * @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object.
85 * @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object.
86 * @param relationship a {@link eu.etaxonomy.cdm.model.taxon.TaxonRelationship} object.
87 * @return a {@link eu.etaxonomy.taxeditor.editor.name.container.ConceptContainer} object.
88 */
89 public static ConceptContainer getNewInstance(TaxonNameEditor editor, AbstractGroup group, TaxonRelationship relationship){
90
91 TaxonRelationshipType relationshipType = relationship.getType();
92
93 if (relationship.getToTaxon().equals(editor.getTaxon())) {
94 return new ConceptContainer (editor, group,
95 relationship.getFromTaxon(), relationshipType, false);
96 } else {
97 return new ConceptContainer (editor, group,
98 relationship.getToTaxon(), relationshipType, true);
99 }
100 }
101
102 /* (non-Javadoc)
103 * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#getViewerFont()
104 */
105 /** {@inheritDoc} */
106 @Override
107 protected Font getViewerFont() {
108 return EditorUtil.getFont(Resources.CONCEPT_FONT);
109 }
110
111 /**
112 * <p>getRelatedTaxon</p>
113 *
114 * @return a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
115 */
116 public Taxon getRelatedTaxon() {
117 return getTaxonBase();
118 }
119
120 /* (non-Javadoc)
121 * @see eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer#showAnnotations()
122 */
123 @Override
124 public void showAnnotations() {
125 if(getData().getSec() == null){
126 getNameViewer().addAnnotation(
127 new EditorAnnotation(0, "This taxon requires a sec. reference."));
128 }
129 super.showAnnotations();
130 }
131
132 /** {@inheritDoc} */
133 @Override
134 protected void updateNonEditableInfo() {
135 showSec();
136 showRelationshipType();
137 }
138
139 /* (non-Javadoc)
140 * @see eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer#updateIndent()
141 */
142 @Override
143 protected void updateIndent() {
144 setIndent(CONCEPT_INDENT);
145 }
146 }
147
148
149
150
151
152