3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.propertysheet
.type
;
13 import java
.beans
.PropertyChangeEvent
;
14 import java
.beans
.PropertyChangeListener
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
18 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
21 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
23 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
27 import eu
.etaxonomy
.taxeditor
.propertysheet
.ICdmBasePropertySource
;
28 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
35 public class TypeDesignationPropertySource
implements ICdmBasePropertySource
{
37 private TypeDesignationBase
<?
> typeDesignation
;
40 * Property unique keys
42 public static final String P_ID_CITATION
= "citation";
43 public static final String P_ID_MICROREF
= "microref";
46 * Property display keys
48 public static final String P_CITATION
= "Citation";
49 public static final String P_MICROREF
= "Microcitation";
51 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
53 TypeDesignationPropertySource(TypeDesignationBase
<?
> typeDesignation
) {
54 this.typeDesignation
= typeDesignation
;
56 addDescriptor(P_ID_CITATION
);
57 addDescriptor(P_ID_MICROREF
);
60 public Object
getEditableValue() {
61 if (typeDesignation
instanceof SpecimenTypeDesignation
) {
62 return ((SpecimenTypeDesignation
) typeDesignation
).getTypeSpecimen().getTitleCache();
65 if (typeDesignation
instanceof NameTypeDesignation
) {
66 if (((NameTypeDesignation
) typeDesignation
).getTypeName() != null) {
67 return ((NameTypeDesignation
) typeDesignation
).getTypeName().getTitleCache();
73 private void addDescriptor(String id
) {
74 // Name relations, listed in custom property descriptor
75 if (id
.equals(P_ID_CITATION
)) {
76 descriptors
.addElement(
77 new PropertyDescriptor(P_ID_CITATION
, P_CITATION
));
79 if (id
.equals(P_ID_MICROREF
)) {
80 descriptors
.addElement(
81 new TextPropertyDescriptor(P_ID_MICROREF
, P_MICROREF
));
85 public IPropertyDescriptor
[] getPropertyDescriptors() {
86 return (IPropertyDescriptor
[]) descriptors
.toArray(
87 new IPropertyDescriptor
[descriptors
.size()]);
90 public Object
getPropertyValue(Object id
) {
92 if (id
.equals(P_ID_CITATION
)) {
94 ReferenceBase
<?
> reference
= typeDesignation
.getCitation();
95 if (reference
== null) {
96 reference
= Generic
.NewInstance();
98 ReferencePropertySource referencePropertySource
= new ReferencePropertySource(reference
);
99 referencePropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
100 public void propertyChange(PropertyChangeEvent evt
) {
101 if (evt
.getNewValue() instanceof ReferenceBase
) {
102 typeDesignation
.setCitation((ReferenceBase
<?
>) evt
.getNewValue());
106 return referencePropertySource
;
109 if (id
.equals(P_ID_MICROREF
)) {
110 return CdmUtils
.Nz(typeDesignation
.getCitationMicroReference());
116 public boolean isPropertySet(Object id
) {
120 public void resetPropertyValue(Object id
) {}
122 public void setPropertyValue(Object id
, Object value
) {
123 if (id
.equals(P_ID_MICROREF
)) {
124 typeDesignation
.setCitationMicroReference((String
) value
);
128 public boolean equals(Object object
) {
129 if (object
== null) {
132 if (toString() == null) {
135 if (toString().equals(object
.toString())) {