import java.util.List;\r
import java.util.Vector;\r
\r
+import org.eclipse.jface.viewers.ICellEditorValidator;\r
import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;\r
import org.eclipse.ui.views.properties.IPropertyDescriptor;\r
import org.eclipse.ui.views.properties.PropertyDescriptor;\r
import eu.etaxonomy.cdm.common.CdmUtils;\r
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;\r
import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;\r
import eu.etaxonomy.cdm.model.name.NonViralName;\r
+import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
import eu.etaxonomy.taxeditor.propertysheet.ICdmBasePropertySource;\r
\r
/**\r
public static final String P_ID_EXAUTHORSHIPCACHE = "P_ID_EXAUTHORSHIPCACHE";\r
public static final String P_ID_BASAUTHORSHIPCACHE = "P_ID_BASAUTHORSHIPCACHE";\r
public static final String P_ID_EXBASAUTHORSHIPCACHE = "P_ID_EXBASAUTHORSHIPCACHE";\r
+ public static final String P_ID_PUBLICATIONYEAR = "P_ID_PUBLICATIONYEAR";\r
+ public static final String P_ID_ORIGINAL_PUBLICATIONYEAR = "P_ID_ORIGINAL_PUBLICATIONYEAR";\r
\r
// Property display keys\r
public static final String P_EDITABLECACHE = "Editable Cache";\r
public static final String P_PROTECT_CACHE = "Protect Cache from overwriting?";\r
public static final String P_AUTHORSHIPCACHE = "Authorship";\r
public static final String P_EXAUTHORSHIPCACHE = "Ex-Authorship";\r
- public static final String P_BASAUTHORSHIPCACHE = "Basionym Authorship";\r
- public static final String P_EXBASAUTHORSHIPCACHE = "Ex-Basionym Authorship";\r
+ public static String P_BASAUTHORSHIPCACHE = "Basionym Authorship";\r
+ public static String P_EXBASAUTHORSHIPCACHE = "Ex-Basionym Authorship";\r
+ public static final String P_PUBLICATIONYEAR = "Publication Year";\r
+ public static final String P_ORIGINAL_PUBLICATIONYEAR = "Original Publication Year"; \r
\r
private static final int CACHE_NOT_PROTECTED = 0;\r
private static final int CACHE_PROTECTED = 1;\r
displayFields.add(P_ID_EDITABLECACHE);\r
displayFields.add(P_ID_PROTECT_CACHE);\r
\r
+ if (NomenclaturalCode.ICZN.equals(name.getNomenclaturalCode())) {\r
+ displayFields.add(P_ID_PUBLICATIONYEAR);\r
+ displayFields.add(P_ID_ORIGINAL_PUBLICATIONYEAR);\r
+ \r
+ P_BASAUTHORSHIPCACHE = "Original Authorship";\r
+ P_EXBASAUTHORSHIPCACHE = "Ex-Original Authorship";\r
+ }\r
+ \r
displayFields.add(P_ID_AUTHORSHIPCACHE);\r
displayFields.add(P_ID_EXAUTHORSHIPCACHE);\r
displayFields.add(P_ID_BASAUTHORSHIPCACHE);\r
} \r
\r
boolean isProtectedCache = name.isProtectedAuthorshipCache();\r
+\r
+ // Publication year\r
+ if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
+ PropertyDescriptor descriptor = (isProtectedCache ?\r
+ new PropertyDescriptor(P_ID_PUBLICATIONYEAR, P_PUBLICATIONYEAR) :\r
+ new TextPropertyDescriptor(P_ID_PUBLICATIONYEAR, P_PUBLICATIONYEAR));\r
+ descriptor.setValidator(new IntegerValidator());\r
+ descriptors.addElement(descriptor);\r
+ }\r
+ \r
+ // Original publication year\r
+ if (id.equals(P_ID_ORIGINAL_PUBLICATIONYEAR)) {\r
+ PropertyDescriptor descriptor = (isProtectedCache ?\r
+ new PropertyDescriptor(P_ID_ORIGINAL_PUBLICATIONYEAR, P_ORIGINAL_PUBLICATIONYEAR) :\r
+ new TextPropertyDescriptor(P_ID_ORIGINAL_PUBLICATIONYEAR, P_ORIGINAL_PUBLICATIONYEAR));\r
+ descriptor.setValidator(new IntegerValidator());\r
+ descriptors.addElement(descriptor);\r
+ }\r
\r
// Authorship cache\r
if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
return name.isProtectedAuthorshipCache() ? CACHE_PROTECTED : CACHE_NOT_PROTECTED;\r
}\r
\r
+ // Publication year\r
+ if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
+ \r
+ if (((ZoologicalName) name).getPublicationYear() == null) {\r
+ return "";\r
+ }\r
+ return Integer.toString(((ZoologicalName) name).getPublicationYear());\r
+ }\r
+\r
+ // Original publication year\r
+ if (id.equals(P_ID_ORIGINAL_PUBLICATIONYEAR)) {\r
+ \r
+ if (((ZoologicalName) name).getOriginalPublicationYear() == null) {\r
+ return "";\r
+ }\r
+ return Integer.toString(((ZoologicalName) name).getOriginalPublicationYear());\r
+ }\r
+ \r
// Authorship cache\r
if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
if (name.getCombinationAuthorTeam() != null) {\r
((Integer) value).intValue() == CACHE_PROTECTED);\r
}\r
\r
+ // Publication year\r
+ if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
+ try {\r
+ ((ZoologicalName) name).setPublicationYear(yearToInteger((String) value));\r
+ } catch (NumberFormatException e) {\r
+ // Do nothing - validator should prevent this\r
+ }\r
+ }\r
+ \r
+ // Original publication year\r
+ if (id.equals(P_ID_ORIGINAL_PUBLICATIONYEAR)) {\r
+ try {\r
+ ((ZoologicalName) name).setOriginalPublicationYear(yearToInteger((String) value));\r
+ } catch (NumberFormatException e) {\r
+ // Do nothing - validator should prevent this\r
+ }\r
+ }\r
+ \r
// Authorship cache\r
if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
if (name.getCombinationAuthorTeam() == null) {\r
team.setNomenclaturalTitle(teamCache);\r
return team;\r
}\r
+ \r
+ private Integer yearToInteger(String year) throws NumberFormatException {\r
+ if (year.length() == 0) {\r
+ return null;\r
+ }\r
+ return Integer.parseInt(year);\r
+ }\r
+ \r
+ class IntegerValidator implements ICellEditorValidator {\r
+\r
+ public String isValid(Object value) {\r
+ String msg = null;\r
+ try {\r
+ yearToInteger((String) value);\r
+ } catch (NumberFormatException e) {\r
+ msg = "Year contains non-integer characters.";\r
+ }\r
+ return msg;\r
+ }\r
+ }\r
}
\ No newline at end of file
\r
package eu.etaxonomy.taxeditor.propertysheet.name;\r
\r
-import org.eclipse.jface.viewers.ICellEditorValidator;\r
-import org.eclipse.ui.views.properties.PropertyDescriptor;\r
-import org.eclipse.ui.views.properties.TextPropertyDescriptor;\r
-\r
import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
\r
/**\r
public class ZoologicalNamePropertySource extends NonViralNamePropertySource {\r
\r
private ZoologicalName zoologicalName;\r
- \r
- // Property unique keys\r
- public static final String P_ID_PUBLICATIONYEAR = "publicationyear";\r
- // Property display keys\r
- public static final String P_PUBLICATIONYEAR = "Publication Year";\r
- \r
- // Where in the list of properties should the year be placed?\r
- public static final int P_PUBLICATIONYEAR_POS = 5;\r
\r
public ZoologicalNamePropertySource(ZoologicalName name) {\r
super(name);\r
this.zoologicalName = name;\r
- addDescriptor(P_ID_PUBLICATIONYEAR);\r
- }\r
-\r
- @Override\r
- protected void addDescriptor(String id) {\r
- \r
- super.addDescriptor(id);\r
- \r
- if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
- PropertyDescriptor descriptor = new TextPropertyDescriptor\r
- (P_ID_PUBLICATIONYEAR, P_PUBLICATIONYEAR);\r
- descriptor.setValidator(new IntegerValidator());\r
- descriptors.add(P_PUBLICATIONYEAR_POS, descriptor);\r
- }\r
- }\r
- \r
- @Override\r
- public Object getPropertyValue(Object id) {\r
- if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
- return "ICZN";\r
- }\r
- if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
- if (zoologicalName.getPublicationYear() == null) {\r
- return "";\r
- }\r
- return Integer.toString(zoologicalName.getPublicationYear());\r
- }\r
- return super.getPropertyValue(id);\r
- }\r
- \r
- public void setPropertyValue(Object id, Object value) {\r
- \r
- if (id.equals(P_ID_PUBLICATIONYEAR)) {\r
- try {\r
- zoologicalName.setPublicationYear(yearToInteger((String) value));\r
- } catch (NumberFormatException e) {\r
- // Do nothing - validator should prevent this\r
- }\r
- }\r
- \r
- super.setPropertyValue(id, value);\r
- }\r
- \r
- private Integer yearToInteger(String year) throws NumberFormatException {\r
- if (year.length() == 0) {\r
- return null;\r
- }\r
- return Integer.parseInt(year);\r
- }\r
- \r
- class IntegerValidator implements ICellEditorValidator {\r
-\r
- public String isValid(Object value) {\r
- String msg = null;\r
- try {\r
- yearToInteger((String) value);\r
- } catch (NumberFormatException e) {\r
- msg = "Year contains non-integer characters.";\r
- }\r
- return msg;\r
- }\r
}\r
}
\ No newline at end of file