Fixed annotations.
authorp.ciardelli <p.ciardelli@localhost>
Fri, 28 Nov 2008 16:26:36 +0000 (16:26 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Fri, 28 Nov 2008 16:26:36 +0000 (16:26 +0000)
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/AnnotationsDialog.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/AnnotationsPropertyDescriptor.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java

index fcac62444e41a65ab7c896fe752a8cf739003c81..e67f69c27359e00164db1c34d6ab4d6b4da77a9b 100644 (file)
@@ -30,6 +30,7 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;\r
 import org.eclipse.swt.widgets.Text;\r
 \r
+import eu.etaxonomy.cdm.model.common.AnnotatableEntity;\r
 import eu.etaxonomy.cdm.model.common.Annotation;\r
 \r
 public class AnnotationsDialog extends Dialog {\r
@@ -43,6 +44,7 @@ public class AnnotationsDialog extends Dialog {
        \r
        private WritableList list = new WritableList();\r
        private Annotation selectedAnnotation;\r
+       private AnnotatableEntity entity;\r
 \r
        /**\r
         * Create the dialog\r
@@ -61,8 +63,10 @@ public class AnnotationsDialog extends Dialog {
                this(parent, SWT.NONE);\r
        }\r
 \r
-       public AnnotationsDialog(Shell parent, Set<Annotation> annotations) {\r
+       public AnnotationsDialog(Shell parent, AnnotatableEntity entity) {\r
                this(parent, SWT.NONE);\r
+               this.entity = entity;\r
+               Set<Annotation> annotations = entity.getAnnotations();\r
                for (Annotation annotation : annotations) {\r
                        list.add(annotation);\r
                }\r
@@ -110,8 +114,12 @@ public class AnnotationsDialog extends Dialog {
                addButton.addMouseListener(new MouseAdapter() {\r
                        @Override\r
                        public void mouseDown(MouseEvent e) {\r
+                               if (text.getText().equals("")) {\r
+                                       return;\r
+                               }\r
                                Annotation annotation = Annotation.NewInstance(text.getText(), null);\r
                                list.add(annotation);\r
+                               entity.addAnnotation(annotation);\r
                                text.setText("");\r
                        }\r
                });\r
@@ -121,7 +129,6 @@ public class AnnotationsDialog extends Dialog {
                table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));\r
                table.setLinesVisible(false);\r
                table.setHeaderVisible(false);\r
-//             table.s\r
                new Label(composite, SWT.NONE);\r
 \r
                ObservableListContentProvider providerList = new ObservableListContentProvider();\r
@@ -182,6 +189,7 @@ public class AnnotationsDialog extends Dialog {
                \r
                public void run() {\r
                        list.remove(annotation);\r
+                       entity.removeAnnotation(annotation);\r
                }\r
        }\r
 }
\ No newline at end of file
index b0955b60048a4cb136681636ea65c0800e89849c..089405652629bbd9451290360f3d51dcda579b79 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Dialog;\r
 import org.eclipse.ui.views.properties.PropertyDescriptor;\r
 \r
+import eu.etaxonomy.cdm.model.common.AnnotatableEntity;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
 \r
 /**\r
@@ -33,11 +34,11 @@ abstract public class AnnotationsPropertyDescriptor extends PropertyDescriptor {
        private static final Logger logger = Logger\r
                        .getLogger(AnnotationsPropertyDescriptor.class);\r
        \r
-       private TaxonNameBase name;\r
+       private AnnotatableEntity entity;\r
        \r
-       public AnnotationsPropertyDescriptor(Object id, String displayName, TaxonNameBase name) {\r
+       public AnnotationsPropertyDescriptor(Object id, String displayName, AnnotatableEntity entity) {\r
                super(id, displayName);\r
-               this.name = name;\r
+               this.entity = entity;\r
        }\r
 \r
     public CellEditor createPropertyEditor(Composite parent) {\r
@@ -48,7 +49,7 @@ abstract public class AnnotationsPropertyDescriptor extends PropertyDescriptor {
                        @Override\r
                        protected Object openDialogBox(\r
                                        Control cellEditorWindow) {\r
-                       dialog = new AnnotationsDialog(cellEditorWindow.getShell(), name.getAnnotations());\r
+                       dialog = new AnnotationsDialog(cellEditorWindow.getShell(), entity);\r
                        Object value = ((AnnotationsDialog) dialog).open();\r
                                if (value instanceof Set) {\r
                                        \r
index 4d1691b2884571ec6d809f28d63e0a46d8b55714..1df2896c30891a76c08ad185e9403989acb2c68d 100644 (file)
@@ -19,7 +19,6 @@ import java.util.Set;
 import java.util.Vector;\r
 \r
 import org.apache.log4j.Logger;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor;\r
 import org.eclipse.ui.views.properties.IPropertyDescriptor;\r
 import org.eclipse.ui.views.properties.IPropertySource;\r
@@ -42,10 +41,8 @@ import eu.etaxonomy.taxeditor.UiUtil;
 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.IReferenceSearch;\r
 import eu.etaxonomy.taxeditor.propertysheet.reference.NomenclaturalReferencePropertySource;\r
 import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
-import eu.etaxonomy.taxeditor.propertysheet.reference.ReferenceSearchDescriptor;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -104,7 +101,7 @@ public class NonViralNamePropertySource implements IPropertySource {
        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
@@ -112,12 +109,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_NOMENCLATURAL_MICROREF = "10:Reference Detail";\r
        \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_TYPE, P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE };     \r
+                       P_ID_CREATED, P_ID_CREATEDBY, P_ID_NOMENCLATURAL_CODE };        \r
        \r
        // ***********************************************************\r
        //              RANKS\r
@@ -145,21 +142,27 @@ 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 = TaxEditorPlugin.getDefault().getNomStatusVocabulary();\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
@@ -283,7 +286,6 @@ public class NonViralNamePropertySource implements IPropertySource {
                        descriptors.addElement(\r
                                        new AnnotationsPropertyDescriptor(P_ID_ANNOTATIONS, P_ANNOTATIONS, name) {\r
                                                protected void saveAnnotations(Set set) {\r
-                                                       \r
                                                        setPropertyValue(P_ID_ANNOTATIONS, set);\r
                                                }\r
                                        }\r
@@ -339,16 +341,6 @@ public class NonViralNamePropertySource implements IPropertySource {
                if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
                        descriptors.addElement(\r
                                        new PropertyDescriptor(P_ID_NOMENCLATURAL_REF,P_NOMENCLATURAL_REF));                    \r
-//                     descriptors.addElement(\r
-//                                     new ReferenceSearchDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF, IReferenceSearch.NOMREF) {\r
-//                                             protected void saveReference(ReferenceBase reference) {\r
-//                                                     if (reference instanceof INomenclaturalReference) {\r
-//                                                             setPropertyValue(P_ID_NOMENCLATURAL_REF, reference);\r
-//                                                     } else {\r
-//                                                             MessageDialog.openError(UiUtil.getShell(), "Reference type error", "The selected reference cannot be used as a nomenclatural reference.");\r
-//                                                     }\r
-//                                             }\r
-//                     });\r
                }\r
                \r
                // Microreference\r
@@ -647,30 +639,10 @@ public class NonViralNamePropertySource implements IPropertySource {
         \r
                // Authorship cache        \r
         if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
+//             name.setProtectedAuthorshipCache(true);\r
                        name.setAuthorshipCache((String) value);\r
         }\r
         \r
-               // Annotations        \r
-        if (id.equals(P_ID_ANNOTATIONS)) {\r
-               if (value instanceof Set) {\r
-                       \r
-                       Set existingAnnotations = name.getAnnotations();        \r
-               Set newAnnotations = (Set) value;\r
-                       \r
-                       for (Object object : newAnnotations) {\r
-                               if (object instanceof Annotation && !existingAnnotations.contains(object)) {\r
-                                       name.addAnnotation((Annotation) object);\r
-                               }\r
-                       }\r
-                       \r
-                       for (Object object : existingAnnotations) {\r
-                               if (object instanceof Annotation && !newAnnotations.contains(object)) {\r
-                                       name.removeAnnotation((Annotation) object);\r
-                               }                               \r
-                       }\r
-                       \r
-               }\r
-        }\r
                // Nomenclatural status        \r
         if (id.equals(P_ID_NOMSTATUS)) {\r
                NomenclaturalStatus nomStatus;\r
@@ -709,9 +681,13 @@ public class NonViralNamePropertySource implements IPropertySource {
                name.setNomenclaturalMicroReference((String) value);\r
         }\r
         \r
-               // Reset both caches to reflect property sheet changes\r
-               name.setTitleCache(name.generateTitle(), false);\r
-               name.setFullTitleCache(name.generateFullTitle(), false);\r
+               // If there is no rank, generated caches will be blank, wiping out the freetext area\r
+        if (name.getRank() != null) {\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
                name.firePropertyChange(ITaxEditorConstants.REFRESH_NAMEVIEWER, null, null);\r
                \r