Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / store / model / NameRelationsUtil.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.store.model;
12
13 import java.util.SortedSet;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
18 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19 import eu.etaxonomy.taxeditor.store.CdmStore;
20 import eu.etaxonomy.taxeditor.store.preference.PreferencesUtil;
21
22 /**
23 * @author p.ciardelli
24 * @created 30.04.2009
25 * @version 1.0
26 */
27 public class NameRelationsUtil {
28 private static final Logger logger = Logger
29 .getLogger(NameRelationsUtil.class);
30
31 /**
32 * Get the type's label out of the session's name relations vocabulary, not directly
33 * from the object.
34 *
35 * @param type
36 * @return
37 */
38 public static String getNameRelationTypeLabel(NameRelationshipType type) {
39 boolean isZoological =
40 PreferencesUtil.getPreferredNomenclaturalCode()
41 == NomenclaturalCode.ICZN ? true : false;
42 return getNameRelationTypeLabel(type, isZoological);
43 }
44
45 public static String getNameRelationTypeLabel(NameRelationshipType type, boolean isZoological) {
46
47 SortedSet<NameRelationshipType> vocab =
48 CdmStore.getDefault().getNameRelationshipTypes();
49
50 // SortedSet<NameRelationshipType> vocab =
51 // CdmSessionDataRepository.getDefault().getNameRelationshipTypes();
52 for (NameRelationshipType type1 : vocab) {
53 if (type1.equals(type)) {
54
55 if (isZoological &&
56 type1.equals(NameRelationshipType.BASIONYM())) {
57 return "original combination for";
58 } else {
59 return type1.getLabel();
60 }
61 }
62 }
63 return "";
64 }
65
66 /**
67 * Get the inverse representation of the type out of the session's
68 * name relations vocabulary, not directly from the object.
69 *
70 * @param type
71 * @return
72 */
73 public static String getNameRelationInverseTypeLabel(NameRelationshipType type) {
74 boolean isZoological =
75 PreferencesUtil.getPreferredNomenclaturalCode()
76 == NomenclaturalCode.ICZN ? true : false;
77 return getNameRelationInverseTypeLabel(type, isZoological);
78 }
79
80 public static String getNameRelationInverseTypeLabel(NameRelationshipType type, boolean isZoological) {
81
82 SortedSet<NameRelationshipType> vocab =
83 CdmStore.getDefault().getNameRelationshipTypes();
84
85 // SortedSet<NameRelationshipType> vocab =
86 // CdmSessionDataRepository.getDefault().getNameRelationshipTypes();
87 for (NameRelationshipType type1 : vocab) {
88 if (type1.equals(type)) {
89 return type1.getInverseLabel();
90 }
91 }
92 return "";
93 }
94 }