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