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
.apache
.log4j
.Logger
;
18 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
19 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
20 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
21 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
22 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
34 public class NomenclaturalAuthorshipPropertySource
implements IPropertySource
{
35 private static final Logger logger
= Logger
36 .getLogger(NomenclaturalAuthorshipPropertySource
.class);
38 // Property unique keys
39 public static final String P_ID_EDITABLECACHE
= "P_ID_EDITABLECACHE";
40 public static final String P_ID_PROTECT_CACHE
= "P_ID_PROTECT_CACHE";
41 public static final String P_ID_AUTHORSHIPCACHE
= "P_ID_AUTHORSHIPCACHE";
42 public static final String P_ID_EXAUTHORSHIPCACHE
= "P_ID_EXAUTHORSHIPCACHE";
43 public static final String P_ID_BASAUTHORSHIPCACHE
= "P_ID_BASAUTHORSHIPCACHE";
44 public static final String P_ID_EXBASAUTHORSHIPCACHE
= "P_ID_EXBASAUTHORSHIPCACHE";
46 // Property display keys
47 public static final String P_EDITABLECACHE
= "Editable Cache";
48 public static final String P_PROTECT_CACHE
= "Protect Cache from overwriting?";
49 public static final String P_AUTHORSHIPCACHE
= "Authorship";
50 public static final String P_EXAUTHORSHIPCACHE
= "Ex-Authorship";
51 public static final String P_BASAUTHORSHIPCACHE
= "Basionym Authorship";
52 public static final String P_EXBASAUTHORSHIPCACHE
= "Ex-Basionym Authorship";
54 private static final int CACHE_NOT_PROTECTED
= 0;
55 private static final int CACHE_PROTECTED
= 1;
57 private NonViralName name
;
59 public NomenclaturalAuthorshipPropertySource(NonViralName name
) {
65 protected void initDescriptors() {
67 List
<String
> displayFields
= new ArrayList
<String
>();
70 displayFields
.add(P_ID_EDITABLECACHE
);
71 displayFields
.add(P_ID_PROTECT_CACHE
);
73 displayFields
.add(P_ID_AUTHORSHIPCACHE
);
74 displayFields
.add(P_ID_EXAUTHORSHIPCACHE
);
75 displayFields
.add(P_ID_BASAUTHORSHIPCACHE
);
76 displayFields
.add(P_ID_EXBASAUTHORSHIPCACHE
);
79 for (String field
: displayFields
) {
84 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
86 protected void addDescriptor(String id
) {
89 if (id
.equals(P_ID_EDITABLECACHE
)) {
90 descriptors
.addElement(
91 new TextPropertyDescriptor(P_ID_EDITABLECACHE
, P_EDITABLECACHE
));
95 if (id
.equals(P_ID_PROTECT_CACHE
)) {
96 descriptors
.addElement(
97 new ComboBoxPropertyDescriptor(P_ID_PROTECT_CACHE
, P_PROTECT_CACHE
,
98 new String
[] {"no", "yes"}));
101 boolean isProtectedCache
= name
.isProtectedAuthorshipCache();
104 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
105 descriptors
.addElement(
107 new PropertyDescriptor(P_ID_AUTHORSHIPCACHE
, P_AUTHORSHIPCACHE
) :
108 new TextPropertyDescriptor(P_ID_AUTHORSHIPCACHE
, P_AUTHORSHIPCACHE
));
111 // Ex-Authorship cache
112 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
113 descriptors
.addElement(
115 new PropertyDescriptor(P_ID_EXAUTHORSHIPCACHE
, P_EXAUTHORSHIPCACHE
) :
116 new TextPropertyDescriptor(P_ID_EXAUTHORSHIPCACHE
, P_EXAUTHORSHIPCACHE
));
119 // Basionym Authorship cache
120 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
121 descriptors
.addElement(
123 new PropertyDescriptor(P_ID_BASAUTHORSHIPCACHE
, P_BASAUTHORSHIPCACHE
) :
124 new TextPropertyDescriptor(P_ID_BASAUTHORSHIPCACHE
, P_BASAUTHORSHIPCACHE
));
127 // Ex-Basionym Authorship cache
128 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
129 descriptors
.addElement(
131 new PropertyDescriptor(P_ID_EXBASAUTHORSHIPCACHE
, P_EXBASAUTHORSHIPCACHE
) :
132 new TextPropertyDescriptor(P_ID_EXBASAUTHORSHIPCACHE
, P_EXBASAUTHORSHIPCACHE
));
137 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
139 public Object
getEditableValue() {
140 return CdmUtils
.Nz(name
.getAuthorshipCache());
144 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
146 public IPropertyDescriptor
[] getPropertyDescriptors() {
147 return (IPropertyDescriptor
[]) descriptors
.toArray(
148 new IPropertyDescriptor
[descriptors
.size()]);
152 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
154 public Object
getPropertyValue(Object id
) {
157 if (id
.equals(P_ID_EDITABLECACHE
)) {
158 return CdmUtils
.Nz(name
.getAuthorshipCache());
162 if (id
.equals(P_ID_PROTECT_CACHE
)) {
163 return name
.isProtectedAuthorshipCache() ? CACHE_PROTECTED
: CACHE_NOT_PROTECTED
;
167 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
168 if (name
.getCombinationAuthorTeam() != null) {
169 return CdmUtils
.Nz(name
.getCombinationAuthorTeam().getNomenclaturalTitle());
175 // Ex-Authorship cache
176 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
177 if (name
.getExCombinationAuthorTeam() != null) {
178 return CdmUtils
.Nz(name
.getExCombinationAuthorTeam().getNomenclaturalTitle());
184 // Basionym Authorship cache
185 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
186 if (name
.getBasionymAuthorTeam() != null) {
187 return CdmUtils
.Nz(name
.getBasionymAuthorTeam().getNomenclaturalTitle());
193 // Ex-Basionym Authorship cache
194 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
195 if (name
.getExBasionymAuthorTeam() != null) {
196 return CdmUtils
.Nz(name
.getExBasionymAuthorTeam().getNomenclaturalTitle());
206 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
208 public boolean isPropertySet(Object id
) {
213 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
215 public void resetPropertyValue(Object id
) {}
218 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
220 public void setPropertyValue(Object id
, Object value
) {
223 if (id
.equals(P_ID_EDITABLECACHE
)) {
224 name
.setAuthorshipCache((String
) value
);
225 name
.generateAuthorship();
229 if (id
.equals(P_ID_PROTECT_CACHE
)) {
230 name
.setProtectedAuthorshipCache(
231 ((Integer
) value
).intValue() == CACHE_PROTECTED
);
235 if (id
.equals(P_ID_AUTHORSHIPCACHE
)) {
236 if (name
.getCombinationAuthorTeam() == null) {
237 name
.setCombinationAuthorTeam(createNewTeam((String
) value
));
239 name
.getCombinationAuthorTeam().setNomenclaturalTitle((String
) value
);
243 // Ex-Authorship cache
244 if (id
.equals(P_ID_EXAUTHORSHIPCACHE
)) {
245 if (name
.getExCombinationAuthorTeam() == null) {
246 name
.setExCombinationAuthorTeam(createNewTeam((String
) value
));
248 name
.getExCombinationAuthorTeam().setNomenclaturalTitle((String
) value
);
252 // Basionym Authorship cache
253 if (id
.equals(P_ID_BASAUTHORSHIPCACHE
)) {
254 if (name
.getBasionymAuthorTeam() == null) {
255 name
.setBasionymAuthorTeam(createNewTeam((String
) value
));
257 name
.getBasionymAuthorTeam().setNomenclaturalTitle((String
) value
);
261 // Ex-Basionym Authorship cache
262 if (id
.equals(P_ID_EXBASAUTHORSHIPCACHE
)) {
263 if (name
.getExBasionymAuthorTeam() == null) {
264 name
.setExBasionymAuthorTeam(createNewTeam((String
) value
));
266 name
.getExBasionymAuthorTeam().setNomenclaturalTitle((String
) value
);
275 private INomenclaturalAuthor
createNewTeam(String teamCache
) {
276 Team team
= Team
.NewInstance();
277 team
.setNomenclaturalTitle(teamCache
);