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 eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
16 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
17 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
18 import eu
.etaxonomy
.taxeditor
.propertysheet
.CollectionPropertySource
;
19 import eu
.etaxonomy
.taxeditor
.store
.model
.NameRelationsUtil
;
21 public class NameRelationsPropertySource
extends CollectionPropertySource
{
23 private TaxonNameBase
<?
, ?
> name
;
24 private boolean isZoological
= false;
26 private Set
<?
> nameRelations
;
28 public NameRelationsPropertySource(TaxonNameBase
<?
, ?
> name
, Collection
<?
> collection
) {
29 super(collection
, name
);
31 if (name
instanceof ZoologicalName
) {
35 this.setNameRelations(name
.getNameRelations());
39 protected String
getItemDisplayName(Object item
) {
40 String itemDisplayName
= "";
42 if (item
instanceof NameRelationship
) {
44 NameRelationship nameRelation
= (NameRelationship
) item
;
46 if (nameRelation
.getFromName() instanceof ZoologicalName
&&
47 nameRelation
.getToName() instanceof ZoologicalName
) {
51 if (nameRelation
.getType() != null) {
52 NameRelationshipType type
= nameRelation
.getType();
54 if (nameRelation
.getFromName().equals(getCollectionOwner())) {
55 label
= NameRelationsUtil
.getNameRelationTypeLabel(type
, isZoological
);
57 label
= NameRelationsUtil
.getNameRelationInverseTypeLabel(type
, isZoological
);
59 itemDisplayName
= label
;
61 itemDisplayName
= "Relation has no type";
64 return itemDisplayName
;
68 public Object
getPropertyValue(Object id
) {
69 if (id
instanceof NameRelationship
) {
70 TaxonNameBase
<?
, ?
> relatedName
;
71 if (((NameRelationship
) id
).getFromName().equals(name
)) {
72 relatedName
= ((NameRelationship
) id
).getToName();
74 relatedName
= ((NameRelationship
) id
).getFromName();
76 return relatedName
.getTitleCache();
82 public void setPropertyValue(Object id
, Object value
) {
83 // Fields not editable in property sheet view
87 public String
toString() {
88 // "Name Relations" header has no value
93 * @param nameRelations the nameRelations to set
95 public void setNameRelations(Set
<?
> nameRelations
) {
96 this.nameRelations
= nameRelations
;
100 * @return the nameRelations
102 public Set
<?
> getNameRelations() {
103 return nameRelations
;