Created BibRefPropertySource, first implementation in DescriptionElementPropertySourc...
authorp.ciardelli <p.ciardelli@localhost>
Tue, 4 Nov 2008 15:40:04 +0000 (15:40 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Tue, 4 Nov 2008 15:40:04 +0000 (15:40 +0000)
.gitattributes
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/CustomSortPropertySheetEntry.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/PropertySourceAdapter.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/bibref/BibRefPropertySource.java [new file with mode: 0644]
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/description/DescriptionElementPropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java

index 83df1e8057db257b1cb73fdaf9cf007436ffeff7..e295d6f699b27afb96b70ca6850e00a2632e10c6 100644 (file)
@@ -519,6 +519,7 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/PropertySheetValueLabelProvider.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/PropertySourceAdapter.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/SourceViewerConfig.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/bibref/BibRefPropertySource.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/description/DescriptionElementPropertySource.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/description/TaxonDescriptionPropertySource.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/BotanicalNamePropertySource.java -text
index f73b52d161902fbbcc631734cd6e45683c72c230..a9bff36ffe61ac86c93828956a0d39ed28fe527c 100644 (file)
@@ -16,8 +16,8 @@ import org.eclipse.ui.views.properties.PropertySheetEntry;
  * <p>\r
  * GetDisplayName is called by two methods from the PropertySheetViewer, which\r
  * <ul>\r
- *    <li>a) we are not allowed to set, and</li>\r
- *    <li>b) uses a comparator which sorts alphabetically.</li>\r
+ *    <li>we are not allowed to set, and</li>\r
+ *    <li>uses a comparator which sorts alphabetically.</li>\r
  * </ul>\r
  * So we set display names in the PropertySourceDescriptors as "01:Uninomial",\r
  *  "02:Specific Epithet"; if we ascertain from the stack trace that a "compare"\r
@@ -49,10 +49,11 @@ public class CustomSortPropertySheetEntry extends PropertySheetEntry {
        String displayName = super.getDisplayName();\r
                \r
                Thread currentThread = Thread.currentThread();\r
-               StackTraceElement stackRequestingName = currentThread.getStackTrace()[2];\r
+               \r
                // currentThread.getStackTrace()[0] = call to getStackTrace\r
                // currentThread.getStackTrace()[1] = getDisplayName\r
                // currentThread.getStackTrace()[2] = who is calling getDisplayName\r
+               StackTraceElement stackRequestingName = currentThread.getStackTrace()[2];\r
 \r
                if (stackRequestingName.toString().lastIndexOf("compare") != -1) {\r
                        return displayName;\r
index c57f136d700eec732429e9d35bbc94238576e508..f5c3f4d996e71a1a88ce6ab722fdd71f00fffccf 100644 (file)
@@ -14,7 +14,6 @@ import org.eclipse.ui.views.properties.IPropertySource;
 \r
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
 import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
-import eu.etaxonomy.cdm.model.description.TextData;\r
 import eu.etaxonomy.cdm.model.name.BotanicalName;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
 import eu.etaxonomy.cdm.model.name.ZoologicalName;\r
@@ -36,7 +35,6 @@ public class PropertySourceAdapter {
                        .getLogger(PropertySourceAdapter.class);\r
        \r
        private Object propertyObject;\r
-//     private Object property;\r
 \r
        public PropertySourceAdapter(Object propertyObject) {\r
                this.propertyObject = propertyObject;\r
@@ -49,10 +47,8 @@ public class PropertySourceAdapter {
                // Property source for Description-related classes\r
                if (clazz == TaxonDescription.class) {\r
                        return new TaxonDescriptionPropertySource((TaxonDescription) propertyObject);\r
-               }               \r
-//             if ((clazz == DescriptionElementBase.class) || (clazz == TextData.class)) {\r
-//                     return new DescriptionElementPropertySource((DescriptionElementBase) propertyObject);\r
-//             }\r
+               }\r
+               \r
                if (propertyObject instanceof DescriptionElementBase) {\r
                        return new DescriptionElementPropertySource((DescriptionElementBase) propertyObject);\r
                }               \r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/bibref/BibRefPropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/bibref/BibRefPropertySource.java
new file mode 100644 (file)
index 0000000..cc585d0
--- /dev/null
@@ -0,0 +1,615 @@
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy \r
+* http://www.e-taxonomy.eu\r
+* \r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+\r
+package eu.etaxonomy.taxeditor.propertysheet.bibref;\r
+\r
+import java.beans.PropertyChangeEvent;\r
+import java.beans.PropertyChangeListener;\r
+import java.beans.PropertyChangeSupport;\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
+import org.apache.log4j.Logger;\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
+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.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.CdDvd;\r
+import eu.etaxonomy.cdm.model.reference.Database;\r
+import eu.etaxonomy.cdm.model.reference.Generic;\r
+import eu.etaxonomy.cdm.model.reference.InProceedings;\r
+import eu.etaxonomy.cdm.model.reference.Journal;\r
+import eu.etaxonomy.cdm.model.reference.Map;\r
+import eu.etaxonomy.cdm.model.reference.Patent;\r
+import eu.etaxonomy.cdm.model.reference.PersonalCommunication;\r
+import eu.etaxonomy.cdm.model.reference.PrintSeries;\r
+import eu.etaxonomy.cdm.model.reference.PrintedUnitBase;\r
+import eu.etaxonomy.cdm.model.reference.Proceedings;\r
+import eu.etaxonomy.cdm.model.reference.PublicationBase;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
+import eu.etaxonomy.cdm.model.reference.Report;\r
+import eu.etaxonomy.cdm.model.reference.SectionBase;\r
+import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;\r
+import eu.etaxonomy.cdm.model.reference.Thesis;\r
+import eu.etaxonomy.cdm.model.reference.WebPage;\r
+import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
+\r
+/**\r
+ * Supplies the properties of a <code>ReferenceBase</code> object for display by\r
+ * a <code>PropertySheet</code>.\r
+ * <p>\r
+ * Includes a drop-down menu that allows the user to change <code>ReferenceBase</code> \r
+ * subclasses. This causes all fields except <code>TitleCache</code> to be wiped clean.\r
+ * <p>\r
+ * Normally, this would be called from another <code>IPropertySource</code>  \r
+ * as follows:\r
+ * <pre>\r
+ * public Object getPropertyValue(Object id) {\r
+ * \r
+ *             ...\r
+ * \r
+ *             if (id.equals(P_ID_BIBREF)) {\r
+ *                     ReferenceBase citation = descriptionElement.getCitation();\r
+ *                     BibRefPropertySource bibRefPropertySource = new BibRefPropertySource(citation);\r
+ *                     bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+ *                             @Override\r
+ *                             public void propertyChange(PropertyChangeEvent evt) {\r
+ *                                     descriptionElement.setCitation((ReferenceBase) evt.getNewValue());\r
+ *                             }\r
+ *                     });\r
+ *                     return bibRefPropertySource;\r
+ *             }               \r
+ * </pre>\r
+ * <p>\r
+ * Note: if <code>P_ID_BIBREF</code> in the above example is associated with an editable \r
+ * <code>TextPropertyDescriptor</code>, it will initalize its cell editor by calling \r
+ * <code>getEditableValue()</code>. If associated with a non-editable <code>PropertyDescriptor</code>, \r
+ * it will get its value from <code>getString()</code>.\r
+ * @author p.ciardelli\r
+ * @created 03.11.2008\r
+ * @version 1.0\r
+ */\r
+public class BibRefPropertySource implements IPropertySource {\r
+       private static final Logger logger = Logger\r
+                       .getLogger(BibRefPropertySource.class);\r
+\r
+       ReferenceBase reference;\r
+       \r
+    // Property unique keys\r
+       public static final String P_ID_REFERENCETYPE = "P_ID_REFERENCETYPE";\r
+       public static final String P_ID_AUTHORTEAM = "P_ID_AUTHORTEAM";\r
+       public static final String P_ID_YEAR = "P_ID_YEAR";\r
+       public static final String P_ID_CITATION = "P_ID_CITATION";\r
+       public static final String P_ID_URI = "P_ID_URI";\r
+       public static final String P_ID_DATEPUBLISHED = "P_ID_DATEPUBLISHED";\r
+       public static final String P_ID_TITLE = "P_ID_TITLE";\r
+       public static final String P_ID_INJOURNAL = "P_ID_INJOURNAL";\r
+       public static final String P_ID_NOMENCLATURAL_CITATION = "P_ID_NOMENCLATURAL_CITATION";\r
+       public static final String P_ID_PAGES = "P_ID_PAGES";\r
+       public static final String P_ID_SERIES = "P_ID_SERIES";\r
+       public static final String P_ID_VOLUME = "P_ID_VOLUME";\r
+       public static final String P_ID_EDITOR = "P_ID_EDITOR";\r
+       public static final String P_ID_PLACEPUBLISHED = "P_ID_PLACEPUBLISHED";\r
+       public static final String P_ID_PUBLISHER = "P_ID_PUBLISHER";\r
+       public static final String P_ID_ISSN = "P_ID_ISSN";\r
+       public static final String P_ID_INSTITUTION = "P_ID_INSTITUTION";\r
+       public static final String P_ID_SCHOOL = "P_ID_SCHOOL";\r
+       public static final String P_ID_INSERIES = "P_ID_INSERIES";\r
+       public static final String P_ID_SERIESPART = "P_ID_SERIESPART";\r
+       public static final String P_ID_ISBN = "P_ID_ISBN";\r
+       public static final String P_ID_ORGANIZATION = "P_ID_ORGANIZATION";\r
+       public static final String P_ID_PRINTEDUNIT = "P_ID_PRINTEDUNIT";\r
+       public static final String P_ID_INBOOK = "P_ID_INBOOK";\r
+       public static final String P_ID_INPROCEEDINGS = "P_ID_INPROCEEDINGS";\r
+       public static final String P_ID_BIBTEX_ENTRYTYPE = "P_ID_BIBTEX_ENTRYTYPE";\r
+       public static final String P_ID_JOURNAL = "P_ID_JOURNAL";\r
+       public static final String P_ID_BOOKTITLE = "P_ID_BOOKTITLE";\r
+       public static final String P_ID_CHAPTER = "P_ID_CHAPTER";\r
+       public static final String P_ID_EDITION = "P_ID_EDITION";\r
+       public static final String P_ID_NUMBER = "P_ID_NUMBER";\r
+       public static final String P_ID_ANNOTE = "P_ID_ANNOTE";\r
+       public static final String P_ID_ADDRESS = "P_ID_ADDRESS";\r
+       public static final String P_ID_HOWPUBLISHED = "P_ID_HOWPUBLISHED";\r
+       public static final String P_ID_REPORTTYPE = "P_ID_REPORTTYPE";\r
+       public static final String P_ID_MONTH = "P_ID_MONTH";\r
+       public static final String P_ID_EPRINT = "P_ID_EPRINT";\r
+       public static final String P_ID_NOTE = "P_ID_NOTE";\r
+       public static final String P_ID_CROSSREF = "P_ID_CROSSREF";\r
+       public static final String P_ID_NOMREFBASE = "P_ID_NOMREFBASE"; \r
+       \r
+    // Property display keys\r
+       public static final String P_REFERENCETYPE = "00:Reference Type";\r
+       public static final String P_AUTHORTEAM = "01:Author Team";\r
+       public static final String P_YEAR = "02:Year";\r
+       public static final String P_CITATION = "03:Citation";\r
+       public static final String P_URI = "04:URI";\r
+       public static final String P_DATEPUBLISHED = "05:Date Published";\r
+       public static final String P_TITLE = "06:Title";\r
+       public static final String P_INJOURNAL = "07:In Journal";\r
+       public static final String P_NOMENCLATURAL_CITATION = "08:Nomenclatural Citation";\r
+       public static final String P_PAGES = "09:Pages";\r
+       public static final String P_SERIES = "10:Series";\r
+       public static final String P_VOLUME = "11:Volume";\r
+       public static final String P_EDITOR = "12:Editor";\r
+       public static final String P_PLACEPUBLISHED = "13:Place Published";\r
+       public static final String P_PUBLISHER = "14:Publisher";\r
+       public static final String P_ISSN = "15:ISSN";\r
+       public static final String P_INSTITUTION = "16:Institution";\r
+       public static final String P_SCHOOL = "17:School";\r
+       public static final String P_INSERIES = "18:In Series";\r
+       public static final String P_SERIESPART = "19:Series Part";\r
+       public static final String P_ISBN = "20:ISBN";\r
+       public static final String P_ORGANIZATION = "21:Organization";\r
+       public static final String P_PRINTEDUNIT = "22:Printed Unit";\r
+       public static final String P_INBOOK = "23:In Book";\r
+       public static final String P_INPROCEEDINGS = "24:In Proceedings";\r
+       public static final String P_BIBTEX_ENTRYTYPE = "25:BibTeX Entry Type";\r
+       public static final String P_JOURNAL = "26:Journal";\r
+       public static final String P_BOOKTITLE = "27:Book Title";\r
+       public static final String P_CHAPTER = "28:Chapter";\r
+       public static final String P_EDITION = "29:Edition";\r
+       public static final String P_NUMBER = "30:Number";\r
+       public static final String P_ANNOTE = "31:Annote";\r
+       public static final String P_ADDRESS = "32:Address";\r
+       public static final String P_HOWPUBLISHED = "33:How Published";\r
+       public static final String P_REPORTTYPE = "34:Report Type";\r
+       public static final String P_MONTH = "35:Month";\r
+       public static final String P_EPRINT = "36:E-Print";\r
+       public static final String P_NOTE = "37:Note";\r
+       public static final String P_CROSSREF = "38:BibTeX Crossref";\r
+       public static final String P_NOMREFBASE = "39:Nomenclatural Citation";          \r
+       \r
+               \r
+       private static HashMap<Class, String> referenceTypeMap = null;\r
+       \r
+       private void populateReferenceTypes() {\r
+               \r
+               // LinkedHashMap maintains insertion order\r
+               referenceTypeMap = new LinkedHashMap<Class, String>();\r
+               \r
+               referenceTypeMap.put(ReferenceBase.class, "");\r
+               referenceTypeMap.put(BibtexReference.class, "BibTeX Reference");\r
+               referenceTypeMap.put(Article.class, "Article");\r
+               referenceTypeMap.put(Generic.class, "Generic");\r
+               referenceTypeMap.put(Patent.class, "Patent");\r
+               referenceTypeMap.put(PersonalCommunication.class, "Personal Communication");\r
+               referenceTypeMap.put(CdDvd.class, "CD / DVD");\r
+               referenceTypeMap.put(Database.class, "Database");\r
+               referenceTypeMap.put(Journal.class, "Journal");\r
+               referenceTypeMap.put(Map.class, "Map");\r
+               referenceTypeMap.put(Book.class, "Book");\r
+               referenceTypeMap.put(Proceedings.class, "Proceedings");\r
+               referenceTypeMap.put(PrintSeries.class, "Print Series");\r
+               referenceTypeMap.put(Report.class, "Report");\r
+               referenceTypeMap.put(Thesis.class, "Thesis");\r
+               referenceTypeMap.put(WebPage.class, "Web Page");\r
+               referenceTypeMap.put(BookSection.class, "Book Section");\r
+               referenceTypeMap.put(InProceedings.class, "In Proceedings");\r
+       }\r
+               \r
+       public BibRefPropertySource(ReferenceBase reference) {\r
+               super();\r
+               \r
+               // Default type of ReferenceBase is Generic\r
+               if (reference == null) {\r
+                       reference = Generic.NewInstance();\r
+               }\r
+               \r
+               this.reference = reference;\r
+\r
+               List<String> displayFields = new ArrayList<String>();\r
+               \r
+               // Drop-down menu to change reference type\r
+               displayFields.add(P_ID_REFERENCETYPE);\r
+               \r
+               // ReferenceBase fields\r
+               displayFields.add(P_ID_AUTHORTEAM);\r
+               displayFields.add(P_ID_YEAR);\r
+               displayFields.add(P_ID_CITATION);\r
+               displayFields.add(P_ID_URI);\r
+               \r
+               Class referenceClass = reference.getClass();\r
+               \r
+               if (reference instanceof BibtexReference) {\r
+                                               \r
+                       displayFields.add(P_ID_BIBTEX_ENTRYTYPE);\r
+                       displayFields.add(P_ID_JOURNAL);\r
+                       displayFields.add(P_ID_BOOKTITLE);\r
+                       displayFields.add(P_ID_CHAPTER);\r
+                       displayFields.add(P_ID_TITLE);\r
+                       displayFields.add(P_ID_SERIES);\r
+                       displayFields.add(P_ID_EDITION);\r
+                       displayFields.add(P_ID_VOLUME);\r
+                       displayFields.add(P_ID_NUMBER);\r
+                       displayFields.add(P_ID_PAGES);\r
+                       displayFields.add(P_ID_ANNOTE);\r
+                       displayFields.add(P_ID_EDITOR);\r
+                       displayFields.add(P_ID_INSTITUTION);\r
+                       displayFields.add(P_ID_SCHOOL);\r
+                       displayFields.add(P_ID_ORGANIZATION);\r
+                       displayFields.add(P_ID_PUBLISHER);\r
+                       displayFields.add(P_ID_ADDRESS);\r
+                       displayFields.add(P_ID_HOWPUBLISHED);\r
+                       displayFields.add(P_ID_REPORTTYPE);\r
+                       displayFields.add(P_ID_MONTH);\r
+                       displayFields.add(P_ID_EPRINT);\r
+                       displayFields.add(P_ID_NOTE);\r
+                       displayFields.add(P_ID_CROSSREF);\r
+                       displayFields.add(P_ID_NOMREFBASE);\r
+               }\r
+\r
+               if (reference instanceof StrictReferenceBase) {\r
+                       \r
+                       displayFields.add(P_ID_DATEPUBLISHED);\r
+                       displayFields.add(P_ID_TITLE);\r
+\r
+                       if (referenceClass == Article.class) {\r
+                               displayFields.add(P_ID_INJOURNAL);\r
+                               displayFields.add(P_ID_NOMENCLATURAL_CITATION);\r
+                               displayFields.add(P_ID_PAGES);\r
+                               displayFields.add(P_ID_SERIES);\r
+                               displayFields.add(P_ID_VOLUME);\r
+                       }\r
+\r
+                       if (referenceClass == Generic.class) {\r
+                               displayFields.add(P_ID_INJOURNAL);\r
+                               displayFields.add(P_ID_NOMENCLATURAL_CITATION);\r
+                               displayFields.add(P_ID_PAGES);\r
+                               displayFields.add(P_ID_SERIES);\r
+                               displayFields.add(P_ID_VOLUME);\r
+                               displayFields.add(P_ID_EDITOR);\r
+                               displayFields.add(P_ID_PLACEPUBLISHED);\r
+                               displayFields.add(P_ID_PUBLISHER);\r
+                       }                       \r
+                       \r
+                       if (referenceClass == Patent.class) {\r
+                               // No additional fields\r
+                       }\r
+                       \r
+                       if (referenceClass == PersonalCommunication.class) {\r
+                               // No additional fields                         \r
+                       }\r
+                       if (reference instanceof PublicationBase) {\r
+\r
+                               displayFields.add(P_ID_PLACEPUBLISHED);\r
+                               displayFields.add(P_ID_PUBLISHER);\r
+                               \r
+                               if (referenceClass == CdDvd.class) {\r
+                                       // No additional fields                                                 \r
+                               }\r
+                               \r
+                               if (referenceClass == Database.class) {\r
+                                       // No additional fields                                 \r
+                               }\r
+                               \r
+                               if (referenceClass == Journal.class) {  \r
+                                       displayFields.add(P_ID_ISSN);\r
+                               }\r
+\r
+                               if (referenceClass == Map.class) {\r
+                                       // No additional fields                                 \r
+                               }                               \r
+                               \r
+                               if (referenceClass == PrintSeries.class) {\r
+                                       displayFields.add(P_ID_SERIES);                                 \r
+                               }\r
+                               \r
+                               if (referenceClass == Report.class) {\r
+                                       displayFields.add(P_ID_INSTITUTION);                                    \r
+                               }\r
+                               \r
+                               if (referenceClass == Thesis.class) {\r
+                                       displayFields.add(P_ID_SCHOOL);                                         \r
+                               }\r
+                               \r
+                               if (referenceClass == WebPage.class) {\r
+                                       // No additional fields         \r
+                               }\r
+                               \r
+                               if (reference instanceof PrintedUnitBase) {\r
+                                       \r
+                                       displayFields.add(P_ID_EDITOR);\r
+                                       displayFields.add(P_ID_INSERIES);\r
+                                       displayFields.add(P_ID_PAGES);\r
+                                       displayFields.add(P_ID_SERIESPART);\r
+                                       displayFields.add(P_ID_VOLUME);\r
+                                       \r
+                                       if (referenceClass == Book.class) {\r
+                                               displayFields.add(P_ID_ISBN);                                           \r
+                                       }\r
+                                       \r
+                                       if (referenceClass == Proceedings.class) {\r
+                                               displayFields.add(P_ID_ORGANIZATION);                                                   \r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       if (reference instanceof SectionBase) {\r
+                               \r
+                               displayFields.add(P_ID_PAGES);  \r
+                               displayFields.add(P_ID_PRINTEDUNIT);\r
+                               \r
+                               if (referenceClass == BookSection.class) {\r
+                                       displayFields.add(P_ID_INBOOK);\r
+                                       displayFields.add(P_ID_NOMENCLATURAL_CITATION);\r
+                               }\r
+                               \r
+                               if (referenceClass == InProceedings.class) {\r
+                                       displayFields.add(P_ID_INPROCEEDINGS);                                  \r
+                               }\r
+                       }\r
+               }\r
+               \r
+               for (String field : displayFields) {\r
+                       addDescriptor(field);\r
+               }\r
+       }\r
+\r
+       protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();\r
+       \r
+       protected void addDescriptor(String id) {\r
+               if (id.equals(P_ID_REFERENCETYPE)) {\r
+                       if (referenceTypeMap == null) {\r
+                               populateReferenceTypes();\r
+                       }\r
+                       String[] P_REFERENCETYPE_MENU = referenceTypeMap.values().toArray(new String[] {});\r
+                       descriptors.addElement(\r
+                                       new ComboBoxPropertyDescriptor(P_ID_REFERENCETYPE, P_REFERENCETYPE, P_REFERENCETYPE_MENU));\r
+               }\r
+               if (id.equals(P_ID_AUTHORTEAM)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_AUTHORTEAM, P_AUTHORTEAM));                     \r
+               }\r
+               if (id.equals(P_ID_YEAR)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_YEAR, P_YEAR));                 \r
+               }\r
+               if (id.equals(P_ID_CITATION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_CITATION, P_CITATION));                 \r
+               } \r
+               if (id.equals(P_ID_URI)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_URI, P_URI));                   \r
+               } \r
+               if (id.equals(P_ID_DATEPUBLISHED)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_DATEPUBLISHED, P_DATEPUBLISHED));                       \r
+               } \r
+               if (id.equals(P_ID_TITLE)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_TITLE, P_TITLE));                       \r
+               } \r
+               if (id.equals(P_ID_INJOURNAL)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INJOURNAL, P_INJOURNAL));                       \r
+               } \r
+               if (id.equals(P_ID_NOMENCLATURAL_CITATION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_NOMENCLATURAL_CITATION, P_NOMENCLATURAL_CITATION));                     \r
+               } \r
+               if (id.equals(P_ID_PAGES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PAGES, P_PAGES));                       \r
+               } \r
+               if (id.equals(P_ID_SERIES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SERIES, P_SERIES));                     \r
+               } \r
+               if (id.equals(P_ID_VOLUME )) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_VOLUME, P_VOLUME));                     \r
+               }\r
+               if (id.equals(P_ID_EDITOR)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_EDITOR, P_EDITOR));                     \r
+               } \r
+               if (id.equals(P_ID_PLACEPUBLISHED)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PLACEPUBLISHED, P_PLACEPUBLISHED));                     \r
+               }\r
+               if (id.equals(P_ID_PUBLISHER)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PUBLISHER, P_PUBLISHER));                       \r
+               } \r
+               if (id.equals(P_ID_ISSN)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ISSN, P_ISSN));                 \r
+               } \r
+               if (id.equals(P_ID_INSTITUTION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INSTITUTION, P_INSTITUTION));                   \r
+               } \r
+               if (id.equals(P_ID_SCHOOL)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SCHOOL, P_SCHOOL));                     \r
+               } \r
+               if (id.equals(P_ID_INSERIES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INSERIES, P_INSERIES));                 \r
+               } \r
+               if (id.equals(P_ID_SERIESPART)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SERIESPART, P_SERIESPART));                     \r
+               } \r
+               if (id.equals(P_ID_ISBN)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ISBN, P_ISBN));\r
+               }\r
+               if (id.equals(P_ID_ORGANIZATION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ORGANIZATION, P_ORGANIZATION));                 \r
+               } \r
+               if (id.equals(P_ID_PRINTEDUNIT)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PRINTEDUNIT, P_PRINTEDUNIT));                   \r
+               } \r
+               if (id.equals(P_ID_INBOOK)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INBOOK, P_INBOOK));                     \r
+               } \r
+               if (id.equals(P_ID_INPROCEEDINGS)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INPROCEEDINGS, P_INPROCEEDINGS));                       \r
+               } \r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()\r
+        */\r
+       @Override\r
+       public Object getEditableValue() {\r
+               return CdmUtils.Nz(reference.getTitleCache());\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()\r
+        */\r
+       @Override\r
+       public IPropertyDescriptor[] getPropertyDescriptors() {\r
+               return (IPropertyDescriptor[]) descriptors.toArray(\r
+                new IPropertyDescriptor[descriptors.size()]);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)\r
+        */\r
+       @Override\r
+       public Object getPropertyValue(Object id) {\r
+               if (id.equals(P_ID_REFERENCETYPE)) {\r
+                       Class referenceClass = reference.getClass();\r
+                       int menuIndex = 0;\r
+                       for (Class clazz : referenceTypeMap.keySet()) {\r
+                               if (clazz == referenceClass) {\r
+                                       return menuIndex;\r
+                               }\r
+                               menuIndex++;\r
+                       }\r
+                       return 0;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)\r
+        */\r
+       @Override\r
+       public boolean isPropertySet(Object id) {\r
+               return false;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)\r
+        */\r
+       @Override\r
+       public void resetPropertyValue(Object id) {}\r
+\r
+       /* (non-Javadoc)\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
+               if (id.equals(P_ID_REFERENCETYPE)) {\r
+                       \r
+                       // NOTE: this code will only be reached if user actually changes choice in reference type\r
+                       //      dropdown list, not if focus is merely gained and lost without changing the value\r
+                       \r
+                       // Guard against class cast error\r
+                       if (!( value instanceof Integer)) {\r
+                               return;\r
+                       }\r
+                       \r
+                       // Grab reference's title cache\r
+                       String oldTitleCache = reference.getTitleCache();\r
+                       \r
+                       // Get reference's class\r
+                       int menuIndex = ((Integer) value).intValue();                   \r
+                       Class referenceClass = (Class)(referenceTypeMap.keySet().toArray())[menuIndex];\r
+                       \r
+                       // Make a new reference using the class\r
+                       reference = makeNewReference(referenceClass);\r
+                       \r
+                       // Set new reference's title cache\r
+                       reference.setTitleCache(oldTitleCache);                 \r
+               }\r
+               \r
+               propertyChangeSupport.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, reference);           \r
+       }\r
+       \r
+       /**\r
+        * Takes a <code>referenceClass</code>, then executes either its <code>NewInstance()</code> \r
+        * method or its constructor. Puts the resulting object in <code>this.reference</code> and\r
+        * returns it.\r
+        * <p>\r
+        * If unsuccessful, <code>this.reference</code> keeps its old value and is returned.\r
+        * @param referenceClass\r
+        * @return\r
+        */\r
+       private ReferenceBase makeNewReference(Class referenceClass) {\r
+                               \r
+               // Check whether the class has a method "NewInstance()";\r
+               try {\r
+                       Method method = referenceClass.getMethod("NewInstance", null);\r
+                       reference = (ReferenceBase) method.invoke(null, null);\r
+               } catch (NoSuchMethodException e) {\r
+                       try {\r
+                               // If not, use its constructor\r
+                               Constructor constructor = referenceClass.getConstructor(null);\r
+                               reference = (ReferenceBase) constructor.newInstance(null);\r
+                       } catch (SecurityException e1) {\r
+                               e1.printStackTrace();\r
+                       } catch (NoSuchMethodException e1) {\r
+                               e1.printStackTrace();\r
+                       } catch (IllegalArgumentException e1) {\r
+                               e1.printStackTrace();\r
+                       } catch (InstantiationException e1) {\r
+                               e1.printStackTrace();\r
+                       } catch (IllegalAccessException e1) {\r
+                               e1.printStackTrace();\r
+                       } catch (InvocationTargetException e1) {\r
+                               e1.printStackTrace();\r
+                       }\r
+               } catch (SecurityException e) {\r
+                       e.printStackTrace();\r
+               } catch (IllegalArgumentException e) {\r
+                       e.printStackTrace();\r
+               } catch (IllegalAccessException e) {\r
+                       e.printStackTrace();\r
+               } catch (InvocationTargetException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               return reference;\r
+       }\r
+\r
+       public String toString() {\r
+               return CdmUtils.Nz(reference.getTitleCache());\r
+       }\r
+\r
+       private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);\r
+       \r
+       public void addPropertyChangeListener(\r
+                       PropertyChangeListener listener) {\r
+               propertyChangeSupport.addPropertyChangeListener(listener);\r
+       }\r
+}
\ No newline at end of file
index 41a96a356ead8130eee1ea4f564a7a8cc7dfea32..beaaba5b6306be4f6c44f9c4ed4f7ee50c04a968 100644 (file)
@@ -9,6 +9,8 @@
 \r
 package eu.etaxonomy.taxeditor.propertysheet.description;\r
 \r
+import java.beans.PropertyChangeEvent;\r
+import java.beans.PropertyChangeListener;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 import java.util.Vector;\r
@@ -18,6 +20,7 @@ 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.model.description.CommonTaxonName;\r
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
@@ -27,7 +30,9 @@ 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.propertysheet.bibref.BibRefPropertySource;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -53,7 +58,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
+       public static final String P_ID_BIBREF = "bibref";\r
 \r
        /**\r
         * Property display keys\r
@@ -64,7 +69,7 @@ public class DescriptionElementPropertySource implements IPropertySource {
        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
+       protected static final String[] TOP_LEVEL_PROPERTIES = new String[] {P_ID_ELEMENT_CLASS, P_ID_FEATURE, P_ID_BIBREF};            \r
        \r
        private String[] P_FEATURE_CLASS_NAME_MENU;\r
        private Class[] P_FEATURE_CLASSES;\r
@@ -144,7 +149,8 @@ public class DescriptionElementPropertySource implements IPropertySource {
                }\r
                \r
                if (id.equals(P_ID_BIBREF)) {\r
-                       descriptors.addElement(new PropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
+                       descriptors.addElement(new TextPropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
+//                     descriptors.addElement(new PropertyDescriptor(P_ID_BIBREF, P_BIBREF));\r
                }\r
        }\r
        \r
@@ -193,11 +199,14 @@ public class DescriptionElementPropertySource implements IPropertySource {
 \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
+                       BibRefPropertySource bibRefPropertySource = new BibRefPropertySource(citation);\r
+                       bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               @Override\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       descriptionElement.setCitation((ReferenceBase) evt.getNewValue());\r
+                               }\r
+                       });\r
+                       return bibRefPropertySource;\r
                }               \r
                \r
                return null;\r
@@ -225,5 +234,17 @@ public class DescriptionElementPropertySource implements IPropertySource {
                if (id.equals(P_ID_ELEMENT_CLASS)) {\r
                        // Hmmm ...\r
                }\r
+               \r
+               if (id.equals(P_ID_BIBREF)) {\r
+                       ReferenceBase bibRef = descriptionElement.getCitation();\r
+                       if (bibRef == null) {\r
+                               bibRef = Generic.NewInstance();\r
+                               descriptionElement.setCitation(bibRef);\r
+                       }\r
+                       \r
+                       // "value" is the BibRefPropertySource, so we get the TitleCache from its\r
+                       // toString() method\r
+                       bibRef.setTitleCache(value.toString());\r
+               }\r
        }\r
 }\r
index a87fc56e1a09b858672b0b118269f8412ee9ecaf..a55cfb07d5e4ed524301b809739c54a3cb8fd26f 100644 (file)
@@ -184,17 +184,19 @@ public class NonViralNamePropertySource implements IPropertySource {
        protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();\r
        /**\r
         * Add descriptor for a given property.\r
-        * \r
+        * <p>\r
         * Notes on Descriptor:\r
-        * \r
-        *  PropertyDescriptor - uneditable cell value\r
-        *  ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based\r
-        *  TextPropertyDescriptor - editable cell value\r
-        *  \r
+        * </p>\r
+        * <ul>\r
+        *  <li>PropertyDescriptor - uneditable cell value</li>\r
+        *  <li>ComboBoxPropertyDescriptor - dropdown list, property supplied must be integer-based</li>\r
+        *  <li>TextPropertyDescriptor - editable cell value</li>\r
+        * </ul>\r
+        *  <p>\r
         *  If any descriptor calls setCategory, all descriptors w/out a category are put in \r
         *  category "Misc".\r
-        *  \r
-        *  descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT }) -\r
+        *  <p>\r
+        *  <code>descriptor.setFilterFlags (new String[] { IPropertySheetEntry.FILTER_ID_EXPERT })</code> -\r
         *   this descriptor shown under advanced properties\r
         *  \r
         * @param id\r
@@ -714,7 +716,6 @@ public class NonViralNamePropertySource implements IPropertySource {
                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