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
;
13 import org
.apache
.log4j
.Logger
;
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
;
22 public class NameRelationsPropertySource
extends CollectionPropertySource
{
23 private static final Logger logger
= Logger
24 .getLogger(NameRelationsPropertySource
.class);
26 private TaxonNameBase name
;
27 private boolean isZoological
= false;
29 public NameRelationsPropertySource(TaxonNameBase name
, Collection collection
) {
30 super(collection
, name
);
32 if (name
instanceof ZoologicalName
) {
38 protected String
getItemDisplayName(Object item
) {
39 String itemDisplayName
= "";
41 if (item
instanceof NameRelationship
) {
43 NameRelationship nameRelation
= (NameRelationship
) item
;
45 if (nameRelation
.getFromName() instanceof ZoologicalName
&&
46 nameRelation
.getToName() instanceof ZoologicalName
) {
50 if (nameRelation
.getType() != null) {
52 NameRelationshipType type
= nameRelation
.getType();
55 if (nameRelation
.getFromName().equals(getCollectionOwner())) {
56 label
= GlobalController
.getNameRelationTypeLabel(type
, isZoological
);
58 label
= GlobalController
.getNameRelationInverseTypeLabel(type
, isZoological
);
60 itemDisplayName
= label
;
62 itemDisplayName
= "Relation has no type";
65 return itemDisplayName
;
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();
75 relatedName
= ((NameRelationship
) id
).getFromName();
77 return relatedName
.getTitleCache();
83 public void setPropertyValue(Object id
, Object value
) {
84 // Fields not editable in property sheet view
88 public String
toString() {
89 // "Name Relations" header has no value