1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.propertysheet.type;
|
12
|
|
13
|
import java.beans.PropertyChangeEvent;
|
14
|
import java.beans.PropertyChangeListener;
|
15
|
import java.util.Vector;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.eclipse.ui.views.properties.IPropertyDescriptor;
|
19
|
import org.eclipse.ui.views.properties.IPropertySource;
|
20
|
import org.eclipse.ui.views.properties.PropertyDescriptor;
|
21
|
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
|
22
|
|
23
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
24
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
25
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
26
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
27
|
import eu.etaxonomy.cdm.model.reference.Generic;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
29
|
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;
|
30
|
|
31
|
/**
|
32
|
* @author p.ciardelli
|
33
|
* @created 28.04.2009
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class TypeDesignationPropertySource implements IPropertySource {
|
37
|
private static final Logger logger = Logger
|
38
|
.getLogger(TypeDesignationPropertySource.class);
|
39
|
|
40
|
private TypeDesignationBase typeDesignation;
|
41
|
|
42
|
/**
|
43
|
* Property unique keys
|
44
|
*/
|
45
|
public static final String P_ID_CITATION = "citation";
|
46
|
public static final String P_ID_MICROREF = "microref";
|
47
|
|
48
|
/**
|
49
|
* Property display keys
|
50
|
*/
|
51
|
public static final String P_CITATION = "Citation";
|
52
|
public static final String P_MICROREF = "Microcitation";
|
53
|
|
54
|
protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
|
55
|
|
56
|
TypeDesignationPropertySource(TypeDesignationBase typeDesignation) {
|
57
|
this.typeDesignation = typeDesignation;
|
58
|
|
59
|
addDescriptor(P_ID_CITATION);
|
60
|
addDescriptor(P_ID_MICROREF);
|
61
|
}
|
62
|
|
63
|
public Object getEditableValue() {
|
64
|
if (typeDesignation instanceof SpecimenTypeDesignation) {
|
65
|
return ((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen().getTitleCache();
|
66
|
}
|
67
|
|
68
|
if (typeDesignation instanceof NameTypeDesignation) {
|
69
|
if (((NameTypeDesignation) typeDesignation).getTypeName() != null) {
|
70
|
return ((NameTypeDesignation) typeDesignation).getTypeName().getTitleCache();
|
71
|
}
|
72
|
}
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
private void addDescriptor(String id) {
|
77
|
// Name relations, listed in custom property descriptor
|
78
|
if (id.equals(P_ID_CITATION)) {
|
79
|
descriptors.addElement(
|
80
|
new PropertyDescriptor(P_ID_CITATION, P_CITATION));
|
81
|
}
|
82
|
if (id.equals(P_ID_MICROREF)) {
|
83
|
descriptors.addElement(
|
84
|
new TextPropertyDescriptor(P_ID_MICROREF, P_MICROREF));
|
85
|
}
|
86
|
}
|
87
|
|
88
|
public IPropertyDescriptor[] getPropertyDescriptors() {
|
89
|
return (IPropertyDescriptor[]) descriptors.toArray(
|
90
|
new IPropertyDescriptor[descriptors.size()]);
|
91
|
}
|
92
|
|
93
|
public Object getPropertyValue(Object id) {
|
94
|
|
95
|
if (id.equals(P_ID_CITATION)) {
|
96
|
|
97
|
ReferenceBase reference = typeDesignation.getCitation();
|
98
|
if (reference == null) {
|
99
|
reference = Generic.NewInstance();
|
100
|
}
|
101
|
ReferencePropertySource referencePropertySource = new ReferencePropertySource(reference);
|
102
|
referencePropertySource.addPropertyChangeListener(new PropertyChangeListener() {
|
103
|
public void propertyChange(PropertyChangeEvent evt) {
|
104
|
if (evt.getNewValue() instanceof ReferenceBase) {
|
105
|
typeDesignation.setCitation((ReferenceBase) evt.getNewValue());
|
106
|
}
|
107
|
}
|
108
|
});
|
109
|
return referencePropertySource;
|
110
|
}
|
111
|
|
112
|
if (id.equals(P_ID_MICROREF)) {
|
113
|
return CdmUtils.Nz(typeDesignation.getCitationMicroReference());
|
114
|
}
|
115
|
|
116
|
return null;
|
117
|
}
|
118
|
|
119
|
public boolean isPropertySet(Object id) {
|
120
|
return false;
|
121
|
}
|
122
|
|
123
|
public void resetPropertyValue(Object id) {}
|
124
|
|
125
|
public void setPropertyValue(Object id, Object value) {
|
126
|
if (id.equals(P_ID_MICROREF)) {
|
127
|
typeDesignation.setCitationMicroReference((String) value);
|
128
|
}
|
129
|
}
|
130
|
|
131
|
public boolean equals(Object object) {
|
132
|
if (object == null) {
|
133
|
return false;
|
134
|
}
|
135
|
if (toString() == null) {
|
136
|
return false;
|
137
|
}
|
138
|
if (toString().equals(object.toString())) {
|
139
|
return true;
|
140
|
} else {
|
141
|
return false;
|
142
|
}
|
143
|
}
|
144
|
}
|