Fixed #1031 - Authorship year in zoological names not handled correctly.
authorp.ciardelli <p.ciardelli@localhost>
Thu, 17 Sep 2009 11:54:55 +0000 (11:54 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Thu, 17 Sep 2009 11:54:55 +0000 (11:54 +0000)
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/BotanicalNamePropertySource.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/NameRelationsPropertySource.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/NomenclaturalAuthorshipPropertySource.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/ZoologicalNamePropertySource.java

index 819f1ae4de973bf330b9623416966647ec4665fd..d0c0a7097f0790898281431395000fc7c0e1adef 100644 (file)
@@ -26,7 +26,6 @@ public class BotanicalNamePropertySource extends NonViralNamePropertySource {
     // Property unique keys\r
        public static final String P_ID_REFERENCEYEAR = "referenceyear";        \r
     // Property display keys\r
-//     public static final String P_REFERENCEYEAR = "099:Reference Year";\r
        public static final String P_REFERENCEYEAR = "Reference Year";\r
                \r
        public BotanicalNamePropertySource(BotanicalName name) {\r
@@ -44,9 +43,6 @@ public class BotanicalNamePropertySource extends NonViralNamePropertySource {
        \r
        @Override\r
        public Object getPropertyValue(Object id) {\r
-        if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
-               return "ICBN";\r
-        }\r
         if (id.equals(P_ID_REFERENCEYEAR)) {\r
                return CdmUtils.Nz(name.getReferenceYear());\r
         }\r
index 52753e7b0bbba09c810844f35cfd3d157a396bd8..71973b82242b32d7632a34c3bff6ea93dbae0848 100644 (file)
@@ -8,15 +8,13 @@
  */\r
 package eu.etaxonomy.taxeditor.propertysheet.name;\r
 \r
-import java.util.Collection;\r
 import java.util.Set;\r
 \r
 import eu.etaxonomy.cdm.model.name.NameRelationship;\r
 import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
-import eu.etaxonomy.taxeditor.editor.labels.ILabelImageStrategy;\r
-import eu.etaxonomy.taxeditor.editor.labels.LabelImageProvider;\r
+import eu.etaxonomy.taxeditor.labels.ILabelImageStrategy;\r
+import eu.etaxonomy.taxeditor.labels.LabelImageProvider;\r
 import eu.etaxonomy.taxeditor.propertysheet.CollectionPropertySource;\r
 \r
 public class NameRelationsPropertySource extends CollectionPropertySource {\r
index 3827c9a3be941f410d8015dab37a5ced35f0fa3f..beb5a3a84b0cc0f1aa4a95700e31dbbf8806ebed 100644 (file)
@@ -14,6 +14,7 @@ import java.util.ArrayList;
 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
@@ -22,7 +23,9 @@ import org.eclipse.ui.views.properties.TextPropertyDescriptor;
 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
@@ -39,14 +42,18 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
        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
@@ -67,6 +74,14 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
                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
@@ -96,6 +111,24 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
                }               \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
@@ -160,6 +193,24 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
                        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
@@ -228,6 +279,24 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
                                        ((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
@@ -274,4 +343,24 @@ public class NomenclaturalAuthorshipPropertySource implements ICdmBasePropertySo
                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
index 273d9d5e64f683a3fd543df2560501edf9d6a073..4d1c97d1b0203ac756acbc08c9cc21229a17f9fe 100644 (file)
@@ -447,8 +447,9 @@ public class NonViralNamePropertySource implements ICdmBasePropertySource {
         \r
                // Nomenclatural code used by parser        \r
         if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
+               return name.getNomenclaturalCode().name();\r
                // Only shown if extending classes don't handle P_ID_NOMENCLATURAL_CODE \r
-               return "none (nonviral name)";\r
+//             return "none (nonviral name)";\r
         }\r
         \r
                // Nomenclatural reference        \r
index 95a7a250450b9ef37327975c59f02ebe17e3f3be..7884c221da20c8fe1a945200755e10c1e9cf18fc 100644 (file)
@@ -9,10 +9,6 @@
 \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
@@ -25,78 +21,9 @@ import eu.etaxonomy.cdm.model.name.ZoologicalName;
 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