Features lists now sorted alphabetically. Added microreference, cache strings to...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / propertysheet / description / DescriptionElementPropertySource.java
index 3bd738f7df38bc3db17352273997a16476d69192..63bc8c6bebdf93e379318f409b4a9072e67cbc27 100644 (file)
@@ -20,7 +20,9 @@ import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;\r
 import org.eclipse.ui.views.properties.IPropertySource;\r
 import org.eclipse.ui.views.properties.PropertyDescriptor;\r
+import org.eclipse.ui.views.properties.TextPropertyDescriptor;\r
 \r
+import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.model.description.CommonTaxonName;\r
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
 import eu.etaxonomy.cdm.model.description.Distribution;\r
@@ -29,9 +31,10 @@ import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;\r
 import eu.etaxonomy.cdm.model.description.TaxonInteraction;\r
 import eu.etaxonomy.cdm.model.description.TextData;\r
-import eu.etaxonomy.cdm.model.reference.Generic;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
+import eu.etaxonomy.taxeditor.controller.DescriptionController;\r
+import eu.etaxonomy.taxeditor.controller.ReferenceController;\r
 import eu.etaxonomy.taxeditor.propertysheet.reference.IReferenceSearch;\r
 import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
 import eu.etaxonomy.taxeditor.propertysheet.reference.ReferenceSearchDescriptor;\r
@@ -59,8 +62,10 @@ public class DescriptionElementPropertySource implements IPropertySource {
         * Property unique keys\r
         */\r
        public static final String P_ID_ELEMENT_CLASS = "element_class";\r
+       public static final String P_ID_ELEMENT_TEXT = "text";\r
        public static final String P_ID_FEATURE = "feature";\r
        public static final String P_ID_BIBREF = "bibref";\r
+       public static final String P_ID_MICROREF = "microref";\r
 \r
        /**\r
         * Property display keys\r
@@ -68,11 +73,13 @@ public class DescriptionElementPropertySource implements IPropertySource {
         *  @see eu.etaxonomy.taxeditor.propertysheet.EditorPropertySheetEntry\r
         */\r
        public static final String P_ELEMENT_CLASS = "01:Save element as";\r
-       public static final String P_FEATURE = "00:Feature";\r
+       public static final String P_ELEMENT_TEXT = "00:Element";\r
+       public static final String P_FEATURE = "01:Feature";\r
        public static final String P_BIBREF = "02:Bibliographic Reference";\r
+       public static final String P_MICROREF = "03:Reference Detail";\r
        \r
-//     protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_ELEMENT_CLASS, P_ID_FEATURE, P_ID_BIBREF};\r
-       protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_BIBREF};\r
+       protected static final String[] TOP_LEVEL_PROPERTIES = \r
+                       new String[] {P_ID_ELEMENT_TEXT, P_ID_FEATURE, P_ID_BIBREF, P_ID_MICROREF};\r
        \r
        private String[] P_FEATURE_CLASS_NAME_MENU;\r
        private Class[] P_FEATURE_CLASSES;\r
@@ -152,12 +159,19 @@ public class DescriptionElementPropertySource implements IPropertySource {
                }\r
                \r
                if (id.equals(P_ID_BIBREF)) {\r
-                       descriptors.addElement(new ReferenceSearchDescriptor(P_ID_BIBREF, P_BIBREF, IReferenceSearch.BIBREF) {\r
-                               protected void saveReference(ReferenceBase reference) {\r
-                                       setPropertyValue(P_ID_BIBREF, reference);\r
-                               }\r
-                       });                     \r
-//                     descriptors.addElement(new TextPropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
+//                     descriptors.addElement(new ReferenceSearchDescriptor(P_ID_BIBREF, P_BIBREF, IReferenceSearch.BIBREF) {\r
+//                             protected void saveReference(ReferenceBase reference) {\r
+//                                     setPropertyValue(P_ID_BIBREF, reference);\r
+//                             }\r
+//                     });                     \r
+                       descriptors.addElement(new PropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
+               }\r
+               if (id.equals(P_ID_ELEMENT_TEXT)) {\r
+                       descriptors.addElement(new TextPropertyDescriptor(P_ID_ELEMENT_TEXT, P_ELEMENT_TEXT));\r
+               }\r
+               \r
+               if (id.equals(P_ID_MICROREF)) {\r
+                       descriptors.addElement(new TextPropertyDescriptor(P_ID_MICROREF, P_MICROREF));\r
                }\r
        }\r
        \r
@@ -210,7 +224,15 @@ public class DescriptionElementPropertySource implements IPropertySource {
                                }\r
                        });\r
                        return bibRefPropertySource;\r
-               }               \r
+               }\r
+               \r
+               if (id.equals(P_ID_ELEMENT_TEXT)) {\r
+                       return DescriptionController.getCache(descriptionElement);      \r
+               }\r
+\r
+               if (id.equals(P_ID_MICROREF)) {\r
+                       return CdmUtils.Nz(descriptionElement.getCitationMicroReference());\r
+               }\r
                \r
                return null;\r
        }\r
@@ -241,20 +263,22 @@ public class DescriptionElementPropertySource implements IPropertySource {
                                descriptionElement.setCitation((ReferenceBase) value);\r
                        }\r
                        \r
-                       if (value instanceof String) {\r
-                               \r
-                       }\r
-                       ReferenceBase bibRef = descriptionElement.getCitation();\r
-                       if (bibRef == null) {\r
-                               bibRef = Generic.NewInstance();\r
-                               descriptionElement.setCitation(bibRef);\r
-                       }\r
+                       ReferenceBase bibRef = \r
+                                       ReferenceController.getOrCreateCitation(descriptionElement);\r
                        \r
                        // "value" is the ReferencePropertySource, so we get the TitleCache from its\r
                        // toString() method\r
                        bibRef.setTitleCache(value.toString());\r
                }\r
                \r
+               if (id.equals(P_ID_ELEMENT_TEXT)) {\r
+                       DescriptionController.setCache(descriptionElement, (String) value);\r
+               }\r
+               \r
+               if (id.equals(P_ID_MICROREF)) {\r
+                       descriptionElement.setCitationMicroReference((String) value);\r
+               }\r
+               \r
                descriptionElement.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null);\r
        }\r
 }\r