.
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / view / propertysheetsupport / NameRelationsPropertySource.java
1
2 package eu.etaxonomy.taxeditor.view.propertysheetsupport;
3
4 import java.util.Collection;
5
6 import org.apache.log4j.Logger;
7
8 import eu.etaxonomy.cdm.model.name.NameRelationship;
9 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
10
11 public class NameRelationsPropertySource extends CollectionPropertySource {
12 private static final Logger logger = Logger
13 .getLogger(NameRelationsPropertySource.class);
14
15 private TaxonNameBase name;
16
17 public NameRelationsPropertySource(TaxonNameBase name, Collection collection) {
18 super(collection);
19 this.name = name;
20 }
21
22 @Override
23 protected String getItemDisplayName(Object item) {
24 String itemDisplayName = "";
25 if (item instanceof NameRelationship) {
26 NameRelationship nameRelation = (NameRelationship) item;
27 if (nameRelation.getType() != null) {
28 itemDisplayName = nameRelation.getType().getLabel();
29 } else {
30 itemDisplayName = "Relation has no type";
31 }
32 }
33 return itemDisplayName;
34 // TODO sort out difference b/w to and from rels
35 }
36
37 @Override
38 public Object getPropertyValue(Object id) {
39 if (id instanceof NameRelationship) {
40 TaxonNameBase<TaxonNameBase> relatedName;
41 String nameValue;
42 if (((NameRelationship) id).getFromName().equals(name)) {
43 relatedName = ((NameRelationship) id).getToName();
44 nameValue = "to " + relatedName.getTitleCache();
45 } else {
46 relatedName = ((NameRelationship) id).getFromName();
47 nameValue = relatedName.getTitleCache();
48 }
49 return nameValue;
50 }
51 return null;
52 }
53
54 @Override
55 public void setPropertyValue(Object id, Object value) {
56 // Fields not editable in property sheet view
57 }
58
59 @Override
60 public String toString() {
61 // "Name Relations" header has no value
62 return "";
63 }
64 }