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
.name
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
15 import java
.util
.Vector
;
17 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
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
;
23 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
24 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
26 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
33 public class NomenclaturalAuthorshipPropertySource
implements IPropertySource
{
35 // Property unique keys
36 public static final String P_ID_EDITABLECACHE
= "P_ID_EDITABLECACHE";
37 public static final String P_ID_PROTECT_CACHE
= "P_ID_PROTECT_CACHE";
38 public static final String P_ID_AUTHORSHIPCACHE
= "P_ID_AUTHORSHIPCACHE";
39 public static final String P_ID_EXAUTHORSHIPCACHE
= "P_ID_EXAUTHORSHIPCACHE";
40 public static final String P_ID_BASAUTHORSHIPCACHE
= "P_ID_BASAUTHORSHIPCACHE";
41 public static final String P_ID_EXBASAUTHORSHIPCACHE
= "P_ID_EXBASAUTHORSHIPCACHE";
43 // Property display keys
44 public static final String P_EDITABLECACHE
= "Editable Cache";
45 public static final String P_PROTECT_CACHE
= "Protect Cache from overwriting?";
46 public static final String P_AUTHORSHIPCACHE
= "Authorship";
47 public static final String P_EXAUTHORSHIPCACHE
= "Ex-Authorship";
48 public static final String P_BASAUTHORSHIPCACHE
= "Basionym Authorship";
49 public static final String P_EXBASAUTHORSHIPCACHE
= "Ex-Basionym Authorship";
51 private static final int CACHE_NOT_PROTECTED
= 0;
52 private static final int CACHE_PROTECTED
= 1;
54 private NonViralName name
;
56 public NomenclaturalAuthorshipPropertySource(NonViralName name
) {
62 protected void initDescriptors() {
64 List
<String
> displayFields
= new ArrayList
<String
>();
67 displayFields
.add(P_ID_EDITABLECACHE
);
68 displayFields
.add(P_ID_PROTECT_CACHE
);
70 displayFields
.add(P_ID_AUTHORSHIPCACHE
);
71 displayFields
.add(P_ID_EXAUTHORSHIPCACHE
);
72 displayFields
.add(P_ID_BASAUTHORSHIPCACHE
);
73 displayFields
.add(P_ID_EXBASAUTHORSHIPCACHE
);
76 for (String field
: displayFields
) {
81 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
83 protected void addDescriptor(String id
) {
86 if (id
.equals(P_ID_EDITABLECACHE
)) {
87 descriptors
.addElement(
88 new TextPropertyDescriptor(P_ID_EDITABLECACHE
, P_EDITABLECACHE
));
92 if (id
.equals(P_ID_PROTECT_CACHE
)) {
93 descriptors
.addElement(
94 new ComboBoxPropertyDescriptor(P_ID_PROTECT_CACHE
, P_PROTECT_CACHE
,
95 new String
[] {"no", "yes"}));
98 boolean isProtectedCache
= name
.isProtectedAuthorshipCache();
101 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
102 descriptors
.addElement(
104 new PropertyDescriptor(P_ID_AUTHORSHIPCACHE
, P_AUTHORSHIPCACHE
) :
105 new TextPropertyDescriptor(P_ID_AUTHORSHIPCACHE
, P_AUTHORSHIPCACHE
));
108 // Ex-Authorship cache
109 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
110 descriptors
.addElement(
112 new PropertyDescriptor(P_ID_EXAUTHORSHIPCACHE
, P_EXAUTHORSHIPCACHE
) :
113 new TextPropertyDescriptor(P_ID_EXAUTHORSHIPCACHE
, P_EXAUTHORSHIPCACHE
));
116 // Basionym Authorship cache
117 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
118 descriptors
.addElement(
120 new PropertyDescriptor(P_ID_BASAUTHORSHIPCACHE
, P_BASAUTHORSHIPCACHE
) :
121 new TextPropertyDescriptor(P_ID_BASAUTHORSHIPCACHE
, P_BASAUTHORSHIPCACHE
));
124 // Ex-Basionym Authorship cache
125 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
126 descriptors
.addElement(
128 new PropertyDescriptor(P_ID_EXBASAUTHORSHIPCACHE
, P_EXBASAUTHORSHIPCACHE
) :
129 new TextPropertyDescriptor(P_ID_EXBASAUTHORSHIPCACHE
, P_EXBASAUTHORSHIPCACHE
));
134 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
136 public Object
getEditableValue() {
137 return CdmUtils
.Nz(name
.getAuthorshipCache());
141 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
143 public IPropertyDescriptor
[] getPropertyDescriptors() {
144 return (IPropertyDescriptor
[]) descriptors
.toArray(
145 new IPropertyDescriptor
[descriptors
.size()]);
149 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
151 public Object
getPropertyValue(Object id
) {
154 if (id
.equals(P_ID_EDITABLECACHE
)) {
155 return CdmUtils
.Nz(name
.getAuthorshipCache());
159 if (id
.equals(P_ID_PROTECT_CACHE
)) {
160 return name
.isProtectedAuthorshipCache() ? CACHE_PROTECTED
: CACHE_NOT_PROTECTED
;
164 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
165 if (name
.getCombinationAuthorTeam() != null) {
166 return CdmUtils
.Nz(name
.getCombinationAuthorTeam().getNomenclaturalTitle());
172 // Ex-Authorship cache
173 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
174 if (name
.getExCombinationAuthorTeam() != null) {
175 return CdmUtils
.Nz(name
.getExCombinationAuthorTeam().getNomenclaturalTitle());
181 // Basionym Authorship cache
182 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
183 if (name
.getBasionymAuthorTeam() != null) {
184 return CdmUtils
.Nz(name
.getBasionymAuthorTeam().getNomenclaturalTitle());
190 // Ex-Basionym Authorship cache
191 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
192 if (name
.getExBasionymAuthorTeam() != null) {
193 return CdmUtils
.Nz(name
.getExBasionymAuthorTeam().getNomenclaturalTitle());
203 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
205 public boolean isPropertySet(Object id
) {
210 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
212 public void resetPropertyValue(Object id
) {}
215 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
217 public void setPropertyValue(Object id
, Object value
) {
220 if (id
.equals(P_ID_EDITABLECACHE
)) {
221 name
.setAuthorshipCache((String
) value
);
222 name
.generateAuthorship();
226 if (id
.equals(P_ID_PROTECT_CACHE
)) {
227 name
.setProtectedAuthorshipCache(
228 ((Integer
) value
).intValue() == CACHE_PROTECTED
);
232 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
233 if (name
.getCombinationAuthorTeam() == null) {
234 name
.setCombinationAuthorTeam(createNewTeam((String
) value
));
236 name
.getCombinationAuthorTeam().setNomenclaturalTitle((String
) value
);
240 // Ex-Authorship cache
241 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
242 if (name
.getExCombinationAuthorTeam() == null) {
243 name
.setExCombinationAuthorTeam(createNewTeam((String
) value
));
245 name
.getExCombinationAuthorTeam().setNomenclaturalTitle((String
) value
);
249 // Basionym Authorship cache
250 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
251 if (name
.getBasionymAuthorTeam() == null) {
252 name
.setBasionymAuthorTeam(createNewTeam((String
) value
));
254 name
.getBasionymAuthorTeam().setNomenclaturalTitle((String
) value
);
258 // Ex-Basionym Authorship cache
259 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
260 if (name
.getExBasionymAuthorTeam() == null) {
261 name
.setExBasionymAuthorTeam(createNewTeam((String
) value
));
263 name
.getExBasionymAuthorTeam().setNomenclaturalTitle((String
) value
);
272 private INomenclaturalAuthor
createNewTeam(String teamCache
) {
273 Team team
= Team
.NewInstance();
274 team
.setNomenclaturalTitle(teamCache
);