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