p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / name / NonViralNamePropertySource.java
index a55cfb07d5e4ed524301b809739c54a3cb8fd26f..2fcbbe8e36d0ace08b35521d63f09dd50d49c9a3 100644 (file)
@@ -9,10 +9,10 @@
 \r
 package eu.etaxonomy.taxeditor.propertysheet.name;\r
 \r
+import java.beans.PropertyChangeEvent;\r
 import java.beans.PropertyChangeListener;\r
 import java.beans.PropertyChangeSupport;\r
 import java.util.ArrayList;\r
-import java.util.Calendar;\r
 import java.util.Date;\r
 import java.util.List;\r
 import java.util.Set;\r
@@ -26,25 +26,23 @@ import org.eclipse.ui.views.properties.PropertyDescriptor;
 import org.eclipse.ui.views.properties.TextPropertyDescriptor;\r
 \r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
-import eu.etaxonomy.cdm.model.common.Annotation;\r
+import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.cdm.model.common.TimePeriod;\r
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;\r
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
-import eu.etaxonomy.cdm.model.reference.Article;\r
-import eu.etaxonomy.cdm.model.reference.BibtexReference;\r
-import eu.etaxonomy.cdm.model.reference.Book;\r
-import eu.etaxonomy.cdm.model.reference.BookSection;\r
 import eu.etaxonomy.cdm.model.reference.Generic;\r
 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
-import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
-import eu.etaxonomy.taxeditor.UiUtil;\r
+import eu.etaxonomy.taxeditor.controller.PreferencesController;\r
+import eu.etaxonomy.taxeditor.model.CdmSessionDataRepository;\r
 import eu.etaxonomy.taxeditor.propertysheet.AnnotationPropertySource;\r
 import eu.etaxonomy.taxeditor.propertysheet.AnnotationsPropertyDescriptor;\r
 import eu.etaxonomy.taxeditor.propertysheet.MarkersPropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.NomenclaturalReferencePropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -59,7 +57,7 @@ public class NonViralNamePropertySource implements IPropertySource {
        NonViralName name;\r
        \r
        // If this is a property with a parent, the parent's property ID\r
-       private String parentid;\r
+       private String parentid = "";\r
        \r
        PropertyChangeSupport propertyChangeSupport;\r
        \r
@@ -67,13 +65,7 @@ public class NonViralNamePropertySource implements IPropertySource {
        public static final String P_ID_PARSED = "parsed";\r
        public static final String P_ID_RANK = "rank";\r
        public static final String P_ID_TITLECACHE = "titlecache";\r
-       public static final String P_ID_UNINOMIAL = "uninomial";\r
-       public static final String P_ID_INFRAGENERICEP = "infragenericep";\r
-       public static final String P_ID_SPECIESEP = "speciesep";\r
-       public static final String P_ID_INFRASPECIFICEP = "infraspecificep";\r
-       public static final String P_ID_APPENDEDPHRASE = "appendedphrase";\r
        public static final String P_ID_HOMOTYPICALGROUP = "homogroup";\r
-       public static final String P_ID_AUTHORSHIPCACHE = "authorshipcache";\r
        public static final String P_ID_NAMERELATIONS = "namerelations";\r
        public static final String P_ID_TYPE = "type";\r
        public static final String P_ID_ANNOTATIONS = "annotations";\r
@@ -86,10 +78,6 @@ public class NonViralNamePropertySource implements IPropertySource {
        public static final String P_ID_NOMENCLATURAL_CODE = "nomenclaturalcode";\r
        public static final String P_ID_NOMENCLATURAL_REF = "nomenclaturalref";\r
        public static final String P_ID_NOMENCLATURAL_MICROREF = "nomenclaturalmicroref";\r
-       public static final String P_ID_REFERENCEYEAR = "referenceyear";\r
-       public static final String P_ID_NOMREF_TYPE = "nomreftype";\r
-       public static final String P_ID_NOMREF_YEAR = "nomrefyear";\r
-       public static final String P_ID_NOMREF_TITLE = "nomreftitle";\r
        \r
     // Property display keys\r
        // Note: for an explanation of the sorting prefixes ("04:"), \r
@@ -97,17 +85,11 @@ public class NonViralNamePropertySource implements IPropertySource {
        public static final String P_PARSED = "00:Parsing Status";\r
        public static final String P_RANK = "02:Rank";\r
        public static final String P_TITLECACHE = "03:Name Cache";\r
-       public static final String P_UNINOMIAL = "04:Uninomial";\r
-       public static final String P_INFRAGENERICEP = "05:Infrageneric Epithet";\r
-       public static final String P_SPECIESEP = "06:Specific Epithet";\r
-       public static final String P_INFRASPECIFICEP = "07:Infraspecific Epithet";\r
-       public static final String P_APPENDEDPHRASE = "09:Appended Phrase";\r
        public static final String P_HOMOTYPICALGROUP = "09:Homotypical Group";\r
-       public static final String P_AUTHORSHIPCACHE = "08:Authorship";\r
        public static final String P_NAMERELATIONS = "11:Name Relations";\r
        public static final String P_TYPE = "12:Type";\r
        public static final String P_ANNOTATIONS = "14:Annotations";\r
-       public static final String P_NOMSTATUS = "10:Nomenclatural Status";\r
+       public static final String P_NOMSTATUS = "100:Nomenclatural Status";\r
        public static final String P_UUID = "01:UUID";\r
        public static final String P_NUM_OF_BASES = "12:Number of Bases";\r
        public static final String P_MARKERS = "13:Markers";\r
@@ -115,14 +97,12 @@ public class NonViralNamePropertySource implements IPropertySource {
        public static final String P_CREATEDBY = "16:Created By";\r
        public static final String P_NOMENCLATURAL_CODE = "02:Nomenclatural Code";\r
        public static final String P_NOMENCLATURAL_REF = "09:Nomenclatural Reference";\r
-       public static final String P_NOMENCLATURAL_MICROREF = "10:Micro Reference";\r
-       public static final String P_NOMREF_TYPE = "00:Reference Type";\r
-       public static final String P_NOMREF_YEAR = "02:Year";\r
-       public static final String P_NOMREF_TITLE = "01:Title";\r
+       public static final String P_NOMENCLATURAL_MICROREF = "10:Reference Detail";\r
        \r
-       protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_PARSED, P_ID_RANK, P_ID_TITLECACHE,  \r
-                       P_ID_ANNOTATIONS, P_ID_NOMSTATUS, P_ID_NAMERELATIONS, P_ID_UUID, P_ID_NOMENCLATURAL_REF,\r
-                       P_ID_TYPE, P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE };     \r
+       protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {\r
+                       P_ID_PARSED, P_ID_RANK, P_ID_TITLECACHE, P_ID_ANNOTATIONS, P_ID_NOMSTATUS, \r
+                       P_ID_NAMERELATIONS, P_ID_UUID, P_ID_NOMENCLATURAL_REF, P_ID_NOMENCLATURAL_MICROREF,\r
+                       P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE };        \r
        \r
        // ***********************************************************\r
        //              RANKS\r
@@ -133,7 +113,7 @@ public class NonViralNamePropertySource implements IPropertySource {
                \r
                // Get terms from rank vocabulary\r
                List<Rank> ranksList = new ArrayList<Rank>();\r
-               ranksList.addAll(UiUtil.getPreferredRanks());\r
+               ranksList.addAll(PreferencesController.getPreferredRanks());\r
                \r
                // Populate ranks menu labels \r
                List<String> ranksMenuList = new ArrayList<String>();\r
@@ -150,21 +130,28 @@ public class NonViralNamePropertySource implements IPropertySource {
                P_RANK_MENU = ranksMenuList.toArray(new String[ranksMenuList.size()]);\r
        }\r
        \r
-       static String[] P_NOMENCLATURALCODE_MENU = new String[] { "ICZN", "ICBN" };\r
-       static String[] P_NOMREF_TYPE_MENU = new String[] { "Article", "Bibtex", "Book", "Book Section", "Generic" };   \r
-\r
        // ***********************************************************\r
        //              NOMENCLATURAL STATUS\r
        // ***********************************************************\r
-       static TermVocabulary<NomenclaturalStatusType> nomStatusVocabulary = \r
-                       TaxEditorPlugin.getDefault().getNomStatusVocabulary();\r
-       static NomenclaturalStatusType[] nomStatusTypes = null;\r
-       static String[] P_NOMSTATUS_MENU = null;\r
-       private static void populateNomStatusTypes() {\r
+//     static TermVocabulary<NomenclaturalStatusType> nomStatusVocabulary = \r
+//                     TaxEditorPlugin.getDefault().getNomStatusVocabulary();\r
+       NomenclaturalStatusType[] nomStatusTypes = null;\r
+       String[] P_NOMSTATUS_MENU = null;\r
+       private void populateNomStatusTypes() {\r
                \r
                // Get terms from nom status vocabulary\r
                List<NomenclaturalStatusType> nomStatusTypesList = new ArrayList<NomenclaturalStatusType>();\r
-               nomStatusTypesList.addAll(nomStatusVocabulary.getTerms());\r
+               TermVocabulary<NomenclaturalStatusType> statusVocab = \r
+                               CdmSessionDataRepository.getDefault().getNomStatus();\r
+               \r
+               // If there is no status vocabulary, init type and status w empty arrays and return\r
+               if (statusVocab == null) {\r
+                       nomStatusTypes = new NomenclaturalStatusType[]{};\r
+                       P_NOMSTATUS_MENU = new String[]{};\r
+                       return;\r
+               }\r
+               \r
+               nomStatusTypesList.addAll(statusVocab.getTerms());\r
                \r
                // Populate nom status type menu labels \r
                List<String> nomStatusTypesMenuList = new ArrayList<String>();\r
@@ -202,10 +189,14 @@ public class NonViralNamePropertySource implements IPropertySource {
         * @param id\r
         */\r
        protected void addDescriptor(String id) {\r
+               \r
+               // Parsed: reports whether parsing was successful\r
                if (id.equals(P_ID_PARSED)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_PARSED, P_PARSED));\r
                }\r
+               \r
+               // Rank menu\r
                if (id.equals(P_ID_RANK)) {\r
                        if (ranks == null) {\r
                                populateRanks();\r
@@ -213,42 +204,23 @@ public class NonViralNamePropertySource implements IPropertySource {
                        descriptors.addElement(\r
                                        new ComboBoxPropertyDescriptor(P_ID_RANK, P_RANK, P_RANK_MENU));\r
                }\r
+               \r
+               // Title cache\r
                if (id.equals(P_ID_TITLECACHE)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_TITLECACHE, P_TITLECACHE));\r
                }\r
-               if (id.equals(P_ID_UNINOMIAL)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_UNINOMIAL, P_UNINOMIAL));\r
-               }\r
-               if (id.equals(P_ID_INFRAGENERICEP)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_INFRAGENERICEP, P_INFRAGENERICEP));\r
-               }\r
-               if (id.equals(P_ID_SPECIESEP)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_SPECIESEP, P_SPECIESEP));\r
-               }\r
-               if (id.equals(P_ID_INFRASPECIFICEP)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_INFRASPECIFICEP, P_INFRASPECIFICEP));\r
-               }\r
-               if (id.equals(P_ID_APPENDEDPHRASE)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_APPENDEDPHRASE, P_APPENDEDPHRASE));\r
-               }\r
-               if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_AUTHORSHIPCACHE, P_AUTHORSHIPCACHE));\r
-               }\r
+                               \r
+               // Homotypical group\r
                if (id.equals(P_ID_HOMOTYPICALGROUP)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_HOMOTYPICALGROUP, P_HOMOTYPICALGROUP));\r
                }\r
+               \r
+               // Name relations, listed in custom property descriptor\r
                if (id.equals(P_ID_NAMERELATIONS)) {\r
                        descriptors.addElement(\r
                                        new NameRelationsPropertyDescriptor(P_ID_NAMERELATIONS, P_NAMERELATIONS, name) {\r
-                                               @Override\r
                                                protected void saveNameRelations(Set set) {\r
                                                        setPropertyValue(P_ID_NAMERELATIONS, set);\r
                                                }\r
@@ -256,20 +228,24 @@ public class NonViralNamePropertySource implements IPropertySource {
                        );\r
                };\r
                \r
+               // Type\r
                if (id.equals(P_ID_TYPE)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_TYPE, P_TYPE));\r
                }\r
+               \r
+               // Annotations, listed in custom property descriptor\r
                if (id.equals(P_ID_ANNOTATIONS)) {\r
                        descriptors.addElement(\r
                                        new AnnotationsPropertyDescriptor(P_ID_ANNOTATIONS, P_ANNOTATIONS, name) {\r
-                                               @Override\r
                                                protected void saveAnnotations(Set set) {\r
                                                        setPropertyValue(P_ID_ANNOTATIONS, set);\r
                                                }\r
                                        }\r
                        );\r
                };\r
+               \r
+               // Nomenclatural status\r
                if (id.equals(P_ID_NOMSTATUS)) {\r
                        if (nomStatusTypes == null) {\r
                                populateNomStatusTypes();\r
@@ -277,54 +253,54 @@ public class NonViralNamePropertySource implements IPropertySource {
                        descriptors.addElement(\r
                                        new ComboBoxPropertyDescriptor(P_ID_NOMSTATUS, P_NOMSTATUS, P_NOMSTATUS_MENU));\r
                }               \r
+               \r
+               // UUID\r
                if (id.equals(P_ID_UUID)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_UUID, P_UUID));\r
                }\r
+               \r
+               // Markers\r
                if (id.equals(P_ID_MARKERS)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_MARKERS, P_MARKERS));\r
                }\r
+               \r
+               // Taxon bases referring to this name\r
                if (id.equals(P_ID_NUM_OF_BASES)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_NUM_OF_BASES, P_NUM_OF_BASES));\r
                }\r
+               \r
+               // Object created when\r
                if (id.equals(P_ID_CREATED)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_CREATED, P_CREATED));\r
                }\r
+               \r
+               // Object created by\r
                if (id.equals(P_ID_CREATEDBY)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_CREATEDBY, P_CREATEDBY));\r
                }\r
+               \r
+               // Nomenclatural code used by parser\r
                if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_NOMENCLATURAL_CODE, P_NOMENCLATURAL_CODE));\r
-                                       // Assuming the ability to change a name's code is not a burning priority ...\r
-//                                     new ComboBoxPropertyDescriptor(P_ID_NOMENCLATURAL_CODE, P_NOMENCLATURAL_CODE, P_NOMENCLATURALCODE_MENU));\r
                }\r
+               \r
+               // Nomenclatural reference\r
                if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
                        descriptors.addElement(\r
-//                                     new TextPropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));\r
-                                       new PropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));\r
+                                       new PropertyDescriptor(P_ID_NOMENCLATURAL_REF,P_NOMENCLATURAL_REF));                    \r
                }\r
+               \r
+               // Microreference\r
                if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
                        descriptors.addElement(\r
                                        new TextPropertyDescriptor(P_ID_NOMENCLATURAL_MICROREF,P_NOMENCLATURAL_MICROREF));\r
-               }\r
-               if (id.equals(P_ID_NOMREF_TYPE)) {\r
-                       descriptors.addElement(\r
-                                       new PropertyDescriptor(P_ID_NOMREF_TYPE, P_NOMREF_TYPE));\r
-//                                     new ComboBoxPropertyDescriptor(P_ID_NOMREF_TYPE, P_NOMREF_TYPE, P_NOMREF_TYPE_MENU));\r
-               }\r
-               if (id.equals(P_ID_NOMREF_YEAR)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_NOMREF_YEAR, P_NOMREF_YEAR));\r
-               }\r
-               if (id.equals(P_ID_NOMREF_TITLE)) {\r
-                       descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_NOMREF_TITLE, P_NOMREF_TITLE));\r
-               }                               \r
+               }       \r
        }\r
        \r
        /**\r
@@ -345,22 +321,23 @@ public class NonViralNamePropertySource implements IPropertySource {
                }\r
        }\r
 \r
-       @Override\r
        public Object getEditableValue() {\r
-               return this;\r
+               return CdmUtils.Nz(name.getTitleCache());\r
        }\r
 \r
-       @Override\r
        public IPropertyDescriptor[] getPropertyDescriptors() {\r
                return (IPropertyDescriptor[]) descriptors.toArray(\r
                 new IPropertyDescriptor[descriptors.size()]);\r
        }\r
 \r
-       @Override\r
        public Object getPropertyValue(Object id) {\r
+               \r
+               // Parsed: reports whether parsing was successful               \r
         if (id.equals(P_ID_PARSED)) {\r
                        return name.getHasProblem() == true ? "problem" : "parsed" ;\r
         }\r
+        \r
+               // Rank menu        \r
                if (id.equals(P_ID_RANK)) {\r
                if (this.name.getRank() == null) {\r
                        return 0;\r
@@ -373,40 +350,41 @@ public class NonViralNamePropertySource implements IPropertySource {
                }\r
                return 0;\r
         }\r
+               \r
+               // Title cache          \r
         if (id.equals(P_ID_TITLECACHE)) {\r
                \r
                // If the name has not been parsed, only show the title cache\r
-//             if (name.getHasProblem()) {\r
                if (name.getRank() == null) {\r
                        return CdmUtils.Nz(name.getTitleCache());\r
                } else {\r
-                       return new NonViralNamePropertySource(name, P_ID_TITLECACHE, getNameFields());\r
+                       \r
+                       // Create property source for submenu\r
+                       ScientificNamePropertySource nameFieldsPropertySource = new ScientificNamePropertySource(name);\r
+                       \r
+                       // Add listener to notify name of all changes to nom. reference\r
+                       nameFieldsPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+//                                     if (evt.getNewValue() instanceof INomenclaturalReference) {\r
+//                                             name.setNomenclaturalReference((INomenclaturalReference) evt.getNewValue());\r
+//                                     }\r
+                               }\r
+                       });\r
+                       return nameFieldsPropertySource;\r
                }\r
         }\r
-               if (id.equals(P_ID_UNINOMIAL)) {\r
-                       return CdmUtils.Nz(name.getGenusOrUninomial());\r
-               }\r
-        if (id.equals(P_ID_INFRAGENERICEP)) {\r
-                       return CdmUtils.Nz(name.getInfraGenericEpithet());\r
-        }\r
-        if (id.equals(P_ID_SPECIESEP)) {\r
-                       return CdmUtils.Nz(name.getSpecificEpithet());\r
-        }\r
-        if (id.equals(P_ID_INFRASPECIFICEP)) {\r
-                       return CdmUtils.Nz(name.getInfraSpecificEpithet());\r
-        }\r
-        if (id.equals(P_ID_APPENDEDPHRASE)) {\r
-               return CdmUtils.Nz(name.getAppendedPhrase());\r
-        }\r
-        if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
-                       return CdmUtils.Nz(name.getAuthorshipCache());\r
-        }\r
+                \r
+               // Homotypical group        \r
         if (id.equals(P_ID_HOMOTYPICALGROUP)) {\r
                        return CdmUtils.Nz(name.getHomotypicalGroup().getUuid().toString());\r
         }\r
-        if (id.equals(P_ID_ANNOTATIONS)) {\r
-                       return new AnnotationPropertySource(name.getAnnotations());\r
-        }\r
+        \r
+               // Annotations, listed in custom property descriptor        \r
+//        if (id.equals(P_ID_ANNOTATIONS)) {\r
+//                     return new AnnotationPropertySource(name.getAnnotations());\r
+//        }\r
+        \r
+               // Nomenclatural status        \r
         if (id.equals(P_ID_NOMSTATUS)) {\r
 //                     return new NomStatusPropertySource(name.getStatus());\r
 //             if (this.name.getRank() == null) return 0;\r
@@ -424,22 +402,33 @@ public class NonViralNamePropertySource implements IPropertySource {
                }\r
                return 0;                       \r
         }\r
+        \r
+               // Name relations, popup to edit list        \r
         if (id.equals(P_ID_NAMERELATIONS)) {\r
                        return new NameRelationsPropertySource(name, name.getNameRelations());\r
         }\r
-        // TODO Button to link to type module\r
+        \r
+               // Type\r
         if (id.equals(P_ID_TYPE)) {\r
                        return "";\r
         }\r
+        \r
+               // UUID        \r
         if (id.equals(P_ID_UUID)) {\r
                        return CdmUtils.Nz(name.getUuid().toString());\r
         }\r
+        \r
+               // Markers        \r
         if (id.equals(P_ID_MARKERS)) {\r
                        return new MarkersPropertySource(name.getMarkers());\r
         }\r
+\r
+               // Taxon bases referring to this name        \r
         if (id.equals(P_ID_NUM_OF_BASES)) {\r
                        return name.getTaxonBases().size();\r
         }\r
+        \r
+               // Object created by        \r
         if (id.equals(P_ID_CREATED)) {\r
                if (name.getCreated() == null) {\r
                        return "";\r
@@ -447,153 +436,63 @@ public class NonViralNamePropertySource implements IPropertySource {
                        return formatDate(name.getCreated().toDate());\r
                }\r
         }\r
+        \r
+               // Object created when        \r
         if (id.equals(P_ID_CREATEDBY)) {\r
                if (name.getCreatedBy() == null) {\r
                        return "";\r
                } else {\r
-                       return CdmUtils.Nz(name.getCreatedBy().generateTitle());\r
+                       return CdmUtils.Nz(((IIdentifiableEntity) name.getCreatedBy()).generateTitle());\r
                }\r
         }\r
+        \r
+               // Nomenclatural code used by parser        \r
         if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
                // Only shown if extending classes don't handle P_ID_NOMENCLATURAL_CODE \r
                return "none (nonviral name)";\r
         }\r
+        \r
+               // Nomenclatural reference        \r
         if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
-//             INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-//             if (nomenclaturalReference == null) {\r
-//                     return "";\r
-//             }               \r
-//             String microReference = name.getNomenclaturalMicroReference();\r
-//                     return CdmUtils.Nz(nomenclaturalReference.getNomenclaturalCitation(microReference));\r
+               \r
+               ReferenceBase nomRef = (ReferenceBase) name.getNomenclaturalReference();\r
                        \r
-               INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-               if (name.getNomenclaturalReference() == null) {\r
-                       return "";\r
-               } else {\r
-                       return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields());\r
-               }\r
+                       // Create nom. reference as necessary\r
+                       if (nomRef == null) {\r
+                               nomRef = Generic.NewInstance();\r
+                       }\r
+                       \r
+                       // Create property source for submenu\r
+                       ReferencePropertySource nomRefPropertySource = new NomenclaturalReferencePropertySource(nomRef);\r
+                       \r
+                       // Add listener to notify name of all changes to nom. reference\r
+                       nomRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       if (evt.getNewValue() instanceof INomenclaturalReference) {\r
+                                               name.setNomenclaturalReference((ReferenceBase) evt.getNewValue());\r
+                                       }\r
+                               }\r
+                       });\r
+                       return nomRefPropertySource;\r
+               \r
         }\r
+        \r
+               // Microreference        \r
         if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
                        return CdmUtils.Nz(name.getNomenclaturalMicroReference());\r
         }\r
-        INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-        if (id.equals(P_ID_NOMREF_TYPE)) {\r
-               if (nomenclaturalReference instanceof Article) {\r
-                       return "Article";\r
-               }\r
-               if (nomenclaturalReference instanceof BibtexReference) {\r
-                       return "Bibtex";\r
-               }\r
-               if (nomenclaturalReference instanceof Book) {\r
-                       return "Book";                  \r
-               }\r
-               if (nomenclaturalReference instanceof BookSection) {\r
-                       return "Book Section";                  \r
-               }\r
-               if (nomenclaturalReference instanceof Generic) {\r
-                       return "Generic";                       \r
-               }               \r
-               return "none";\r
-        }\r
-        if (id.equals(P_ID_NOMREF_YEAR)) {\r
-               return CdmUtils.Nz(nomenclaturalReference.getYear());\r
-        }\r
-        if (id.equals(P_ID_NOMREF_TITLE)) {\r
-               if (nomenclaturalReference instanceof Article) {\r
-                       return CdmUtils.Nz(((Article) nomenclaturalReference).getTitle());\r
-               }\r
-               if (nomenclaturalReference instanceof BibtexReference) {\r
-                       return CdmUtils.Nz(((BibtexReference) nomenclaturalReference).getTitle());\r
-               }\r
-               if (nomenclaturalReference instanceof Book) {\r
-                       return CdmUtils.Nz(((Book) nomenclaturalReference).getTitle());\r
-               }\r
-               if (nomenclaturalReference instanceof BookSection) {\r
-                       return CdmUtils.Nz(((BookSection) nomenclaturalReference).getTitle());\r
-               }\r
-               if (nomenclaturalReference instanceof Generic) {\r
-                       return CdmUtils.Nz(((Generic) nomenclaturalReference).getTitle());\r
-               }\r
-        }\r
         return null;\r
        }\r
  \r
-       /**\r
-        * The fields displayed under the title cache are dependent on rank.\r
-        * \r
-        * @return\r
-        */\r
-       private String[] getNameFields() {\r
-               \r
-               // An unparsed name has no name fields, only a cache. \r
-               //      Therefore, if rank is null, the name is unparsed.\r
-               if (name.getRank() == null) {\r
-                       return null;\r
-               }\r
-               \r
-       List<String> nameFields = new ArrayList<String>();\r
-       nameFields.add(P_ID_UNINOMIAL);\r
-       if (name.isSupraGeneric() || name.isGenus()) { // Rank is higher than GENUS or equals GENUS\r
-       }\r
-       else if (name.isInfraGeneric()) { // lower than GENUS and higher than SPECIES\r
-               nameFields.add(P_ID_INFRAGENERICEP);\r
-       }   \r
-       else if (name.isSpecies()) { // Rank equals SPECIES\r
-               nameFields.add(P_ID_SPECIESEP);\r
-       }\r
-       else if (name.isInfraSpecific()) { // Rank is lower than SPECIES\r
-               nameFields.add(P_ID_SPECIESEP);\r
-               nameFields.add(P_ID_INFRASPECIFICEP);\r
-       } else {\r
-               nameFields.add(P_ID_SPECIESEP);\r
-       }\r
-       nameFields.add(P_ID_AUTHORSHIPCACHE);\r
-       nameFields.add(P_ID_APPENDEDPHRASE);\r
-       return nameFields.toArray(new String[nameFields.size()]);\r
-       }\r
-\r
-       private String[] getReferenceFields() {\r
-               List<String> referenceFields = new ArrayList<String>();\r
-               \r
-       INomenclaturalReference reference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-       if (reference == null) {\r
-               return null;\r
-       }\r
-       \r
-       referenceFields.add(P_ID_NOMREF_TYPE);\r
-       referenceFields.add(P_ID_NOMREF_YEAR);\r
-       referenceFields.add(P_ID_NOMENCLATURAL_MICROREF);\r
-       referenceFields.add(P_ID_NOMREF_TITLE);\r
-       \r
-       if (reference instanceof Article) {\r
-\r
-       }\r
-       if (reference instanceof BibtexReference) {\r
-               \r
-       }\r
-       if (reference instanceof Book) {\r
-\r
-       }\r
-       if (reference instanceof BookSection) {\r
-               \r
-       }\r
-       if (reference instanceof Generic) {\r
-               \r
-       }\r
-               \r
-               return referenceFields.toArray(new String[referenceFields.size()]);\r
-       }\r
        \r
        private Object formatDate(Date date) {\r
                return String.format("%1$tm-%1$td-%1$tY %1$tH:%1$tM:%1$tS", date);\r
        }\r
        \r
-       @Override\r
        public boolean isPropertySet(Object id) {\r
                return false;\r
        }\r
 \r
-       @Override\r
        public void resetPropertyValue(Object id) {}\r
 \r
        /** \r
@@ -601,7 +500,6 @@ public class NonViralNamePropertySource implements IPropertySource {
         * \r
         * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)\r
         */\r
-       @Override\r
        public void setPropertyValue(Object id, Object value) {\r
                                \r
                // Since this is only called when the property value changes,\r
@@ -609,41 +507,13 @@ public class NonViralNamePropertySource implements IPropertySource {
                //      listener.\r
                name.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null);\r
                \r
+               // Rank menu            \r
                if (id.equals(P_ID_RANK)) {\r
                        int index = ((Integer) value).intValue();\r
                        name.setRank(ranks[index]);\r
         }\r
-               if (id.equals(P_ID_UNINOMIAL)) {\r
-                       name.setGenusOrUninomial((String) value);\r
-               }\r
-        if (id.equals(P_ID_INFRAGENERICEP)) {\r
-                       name.setInfraGenericEpithet((String) value);\r
-        }\r
-        if (id.equals(P_ID_SPECIESEP)) {\r
-                       name.setSpecificEpithet((String) value);\r
-        }\r
-        if (id.equals(P_ID_INFRASPECIFICEP)) {\r
-                       name.setInfraSpecificEpithet((String) value);\r
-        }\r
-        if (id.equals(P_ID_APPENDEDPHRASE)) {\r
-                       name.setAppendedPhrase((String) value);\r
-        }\r
-        if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
-                       name.setAuthorshipCache((String) value);\r
-        }\r
-        if (id.equals(P_ID_ANNOTATIONS)) {\r
-               Set annotations = name.getAnnotations();\r
-               if (value instanceof Set) {\r
-                       for (Object object: (Set) value) {\r
-                               if (object instanceof Annotation && !annotations.contains(object)) {\r
-                                       name.addAnnotation((Annotation) object);\r
-                               }\r
-                       }\r
-               }\r
-        }\r
-        if (id.equals(P_ID_NAMERELATIONS)) {\r
-               // TODO set name relations\r
-        }\r
+                       \r
+               // Nomenclatural status        \r
         if (id.equals(P_ID_NOMSTATUS)) {\r
                NomenclaturalStatus nomStatus;\r
                        int index = ((Integer) value).intValue();\r
@@ -663,102 +533,35 @@ public class NonViralNamePropertySource implements IPropertySource {
                                name.addStatus(nomStatus);\r
                        }\r
         }\r
+        \r
+               // Markers        \r
         if (id.equals(P_ID_MARKERS)) {\r
                // TODO set markers\r
         }\r
+        \r
+               // Nomenclatural reference        \r
         if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
-               // TODO ask Andreas M. how best to set nom. ref\r
+               if (value instanceof INomenclaturalReference) {\r
+                       name.setNomenclaturalReference((ReferenceBase) value);\r
+               }\r
         }\r
+        \r
+               // Microreference        \r
         if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
                name.setNomenclaturalMicroReference((String) value);\r
         }\r
-        if (id.equals(P_ID_NOMREF_YEAR)) {\r
-               INomenclaturalReference reference = name.getNomenclaturalReference();\r
-               \r
-               if (reference instanceof BibtexReference) {\r
-                       ((BibtexReference) reference).setYear((String) value);\r
-               }\r
-               TimePeriod datePublished = getDatePublished((String) value);\r
-               if (reference instanceof Article) {\r
-                       ((Article) reference).setDatePublished(datePublished);\r
-               }\r
-               if (reference instanceof Book) {\r
-                       ((Book) reference).setDatePublished(datePublished);\r
-               }\r
-               if (reference instanceof BookSection) {\r
-                       ((BookSection) reference).setDatePublished(datePublished);\r
-               }\r
-               if (reference instanceof Generic) {\r
-                       ((Generic) reference).setDatePublished(datePublished);\r
-               }\r
-        }\r
-        if (id.equals(P_ID_NOMREF_TITLE)) {\r
-               INomenclaturalReference reference = name.getNomenclaturalReference();\r
+        \r
+               // If there is no rank, generated caches will be blank, wiping out the freetext area\r
+        if (name.getRank() != null) {\r
                \r
-               if (reference instanceof BibtexReference) {\r
-                       ((BibtexReference) reference).setTitle((String) value);\r
-               }\r
-               if (reference instanceof Article) {\r
-                       ((Article) reference).setTitle((String) value);\r
-               }\r
-               if (reference instanceof Book) {\r
-                       ((Book) reference).setTitle((String) value);\r
-               }\r
-               if (reference instanceof BookSection) {\r
-                       ((BookSection) reference).setTitle((String) value);\r
-               }\r
-               if (reference instanceof Generic) {\r
-                       ((Generic) reference).setTitle((String) value);\r
-               }\r
+               // Reset both caches to reflect property sheet changes\r
+                       name.setTitleCache(name.generateTitle(), false);\r
+                       name.setFullTitleCache(name.generateFullTitle(), false);\r
         }\r
-        \r
-               // Reset both caches to reflect property sheet changes\r
-               name.setTitleCache(name.generateTitle(), false);\r
-               name.setFullTitleCache(name.generateFullTitle(), false);\r
                \r
-               name.firePropertyChange(ITaxEditorConstants.REFRESH_NAMEVIEWER, null, null);\r
-       }\r
-\r
-       private TimePeriod getDatePublished(String refYear) {\r
-               if (refYear == null){\r
-                       return null;\r
-               }\r
+//             name.firePropertyChange(ITaxEditorConstants.REFRESH_NAMEVIEWER, null, null);\r
                \r
-               String[] years = refYear.split("-");\r
-               Calendar calStart = null;\r
-               Calendar calEnd = null;\r
-               if (years.length > 2 || years.length <= 0){\r
-                       logger.warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX getDatePublished");\r
-               }else {\r
-                       calStart = getCalendar(years[0]);\r
-                       if (years.length >= 2){\r
-                                       calEnd = getCalendar(years[1]);\r
-                       }\r
-               }\r
-               TimePeriod result = TimePeriod.NewInstance(calStart, calEnd);\r
-               return result;\r
        }\r
-       \r
-       private static Calendar getCalendar(String strYear){\r
-       \r
-               //FIXME until now only quick and dirty and wrong\r
-               Calendar cal = Calendar.getInstance();\r
-               cal.set(9999, Calendar.DECEMBER, 30, 0, 0, 0);\r
-               if (CdmUtils.isNumeric(strYear)){\r
-                       try {\r
-                               Integer year = Integer.valueOf(strYear.trim());\r
-                               if (year > 1750 && year < 2030){\r
-                                       cal.set(year, Calendar.JANUARY, 1, 0, 0, 0);\r
-                               }\r
-                       } catch (NumberFormatException e) {\r
-                               logger.debug("Not a Integer format in getCalendar()");\r
-                       }\r
-               }\r
-               \r
-               return cal;\r
-       \r
-       }\r
-       \r
 \r
        /** \r
         * Any node with children must override {@link java.lang.Object#toString()} \r
@@ -766,13 +569,15 @@ public class NonViralNamePropertySource implements IPropertySource {
         *  \r
         * @see java.lang.Object#toString()\r
         */\r
-       @Override\r
        public String toString() {\r
+               if (parentid == null || parentid.equals("")) {\r
+                       return "";\r
+               }\r
                if (parentid.equals(P_ID_TITLECACHE)) {\r
                        return name.getTitleCache(); \r
                }\r
                if (parentid.equals(P_ID_NOMENCLATURAL_REF)) {\r
-               INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference();\r
+               INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
                if (nomenclaturalReference == null) {\r
                        return "";\r
                }               \r