(no commit message)
[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 }
35
36 @Override
37 public Object getPropertyValue(Object id) {
38 if (id instanceof NameRelationship) {
39 TaxonNameBase relatedName;
40 String nameValue;
41 if (((NameRelationship) id).getFromName().equals(name)) {
42 relatedName = ((NameRelationship) id).getToName();
43 nameValue = "to " + relatedName.getTitleCache();
44 } else {
45 relatedName = ((NameRelationship) id).getFromName();
46 nameValue = relatedName.getTitleCache();
47 }
48 return nameValue;
49 }
50 return null;
51 }
52
53 @Override
54 public void setPropertyValue(Object id, Object value) {
55 // Fields not editable in property sheet view
56 }
57
58 @Override
59 public String toString() {
60 // "Name Relations" header has no value
61 return "";
62 }
63 }