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
.type
;
11 import java
.beans
.PropertyChangeEvent
;
12 import java
.beans
.PropertyChangeListener
;
13 import java
.util
.Collection
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
17 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
18 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
22 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
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
.CollectionPropertySource
;
28 import eu
.etaxonomy
.taxeditor
.propertysheet
.reference
.ReferencePropertySource
;
30 public class TypeCollectionPropertySource
extends CollectionPropertySource
{
31 private static final Logger logger
= Logger
32 .getLogger(TypeCollectionPropertySource
.class);
34 private TaxonNameBase name
;
36 public TypeCollectionPropertySource(TaxonNameBase name
, Collection collection
) {
41 protected void addDescriptor(Object item
) {
42 String itemDisplayName
= getItemDisplayName(item
);
44 if (item
instanceof NameTypeDesignation
) {
45 descriptors
.addElement(
46 new PropertyDescriptor(item
, itemDisplayName
));
49 /* Two issues here, caused by making a ProperySheet field editable while at the same
50 * time returning an IPropertySource with which its child fields are built.
52 * First, TextPropertyDescriptor expects its value to be set w/ a String and
53 * throws an Assert exception when this is not the case, i.e. when it is passed an
54 * IPropertySource; hence, the override of doSetValue().
56 * Second, the super implementation of doGetValue() was causing the equality test in
57 * PropertySheetEntry:140 to return false: it was comparing the IPropertySource with
58 * the CellEditor's text String, thereby triggering an infinite loop where the cell's
59 * previous state would never equals the cell's current state. Hence, the
60 * IPropertySource is now saved in the field editorValue for comparison.
62 descriptors
.addElement(
63 new TextPropertyDescriptor(item
, itemDisplayName
));
64 // new TextPropertyDescriptor(item, itemDisplayName) {
65 // public CellEditor createPropertyEditor(Composite parent) {
66 // CellEditor editor = new TextCellEditor(parent) {
67 // Object editorValue;
68 // protected void doSetValue(Object value) {
69 // if (value instanceof String) {
70 // super.doSetValue(value);
72 // editorValue = value;
73 // super.doSetValue(value.toString());
76 //// protected Object doGetValue() {
77 //// return super.doGetValue();
80 // if (getValidator() != null) {
81 // editor.setValidator(getValidator());
90 protected String
getItemDisplayName(Object item
) {
93 if (item
instanceof SpecimenTypeDesignation
) {
95 SpecimenTypeDesignation typeDesignation
= (SpecimenTypeDesignation
) item
;
97 if (typeDesignation
.getTypeStatus() != null) {
98 str
= typeDesignation
.getTypeStatus().getLabel();
104 if (item
instanceof NameTypeDesignation
) {
106 NameTypeDesignation typeDesignation
= (NameTypeDesignation
) item
;
108 if (typeDesignation
.isLectoType()) {
119 public Object
getPropertyValue(Object id
) {
121 if (id
instanceof TypeDesignationBase
) {
122 return new TypeDesignationPropertySource((TypeDesignationBase
) id
);
128 public void setPropertyValue(Object id
, Object value
) {
130 if (id
instanceof SpecimenTypeDesignation
&& value
instanceof String
) {
131 SpecimenTypeDesignation typeDesignation
= (SpecimenTypeDesignation
) id
;
133 if (typeDesignation
.getTypeSpecimen() != null) {
134 typeDesignation
.getTypeSpecimen().setTitleCache((String
) value
);
136 logger
.warn("'typeDesignation.getTypeSpecimen()' returned null.");
142 * @see eu.etaxonomy.taxeditor.propertysheet.CollectionPropertySource#toString()
145 public String
toString() {
149 class TypeDesignationPropertySource
implements IPropertySource
{
151 private TypeDesignationBase typeDesignation
;
153 TypeDesignationPropertySource(TypeDesignationBase typeDesignation
) {
154 this.typeDesignation
= typeDesignation
;
158 public Object
getEditableValue() {
159 if (typeDesignation
instanceof SpecimenTypeDesignation
) {
160 return ((SpecimenTypeDesignation
) typeDesignation
).getTypeSpecimen().getTitleCache();
163 if (typeDesignation
instanceof NameTypeDesignation
) {
164 if (((NameTypeDesignation
) typeDesignation
).getTypeName() != null) {
165 return ((NameTypeDesignation
) typeDesignation
).getTypeName().getTitleCache();
173 public IPropertyDescriptor
[] getPropertyDescriptors() {
174 return new IPropertyDescriptor
[]{
175 new PropertyDescriptor(
176 typeDesignation
, "Citation")
181 public Object
getPropertyValue(Object id
) {
182 ReferenceBase reference
= typeDesignation
.getCitation();
183 if (reference
== null) {
184 reference
= Generic
.NewInstance();
186 ReferencePropertySource referencePropertySource
= new ReferencePropertySource(reference
);
187 referencePropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
188 public void propertyChange(PropertyChangeEvent evt
) {
189 if (evt
.getNewValue() instanceof ReferenceBase
) {
190 typeDesignation
.setCitation((ReferenceBase
) evt
.getNewValue());
194 return referencePropertySource
;
198 public boolean isPropertySet(Object id
) {
203 public void resetPropertyValue(Object id
) {}
206 public void setPropertyValue(Object id
, Object value
) {
209 // public String toString() {
210 // if (typeDesignation instanceof SpecimenTypeDesignation) {
211 // return ((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen().getTitleCache();
214 // if (typeDesignation instanceof NameTypeDesignation) {
215 // if (((NameTypeDesignation) typeDesignation).getTypeName() != null) {
216 // return ((NameTypeDesignation) typeDesignation).getTypeName().getTitleCache();
223 public boolean equals(Object object
) {
224 if (object
== null) {
227 if (toString() == null) {
230 if (toString().equals(object
.toString())) {