1) Checkin for Anahit 2) Delete NameRelations works now (maybe not behind the scenes...
authorp.ciardelli <p.ciardelli@localhost>
Thu, 16 Oct 2008 12:35:22 +0000 (12:35 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Thu, 16 Oct 2008 12:35:22 +0000 (12:35 +0000)
12 files changed:
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/SaveAllAction.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameViewer.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/CustomSortPropertySheetEntry.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/description/DescriptionElementPropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/BotanicalNamePropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/ListNameRelationsWizardPage.java

index 0de7d5bb6818d43ff83191fbd7d6527d4b54c922..9557056b5708a41c4b414a1bd2481ae3b047254c 100644 (file)
@@ -70,6 +70,7 @@ public class ITaxEditorConstants {
        public static final String HOMOTYPIC_GROUP = "homotypicgroup";\r
        public static final String QUICK_NAME_TAXON = "quick_name_taxon";\r
        public static final String PROPERTY_SHEET_CHANGE = "property_sheet_change";\r
+       public static final String REFRESH_NAMEVIEWER = "refresh_name_viewer";\r
 \r
        /* ***************************************************************************************\r
                FONTS\r
@@ -92,6 +93,5 @@ public class ITaxEditorConstants {
         ************************************************************************************** */\r
        public static final String FEATURE_PREFERENCE = "feature_preference";\r
        public static final String RANK_PREFERENCE = "rank_preference";\r
-;\r
        \r
 }\r
index 9d50a2d61312b846ca8fbfb96a7ef41358dba1ba..7d12008432b9a7faea68b4dd7e26859aed9dfc84 100644 (file)
@@ -527,10 +527,10 @@ public class TaxEditorPlugin extends AbstractUIPlugin {
                if (sessionRootTaxa == null) {\r
                        \r
                        sessionRootTaxa = new HashSet<Taxon>();\r
-                       sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(\r
-                                       getSec(), null, false));\r
 //                     sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(\r
-//                                     getSec(), null, true));                 \r
+//                                     getSec(), null, false));\r
+                       sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(\r
+                                       getSec(), null, true));                 \r
                        addSessionTaxa(sessionRootTaxa);\r
                                                \r
                }\r
index 6ef9c9b03055308dd278a9d59131b1162393b79d..4b1641148d0faefd4ef3db80326dd4bceb3da508 100644 (file)
@@ -16,8 +16,10 @@ import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
+import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;
 import eu.etaxonomy.taxeditor.UiUtil;
+import eu.etaxonomy.taxeditor.model.CdmUtil;
 
 /**
  * Calls <code>MultiPageTaxonEditor.doSave()</code> method for all
@@ -60,8 +62,16 @@ public class SaveAllAction implements IWorkbenchWindowActionDelegate {
                // Commit the transaction
                TaxEditorPlugin.getDefault().commitTransaction();       
        
+               // Force library objects to be associated with new transaction
+               CdmUtil.clearLibraryObjects();
+               
                // Start a new transaction
                TaxEditorPlugin.getDefault().startTransaction();
+               
+               // Put all open taxa in the new transaction
+               for (Object taxon : TaxEditorPlugin.getDefault().getObservableSessionTaxa()) {
+                       CdmUtil.getTaxonService().saveTaxon((Taxon) taxon);
+               }
        }
 
        /**
index fac051d9f612ee175de170fc78e41d0a825bec67..31941d33c71949e2392329e291d92da50652042b 100644 (file)
@@ -90,8 +90,8 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart {
                new SaveTaxonAction(taxon).run();\r
 //             CdmUtil.commitTransaction(tx);\r
                setDirty(false);\r
-               tx = CdmUtil.startTransaction();\r
-               CdmUtil.getTaxonService().saveTaxon(taxon);\r
+//             tx = CdmUtil.startTransaction();\r
+//             CdmUtil.getTaxonService().saveTaxon(taxon);\r
        }\r
 \r
        private void setDirty(boolean dirty) {\r
@@ -143,8 +143,8 @@ public class MultiPageTaxonEditor extends MultiPageEditorPart {
                        taxon = null;\r
                }\r
 \r
-               // Save taxon to put it into this transaction\r
-//             CdmUtil.getTaxonService().saveTaxon(taxon);\r
+               // Save taxon to put it into current transaction\r
+               CdmUtil.getTaxonService().saveTaxon(taxon);\r
                \r
                // Listen for name changes, \r
                //  change tab for this taxon editor accordingly\r
index f17a5a7e01c8ba84725b3ff8e2a6bcec9039376d..576d636ba846faffe16be504c264b2440b932539 100644 (file)
@@ -9,10 +9,16 @@
 \r
 package eu.etaxonomy.taxeditor.editor.name;\r
 \r
+import java.beans.PropertyChangeEvent;\r
+import java.beans.PropertyChangeListener;\r
+\r
 import org.apache.log4j.Logger;\r
 import org.eclipse.core.runtime.Assert;\r
 import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.text.TextViewer;\r
 import org.eclipse.jface.util.IPropertyChangeListener;\r
+import org.eclipse.swt.events.DisposeEvent;\r
+import org.eclipse.swt.events.DisposeListener;\r
 import org.eclipse.swt.events.FocusAdapter;\r
 import org.eclipse.swt.events.FocusEvent;\r
 import org.eclipse.swt.graphics.Font;\r
@@ -23,6 +29,7 @@ import org.eclipse.ui.forms.IManagedForm;
 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;\r
 import eu.etaxonomy.cdm.model.taxon.Synonym;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
@@ -123,7 +130,8 @@ public class NameComposite extends EditorGroupedComposite {
 \r
        private static final String EMPTY_NAME_PROMPT = "Click to add name";\r
 \r
-       private NameViewer nameViewer;\r
+//     private NameViewer nameViewer;\r
+//     private NameViewer textViewer;\r
 \r
        /**\r
         * Used to turn parser on and off.\r
@@ -133,6 +141,10 @@ public class NameComposite extends EditorGroupedComposite {
         */\r
        private boolean isUseParser = false;\r
 \r
+       protected boolean isParsing;\r
+\r
+       private NameViewer nameViewer;\r
+\r
        /**\r
         * The constructor for a DescriptionElementComposite. Takes a parent Composite on which to\r
         * create itself, and an IManagedForm for Composite life cycle methods, i.e.\r
@@ -148,17 +160,64 @@ public class NameComposite extends EditorGroupedComposite {
                createNameViewer();\r
                createBorderSupport();\r
                createLineWrapSupport();\r
-\r
+               \r
                setData(data);\r
+               \r
+               createNameListener(data);\r
+               \r
                transform(compositeType);\r
                \r
                createEmptyViewerPrompt(EMPTY_NAME_PROMPT);\r
-               \r
                createParser();\r
                \r
                setFocus();\r
        }\r
 \r
+       /**\r
+        * Listens for changes to this name's <code>fullTitleCache</code>.\r
+        * \r
+        * @param data\r
+        */\r
+       private void createNameListener(TaxonBase taxonBase) {\r
+               if (taxonBase.getName() == null) {\r
+                       return;\r
+               }\r
+               \r
+               final TaxonNameBase name = taxonBase.getName();\r
+               \r
+               final PropertyChangeListener listener = new PropertyChangeListener() {\r
+                       @Override\r
+                       public void propertyChange(PropertyChangeEvent evt) {\r
+                               \r
+                               if (isParsing) {\r
+                                       return;\r
+                               }\r
+                               \r
+                               deactivateParser();\r
+                               ((NameViewer) getTextViewer()).setText(name.getFullTitleCache());\r
+                               activateParser();\r
+                       }\r
+               };\r
+               \r
+               name.addPropertyChangeListener("fullTitleCache", listener);\r
+               name.addPropertyChangeListener("nomenclaturalMicroReference", listener);\r
+\r
+               name.addPropertyChangeListener(ITaxEditorConstants.REFRESH_NAMEVIEWER, listener);\r
+               \r
+               StrictReferenceBase reference = (StrictReferenceBase) name.getNomenclaturalReference();\r
+               if (reference != null) {\r
+                       reference.addPropertyChangeListener("titleCache", listener);\r
+               }\r
+               \r
+               this.addDisposeListener(new DisposeListener() {\r
+\r
+                       @Override\r
+                       public void widgetDisposed(DisposeEvent e) {\r
+//                             name.removePropertyChangeListener(listener);\r
+                       }\r
+               });\r
+       }\r
+\r
        /**\r
         * All cosmetic - non-data-related, i.e. icons, fonts, etc. -\r
         * transformations take place in this method.\r
@@ -174,7 +233,7 @@ public class NameComposite extends EditorGroupedComposite {
                                setIcon(HETEROTYPIC_SYNONYM_ORIGINAL_COMBINATION_ICON);\r
                        }\r
                }\r
-\r
+               \r
                if (transformation.equals(REMOVE_GROUP_BASIONYM)) {\r
                        if (compositeType.equals(HOMOTYPIC_SYNONYM)) {\r
                                setIcon(HOMOTYPIC_SYNONYM_ICON);\r
@@ -285,11 +344,13 @@ public class NameComposite extends EditorGroupedComposite {
        }\r
 \r
        private void createParser() {\r
-               nameViewer.setParseListener(new ParseListener() {\r
+               ((NameViewer) getTextViewer()).setParseListener(new ParseListener() {\r
 \r
                        @Override\r
                        public void parse(String text) {\r
 \r
+                               isParsing = true;\r
+                               \r
                                if (!isUseParser) {\r
                                        return;\r
                                }\r
@@ -299,10 +360,12 @@ public class NameComposite extends EditorGroupedComposite {
                                \r
                                if (nonViralName != null) {\r
                                        CdmUtil.parseFullReference(nonViralName, text, null, true);\r
-                                       nameViewer.setShowError(nonViralName.getHasProblem());\r
+                                       ((NameViewer) getTextViewer()).setShowError(nonViralName.getHasProblem());\r
                                }\r
 \r
                                setDirty(true);\r
+                               \r
+                               isParsing = false;\r
                        }\r
                });\r
                activateParser();\r
@@ -317,8 +380,11 @@ public class NameComposite extends EditorGroupedComposite {
        }\r
        \r
        private NameViewer createNameViewer() {\r
-               nameViewer = new NameViewer(this);\r
-               nameViewer.setLineBreakListener(new LineBreakListener() {\r
+//             nameViewer = new NameViewer(this);\r
+//             nameViewer.setLineBreakListener(new LineBreakListener() {\r
+               \r
+               setTextViewer(new NameViewer(this));\r
+               getTextViewer().setLineBreakListener(new LineBreakListener() {\r
 \r
                        @Override\r
                        public void handleSplitText(String text) {\r
@@ -334,20 +400,22 @@ public class NameComposite extends EditorGroupedComposite {
 \r
                });\r
 \r
-               nameViewer.getTextWidget().addFocusListener(new FocusAdapter() {\r
+//             nameViewer.getTextWidget().addFocusListener(new FocusAdapter() {\r
+               getTextViewer().getTextWidget().addFocusListener(new FocusAdapter() {\r
                        public void focusGained(FocusEvent e) {\r
                                setFocus();\r
                        }\r
                });\r
 \r
                // createLineWrapSupport(nameViewer);\r
-\r
-               this.textViewer = nameViewer;\r
-\r
-               nameViewer.getTextWidget().setBackground(TaxEditorPlugin.getDefault().\r
-                               getColor(ITaxEditorConstants.GROUP_GRAY_BKG_COLOR));\r
+//\r
+//             this.textViewer = nameViewer;\r
+//             nameViewer.getTextWidget().setBackground(TaxEditorPlugin.getDefault().\r
+//                             getColor(ITaxEditorConstants.GROUP_GRAY_BKG_COLOR));\r
+               getTextViewer().getTextWidget().setBackground(TaxEditorPlugin.getDefault().\r
+                               getColor(ITaxEditorConstants.GROUP_GRAY_BKG_COLOR));            \r
                \r
-               return nameViewer;\r
+               return (NameViewer) getTextViewer();\r
        }\r
 \r
        /**\r
@@ -463,5 +531,21 @@ public class NameComposite extends EditorGroupedComposite {
 \r
                }\r
                return false;\r
-       }       \r
+       }\r
+       \r
+       public void setText(String text) {\r
+               Assert.isNotNull(getTextViewer(), \r
+                               "Cannot set text for a TextViewer that has not yet been initialized.");\r
+               Assert.isNotNull(getTextViewer().getDocument(), \r
+                               "Cannot set text for a TextViewer whose Document has not yet been initialized.");\r
+               getTextViewer().getDocument().set(text);\r
+       }\r
+       \r
+       public NameViewer getTextViewer() {\r
+               return this.nameViewer;\r
+       }\r
+       \r
+       public void setTextViewer(NameViewer textViewer) {\r
+               this.nameViewer = textViewer;\r
+       }\r
 }
\ No newline at end of file
index bef44435f6cacb4c9b816abae2c56cfd4bba6946..7ac28eaf32ae2ade22affb752c5a6df01206fefd 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Iterator;
 \r
 import org.apache.log4j.Logger;\r
 import org.eclipse.core.commands.operations.IUndoContext;\r
+import org.eclipse.core.runtime.Assert;\r
 import org.eclipse.jface.text.Document;\r
 import org.eclipse.jface.text.ILineTracker;\r
 import org.eclipse.jface.text.IUndoManager;\r
@@ -130,7 +131,18 @@ public class NameViewer extends SourceViewer {
                if (text == null) {\r
                        text = "";\r
                }\r
-               this.getTextWidget().setText(text);\r
+               try {\r
+                       Assert.isNotNull(text);\r
+                       // TODO figure out why getTextWidget() returns null!\r
+                       if (this.getTextWidget() == null) {\r
+                               return;\r
+                       }\r
+                       Assert.isNotNull(this.getTextWidget());\r
+                       this.getTextWidget().setText(text);\r
+               } catch (RuntimeException e) {\r
+                       // TODO Auto-generated catch block\r
+                       e.printStackTrace();\r
+               }\r
        }\r
 \r
        public void setCursorToEOL() {\r
index 4d9bd1384599a1b69d1de45fe087ddd13060c6bd..fdf78fb7ab33a8b9ba14ea1c36b2afdc28370a54 100644 (file)
@@ -19,6 +19,7 @@ import org.springframework.transaction.TransactionStatus;
 import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
 import eu.etaxonomy.cdm.api.service.INameService;\r
 import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
@@ -29,7 +30,7 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
+import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.cdm.model.taxon.Synonym;\r
 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;\r
@@ -54,10 +55,20 @@ public class CdmUtil {
        private static final Logger logger = Logger.getLogger(CdmUtil.class);\r
 \r
        private static INonViralNameParser nonViralNameParser;\r
-       \r
        private static TermVocabulary<Feature> features;\r
        private static SortedSet<Rank> ranks;\r
 \r
+       /**\r
+        * Clears all objects retrieved from <code>cdmlib</code> \r
+        * to force them to re-initialize the next time they\r
+        * are called.\r
+        */\r
+       public static void clearLibraryObjects() {\r
+               features = null;\r
+               ranks = null;\r
+               nonViralNameParser = null;\r
+       }\r
+       \r
        /**\r
         * Checks whether synonym's name is the basionym for ALL names \r
         *      in its group.\r
@@ -265,6 +276,11 @@ public class CdmUtil {
                \r
                TaxonNameBase name = getNonViralNameParser().parseFullReference(fullReference,\r
                                nomCode, rank);\r
+\r
+               if (name.hasProblem()) {\r
+                       name.setFullTitleCache(fullReference);\r
+               }\r
+               \r
                return name;\r
        }\r
 \r
@@ -279,6 +295,10 @@ public class CdmUtil {
         */\r
        public static void parseFullReference(NonViralName nameToBeFilled, String fullReference, Rank rank, boolean makeEmpty) {\r
                getNonViralNameParser().parseFullReference(nameToBeFilled, fullReference, rank, makeEmpty);\r
+               \r
+               if (nameToBeFilled.hasProblem()) {\r
+                       nameToBeFilled.setFullTitleCache(fullReference);\r
+               }\r
        }\r
        \r
        /**\r
@@ -382,4 +402,13 @@ public class CdmUtil {
        public static void commitTransaction(TransactionStatus tx) {\r
                TaxEditorPlugin.getDefault().getCdmApp().commitTransaction(tx);\r
        }\r
+       \r
+       public static void getNomenclaturalReference(TaxonNameBase name) {\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
 }\r
index 2e0e945223b80f0304aa14ffaf2f67c66ccc175d..f73b52d161902fbbcc631734cd6e45683c72c230 100644 (file)
@@ -37,6 +37,10 @@ public class CustomSortPropertySheetEntry extends PropertySheetEntry {
         return new CustomSortPropertySheetEntry();\r
     }\r
            \r
+       public CustomSortPropertySheetEntry() {\r
+               super();\r
+       }\r
+       \r
     /* (non-Javadoc)\r
      * @see org.eclipse.ui.views.properties.PropertySheetEntry#getDisplayName()\r
      */\r
index 9669623726cb16be62d1393bf7a4ce53fc1a6a28..41a96a356ead8130eee1ea4f564a7a8cc7dfea32 100644 (file)
@@ -27,6 +27,7 @@ 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.ReferenceBase;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -52,6 +53,7 @@ public class DescriptionElementPropertySource implements IPropertySource {
         */\r
        public static final String P_ID_ELEMENT_CLASS = "element_class";\r
        public static final String P_ID_FEATURE = "feature";\r
+       public static final String P_ID_BIBREF = "nomref";\r
 \r
        /**\r
         * Property display keys\r
@@ -60,6 +62,7 @@ public class DescriptionElementPropertySource implements IPropertySource {
         */\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_BIBREF = "02:Bibliographic Reference";\r
        \r
        protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_ELEMENT_CLASS, P_ID_FEATURE};         \r
        \r
@@ -139,6 +142,10 @@ public class DescriptionElementPropertySource implements IPropertySource {
                if (id.equals(P_ID_FEATURE)) {\r
                        descriptors.addElement(new PropertyDescriptor(P_ID_FEATURE, P_FEATURE));\r
                }\r
+               \r
+               if (id.equals(P_ID_BIBREF)) {\r
+                       descriptors.addElement(new PropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
+               }\r
        }\r
        \r
        /* (non-Javadoc)\r
@@ -183,6 +190,15 @@ public class DescriptionElementPropertySource implements IPropertySource {
                                return "";\r
                        }\r
                }\r
+\r
+               if (id.equals(P_ID_BIBREF)) {\r
+                       ReferenceBase citation = descriptionElement.getCitation();\r
+                       if (citation == null) {\r
+                               return "";\r
+                       } else {\r
+                               return citation.getTitleCache();\r
+                       }\r
+               }               \r
                \r
                return null;\r
        }\r
index 5a76c75255b7fc325f7c49695c0a7deb7a0ca990..21099f197776b5a7a3290f7f8981663bd6b27ff9 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.propertysheet.name;
 import org.apache.log4j.Logger;\r
 import org.eclipse.ui.views.properties.TextPropertyDescriptor;\r
 \r
+import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.model.name.BotanicalName;\r
 \r
 /**\r
@@ -49,7 +50,7 @@ public class BotanicalNamePropertySource extends NonViralNamePropertySource {
                return "ICBN";\r
         }\r
         if (id.equals(P_ID_REFERENCEYEAR)) {\r
-               return subEmptyForNull(name.getReferenceYear());\r
+               return CdmUtils.Nz(name.getReferenceYear());\r
         }\r
                return super.getPropertyValue(id);\r
        }\r
index 27821be9fda55e367f0dd11d19c11ed9b2e6ed2d..a87fc56e1a09b858672b0b118269f8412ee9ecaf 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.propertysheet.name;
 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
@@ -24,12 +25,19 @@ import org.eclipse.ui.views.properties.IPropertySource;
 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.common.Annotation;\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.taxeditor.ITaxEditorConstants;\r
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
@@ -79,6 +87,9 @@ public class NonViralNamePropertySource implements IPropertySource {
        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
@@ -104,7 +115,10 @@ 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:Nomenclatural Micro 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
        \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
@@ -137,6 +151,7 @@ public class NonViralNamePropertySource implements IPropertySource {
        }\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
@@ -288,12 +303,26 @@ public class NonViralNamePropertySource implements IPropertySource {
                }\r
                if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
                        descriptors.addElement(\r
-                                       new TextPropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));\r
+//                                     new TextPropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));\r
+                                       new PropertyDescriptor(P_ID_NOMENCLATURAL_REF, P_NOMENCLATURAL_REF));\r
                }\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
@@ -347,31 +376,31 @@ public class NonViralNamePropertySource implements IPropertySource {
                // If the name has not been parsed, only show the title cache\r
 //             if (name.getHasProblem()) {\r
                if (name.getRank() == null) {\r
-                       return subEmptyForNull(name.getTitleCache());\r
+                       return CdmUtils.Nz(name.getTitleCache());\r
                } else {\r
                        return new NonViralNamePropertySource(name, P_ID_TITLECACHE, getNameFields());\r
                }\r
         }\r
                if (id.equals(P_ID_UNINOMIAL)) {\r
-                       return subEmptyForNull(name.getGenusOrUninomial());\r
+                       return CdmUtils.Nz(name.getGenusOrUninomial());\r
                }\r
         if (id.equals(P_ID_INFRAGENERICEP)) {\r
-                       return subEmptyForNull(name.getInfraGenericEpithet());\r
+                       return CdmUtils.Nz(name.getInfraGenericEpithet());\r
         }\r
         if (id.equals(P_ID_SPECIESEP)) {\r
-                       return subEmptyForNull(name.getSpecificEpithet());\r
+                       return CdmUtils.Nz(name.getSpecificEpithet());\r
         }\r
         if (id.equals(P_ID_INFRASPECIFICEP)) {\r
-                       return subEmptyForNull(name.getInfraSpecificEpithet());\r
+                       return CdmUtils.Nz(name.getInfraSpecificEpithet());\r
         }\r
         if (id.equals(P_ID_APPENDEDPHRASE)) {\r
-               return subEmptyForNull(name.getAppendedPhrase());\r
+               return CdmUtils.Nz(name.getAppendedPhrase());\r
         }\r
         if (id.equals(P_ID_AUTHORSHIPCACHE)) {\r
-                       return subEmptyForNull(name.getAuthorshipCache());\r
+                       return CdmUtils.Nz(name.getAuthorshipCache());\r
         }\r
         if (id.equals(P_ID_HOMOTYPICALGROUP)) {\r
-                       return subEmptyForNull(name.getHomotypicalGroup().getUuid().toString());\r
+                       return CdmUtils.Nz(name.getHomotypicalGroup().getUuid().toString());\r
         }\r
         if (id.equals(P_ID_ANNOTATIONS)) {\r
                        return new AnnotationPropertySource(name.getAnnotations());\r
@@ -401,7 +430,7 @@ public class NonViralNamePropertySource implements IPropertySource {
                        return "";\r
         }\r
         if (id.equals(P_ID_UUID)) {\r
-                       return subEmptyForNull(name.getUuid().toString());\r
+                       return CdmUtils.Nz(name.getUuid().toString());\r
         }\r
         if (id.equals(P_ID_MARKERS)) {\r
                        return new MarkersPropertySource(name.getMarkers());\r
@@ -420,7 +449,7 @@ public class NonViralNamePropertySource implements IPropertySource {
                if (name.getCreatedBy() == null) {\r
                        return "";\r
                } else {\r
-                       return subEmptyForNull(name.getCreatedBy().generateTitle());\r
+                       return CdmUtils.Nz(name.getCreatedBy().generateTitle());\r
                }\r
         }\r
         if (id.equals(P_ID_NOMENCLATURAL_CODE)) {\r
@@ -428,17 +457,61 @@ public class NonViralNamePropertySource implements IPropertySource {
                return "none (nonviral name)";\r
         }\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
                INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-               if (nomenclaturalReference == null) {\r
+               if (name.getNomenclaturalReference() == null) {\r
                        return "";\r
+               } else {\r
+                       return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields());\r
                }\r
-//             getNomReference();\r
-//             getNom\r
-               String microReference = name.getNomenclaturalMicroReference();\r
-                       return subEmptyForNull(nomenclaturalReference.getNomenclaturalCitation(microReference));\r
         }\r
         if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
-                       return subEmptyForNull(name.getNomenclaturalMicroReference());\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
@@ -477,23 +550,41 @@ public class NonViralNamePropertySource implements IPropertySource {
        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
-       /**\r
-        * If the value of a TextPropertyDescriptor is initialized with NULL,\r
-        *  the user can't edit it; such values need to be set to "". \r
-        *  Hence this function.\r
-        *  \r
-        * @param string\r
-        * @return\r
-        */\r
-       protected String subEmptyForNull(String string) {\r
-               if (string == null)\r
-                       return "";\r
-               return string;\r
-       }\r
        \r
        @Override\r
        public boolean isPropertySet(Object id) {\r
@@ -510,11 +601,10 @@ public class NonViralNamePropertySource implements IPropertySource {
         */\r
        @Override\r
        public void setPropertyValue(Object id, Object value) {\r
-               \r
+                               \r
                // Since this is only called when the property value changes,\r
                //      it is a reliable place to fire the name's property change\r
                //      listener.\r
-//             name.firePropertyChange((String) id, null, value);\r
                name.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, null);\r
                \r
                if (id.equals(P_ID_RANK)) {\r
@@ -529,7 +619,6 @@ public class NonViralNamePropertySource implements IPropertySource {
         }\r
         if (id.equals(P_ID_SPECIESEP)) {\r
                        name.setSpecificEpithet((String) value);\r
-                       name.setAppendedPhrase("joemama");\r
         }\r
         if (id.equals(P_ID_INFRASPECIFICEP)) {\r
                        name.setInfraSpecificEpithet((String) value);\r
@@ -579,11 +668,96 @@ public class NonViralNamePropertySource implements IPropertySource {
                // TODO ask Andreas M. how best to set nom. ref\r
         }\r
         if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
-               // TODO decide if this is editable at all, and if so, how to implement\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
-        boolean test = false;\r
-        if (test) test = true;\r
+        if (id.equals(P_ID_NOMREF_TITLE)) {\r
+               INomenclaturalReference reference = name.getNomenclaturalReference();\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
+        }\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("fullTitleCache", null, name.getFullTitleCache());\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
+               \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
@@ -593,9 +767,17 @@ public class NonViralNamePropertySource implements IPropertySource {
         */\r
        @Override\r
        public String toString() {\r
-               if (parentid.equals(P_ID_TITLECACHE))\r
+               if (parentid.equals(P_ID_TITLECACHE)) {\r
                        return name.getTitleCache(); \r
-//                     return name.getFullTitleCache();\r
+               }\r
+               if (parentid.equals(P_ID_NOMENCLATURAL_REF)) {\r
+               INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference();\r
+               if (nomenclaturalReference == null) {\r
+                       return "";\r
+               }               \r
+               String microReference = name.getNomenclaturalMicroReference();\r
+                       return CdmUtils.Nz(nomenclaturalReference.getNomenclaturalCitation(microReference));\r
+               }\r
                return super.toString();\r
        }\r
        \r
index 2a886f911ab736171832028858db1643fb40183c..e5844532c212853fb133137897723c866855bea6 100644 (file)
@@ -120,6 +120,7 @@ public class ListNameRelationsWizardPage extends WizardPage {
                                true, 3, 1));\r
                nameRelationsTable.addSelectionListener(new SelectionAdapter() {\r
                        public void widgetSelected(SelectionEvent e) {\r
+                               // TODO: As long as onNameBase.removeNameRelationship() doesn't work, "Remove" stays disabled ... \r
                                setEnableExistingRelationButtons(true);\r
                                TableItem[] selectedItem = nameRelationsTable.getSelection();\r
                                if (e.item.getData() instanceof NameRelationship) {\r