p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / name / NameRelationsPropertySource.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 package eu.etaxonomy.taxeditor.propertysheet.name;
10
11 import java.util.Collection;
12
13 import org.apache.log4j.Logger;
14
15 import eu.etaxonomy.cdm.model.name.NameRelationship;
16 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
17 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
18 import eu.etaxonomy.cdm.model.name.ZoologicalName;
19 import eu.etaxonomy.taxeditor.controller.GlobalController;
20 import eu.etaxonomy.taxeditor.propertysheet.CollectionPropertySource;
21
22 public class NameRelationsPropertySource extends CollectionPropertySource {
23 private static final Logger logger = Logger
24 .getLogger(NameRelationsPropertySource.class);
25
26 private TaxonNameBase name;
27 private boolean isZoological = false;
28
29 public NameRelationsPropertySource(TaxonNameBase name, Collection collection) {
30 super(collection, name);
31 this.name = name;
32 if (name instanceof ZoologicalName) {
33 isZoological = true;
34 }
35 }
36
37 @Override
38 protected String getItemDisplayName(Object item) {
39 String itemDisplayName = "";
40
41 if (item instanceof NameRelationship) {
42
43 NameRelationship nameRelation = (NameRelationship) item;
44
45 if (nameRelation.getFromName() instanceof ZoologicalName &&
46 nameRelation.getToName() instanceof ZoologicalName) {
47 isZoological = true;
48 }
49
50 if (nameRelation.getType() != null) {
51
52 NameRelationshipType type = nameRelation.getType();
53
54 String label;
55 if (nameRelation.getFromName().equals(getCollectionOwner())) {
56 label = GlobalController.getNameRelationTypeLabel(type, isZoological);
57 } else {
58 label = GlobalController.getNameRelationInverseTypeLabel(type, isZoological);
59 }
60 itemDisplayName = label;
61 } else {
62 itemDisplayName = "Relation has no type";
63 }
64 }
65 return itemDisplayName;
66 }
67
68 @Override
69 public Object getPropertyValue(Object id) {
70 if (id instanceof NameRelationship) {
71 TaxonNameBase relatedName;
72 if (((NameRelationship) id).getFromName().equals(name)) {
73 relatedName = ((NameRelationship) id).getToName();
74 } else {
75 relatedName = ((NameRelationship) id).getFromName();
76 }
77 return relatedName.getTitleCache();
78 }
79 return null;
80 }
81
82 @Override
83 public void setPropertyValue(Object id, Object value) {
84 // Fields not editable in property sheet view
85 }
86
87 @Override
88 public String toString() {
89 // "Name Relations" header has no value
90 return "";
91 }
92 }