2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.propertysheet
.name
;
11 import java
.util
.Collection
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
19 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
20 import eu
.etaxonomy
.taxeditor
.propertysheet
.CollectionPropertySource
;
21 import eu
.etaxonomy
.taxeditor
.store
.model
.NameRelationsUtil
;
23 public class NameRelationsPropertySource
extends CollectionPropertySource
{
24 private static final Logger logger
= Logger
25 .getLogger(NameRelationsPropertySource
.class);
27 private TaxonNameBase name
;
28 private boolean isZoological
= false;
30 private Set nameRelations
;
32 public NameRelationsPropertySource(TaxonNameBase name
, Collection collection
) {
33 super(collection
, name
);
35 if (name
instanceof ZoologicalName
) {
39 this.nameRelations
= name
.getNameRelations();
43 protected String
getItemDisplayName(Object item
) {
44 String itemDisplayName
= "";
46 if (item
instanceof NameRelationship
) {
48 NameRelationship nameRelation
= (NameRelationship
) item
;
50 if (nameRelation
.getFromName() instanceof ZoologicalName
&&
51 nameRelation
.getToName() instanceof ZoologicalName
) {
55 if (nameRelation
.getType() != null) {
56 NameRelationshipType type
= nameRelation
.getType();
58 if (nameRelation
.getFromName().equals(getCollectionOwner())) {
59 label
= NameRelationsUtil
.getNameRelationTypeLabel(type
, isZoological
);
61 label
= NameRelationsUtil
.getNameRelationInverseTypeLabel(type
, isZoological
);
63 itemDisplayName
= label
;
65 itemDisplayName
= "Relation has no type";
68 return itemDisplayName
;
72 public Object
getPropertyValue(Object id
) {
73 if (id
instanceof NameRelationship
) {
74 TaxonNameBase relatedName
;
75 if (((NameRelationship
) id
).getFromName().equals(name
)) {
76 relatedName
= ((NameRelationship
) id
).getToName();
78 relatedName
= ((NameRelationship
) id
).getFromName();
80 return relatedName
.getTitleCache();
86 public void setPropertyValue(Object id
, Object value
) {
87 // Fields not editable in property sheet view
91 public String
toString() {
92 // "Name Relations" header has no value