1) Added import / export dummy functionality (i.e. CDM library not yet functional...
authorp.ciardelli <p.ciardelli@localhost>
Thu, 13 Nov 2008 10:54:55 +0000 (10:54 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Thu, 13 Nov 2008 10:54:55 +0000 (10:54 +0000)
15 files changed:
.gitattributes
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationActionBarAdvisor.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/UiUtil.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java [new file with mode: 0644]
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/TimePeriodPropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/description/DescriptionElementPropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/NonViralNamePropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/NomenclaturalReferencePropertySource.java [new file with mode: 0644]
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/ReferencePropertySource.java [new file with mode: 0644]

index f12b7544b605ff25edb072bf13a5b0f301c6788c..f2ce1e9d592dc6736000e380f7f7d9a92fc15f42 100644 (file)
@@ -425,6 +425,7 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/Re
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SaveTaxonAction.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/SwapSynonymAndTaxonAction.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/TaxonActionFactory.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ImportAction.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AdaptCompositeToGroupAction.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/AddBasionymCompositeAction.java -text
@@ -537,3 +538,5 @@ eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/NameRelationWizard.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/NameRelationWizardModel.java -text
 eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/namerelationswizard/NameRelationsListWizard.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/NomenclaturalReferencePropertySource.java -text
+eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/ReferencePropertySource.java -text
index 07ef3c8583c166cfa016cf56634d017541a8ebb1..08f2e09b2d314f4db3a8003ad1138c098858da0b 100644 (file)
@@ -9,6 +9,9 @@
 
 package eu.etaxonomy.taxeditor;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.log4j.Logger;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
@@ -20,8 +23,9 @@ import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
 import org.eclipse.ui.application.ActionBarAdvisor;
 import org.eclipse.ui.application.IActionBarConfigurer;
 
+import eu.etaxonomy.cdm.io.common.ImportWrapper;
+import eu.etaxonomy.taxeditor.actions.io.ExportAction;
 import eu.etaxonomy.taxeditor.actions.io.ImportAction;
-import eu.etaxonomy.taxeditor.actions.ui.OpenNameRelationWizardAction;
 import eu.etaxonomy.taxeditor.actions.ui.OpenTaxonEditorAction;
 
 /**
@@ -46,7 +50,10 @@ public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
        private IWorkbenchAction undoAction;
        
        private IAction newNameAction;
-       private IAction importAction;
+
+       private List<IAction> importActionList;
+
+       private IAction exportJaxbAction;
 
        public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
                super(configurer);
@@ -72,27 +79,58 @@ public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
                newNameAction = new OpenTaxonEditorAction();
                register(newNameAction);
                
-               importAction = new ImportAction();
-               register(importAction);
-               
                preferencesAction = ActionFactory.PREFERENCES.create(window);
+               
+               makeImportActions();
+               
+               exportJaxbAction = new ExportAction(ExportAction.JAXB);
+               register(exportJaxbAction);
+       }
+
+       private void makeImportActions() {
+               
+               importActionList = new ArrayList<IAction>();
+               
+               for (ImportWrapper wrapper : ImportWrapper.list()) {
+                       IAction importAction = new ImportAction(wrapper);
+                       register(importAction);
+                       importActionList.add(importAction);             
+               }
        }
 
        protected void fillMenuBar(IMenuManager menuBar) {
-               MenuManager fileMenu = new MenuManager("&File",
-                               null);
+
                // Note: to hook into Eclipse File Menu, to use open File for instance,
                //  replace NULL with IWorkbenchActionConstants.M_FILE);
+               MenuManager fileMenu = new MenuManager("&File",
+                               null);
+               
+               // Create submenu for imports
+               MenuManager importMenu = new MenuManager("Import ...", null);
+               
+               // Create submenu for exports
+               MenuManager exportMenu = new MenuManager("Export as ...", null);
 
+               // Populate file menu
                menuBar.add(fileMenu);
                fileMenu.add(newNameAction);
                fileMenu.add(saveAction);
                fileMenu.add(undoAction);
                fileMenu.add(new Separator());
-               fileMenu.add(importAction);
+               fileMenu.add(importMenu);
+               fileMenu.add(exportMenu);
                fileMenu.add(new Separator());
                fileMenu.add(exitAction);
                
+               // Populate submenu for imports
+               for (IAction importAction : importActionList) {
+                       importMenu.add(importAction);
+               }
+
+               // Populate submenu for exports
+               exportMenu.add(exportJaxbAction);
+               
+               // Populate preferences
                MenuManager preferencesMenu = new MenuManager("&Preferences",
                                null);
                menuBar.add(preferencesMenu);
index 421153fd321625a9f6ba6ea762cd76baf553f61c..1de6ae6b0e3dae2d7c8da940106361b649ff47d9 100644 (file)
@@ -42,4 +42,11 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
                configurer.setShowPerspectiveBar(true);
                configurer.setTitle("EDIT Taxonomic Editor");
        }
+       
+       public void postWindowOpen() {
+               
+               // Remove "Show adv. properties" and "Show categories" from prop. sheet
+               UiUtil.hidePropertySheetToolbar();
+       }
+       
 }
index 715a5c5d4f4afbfde8a49914b4166da403e5e9ac..5bc143221fa13524e368f3c2644ff5c67822e97c 100644 (file)
@@ -14,6 +14,7 @@ import org.eclipse.ui.IFolderLayout;
 import org.eclipse.ui.IPageLayout;
 import org.eclipse.ui.IPerspectiveFactory;
 import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.views.properties.PropertySheetPage;
 
 import eu.etaxonomy.taxeditor.navigation.RecentNamesView;
 import eu.etaxonomy.taxeditor.navigation.TaxonomicTreeView;
@@ -53,6 +54,7 @@ public class FreetextPropertiesPerspective implements IPerspectiveFactory {
                folderLayoutRight.addView(IPageLayout.ID_PROP_SHEET);
                
                layout.getViewLayout(IPageLayout.ID_PROP_SHEET).setCloseable(false);
+               layout.getViewLayout(IPageLayout.ID_PROP_SHEET);
                layout.getViewLayout(TaxonomicTreeView.ID).setCloseable(false);         
        }
 }
index 7d12008432b9a7faea68b4dd7e26859aed9dfc84..f1258dbd0b55c95279d8ddab10ef463b587c53de 100644 (file)
@@ -49,7 +49,6 @@ import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.INameService;\r
 import eu.etaxonomy.cdm.api.service.ITaxonService;\r
 import eu.etaxonomy.cdm.database.CdmDataSource;\r
-import eu.etaxonomy.cdm.database.CdmPersistentDataSource;\r
 import eu.etaxonomy.cdm.database.DataSourceNotFoundException;\r
 import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
 import eu.etaxonomy.cdm.database.ICdmDataSource;\r
index ebfbe6daa64144d92869f06fc7cb0148fff39913..65a587b4362fbfb7893f8578f9ab3a0db19dd73a 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.IActionBars;\r
 import org.eclipse.ui.IEditorInput;\r
 import org.eclipse.ui.IEditorPart;\r
 import org.eclipse.ui.IEditorReference;\r
@@ -68,10 +69,23 @@ public class UiUtil {
                                return reference.getView(false);\r
                        }\r
                }\r
-//             PropertySheet ps = new PropertySheet();\r
                return null;\r
        }\r
        \r
+       /**\r
+        * By default, property sheet has buttons in the toolbar for \r
+        * "Show advanced properties" and "Show categories".\r
+        * <p>\r
+        * This is confusing for the user, hence a method to remove them\r
+        * until such time as advanced properties or categories are implemented.\r
+        */\r
+       public static void hidePropertySheetToolbar() {\r
+               PropertySheet propertySheet = (PropertySheet) getPropertySheet();\r
+               IActionBars actionBars = propertySheet.getViewSite().getActionBars();\r
+               actionBars.getToolBarManager().removeAll();\r
+               actionBars.getMenuManager().removeAll();\r
+       }\r
+       \r
        /**\r
         * The property sheet listener ensures only property sheets\r
         *      with data cause the Property Sheet to be updated.\r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/io/ExportAction.java
new file mode 100644 (file)
index 0000000..5de2f11
--- /dev/null
@@ -0,0 +1,65 @@
+/**\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.actions.io;\r
+\r
+import java.io.File;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+\r
+import eu.etaxonomy.taxeditor.UiUtil;\r
+\r
+/**\r
+ * @author p.ciardelli\r
+ * @created 05.11.2008\r
+ * @version 1.0\r
+ */\r
+public class ExportAction extends Action {\r
+       private static final Logger logger = Logger.getLogger(ExportAction.class);\r
+\r
+       private static String text = "Export as ...";\r
+       private ImageDescriptor image = null;\r
+       public static final String ID = "eu.etaxonomy.taxeditor.actions.io.exportaction"; //$NON-NLS-1$\r
+\r
+       public static final String JAXB = "JAXB";\r
+\r
+       private FileDialog dialog;\r
+       private File file;\r
+\r
+       private String exportType;\r
+       \r
+       public ExportAction() {\r
+               super(text);\r
+               setImageDescriptor(image);\r
+               setId(ID);\r
+       }\r
+\r
+       public ExportAction(String exportType) {\r
+               this();\r
+               \r
+               this.exportType = exportType;\r
+               setText(exportType);\r
+       }\r
+\r
+       public void run() {\r
+\r
+               // Use same title "Import FORMAT" for all message dialogs\r
+               String title = "Export " + getText();\r
+               \r
+               // Get file from user\r
+               dialog = new FileDialog(UiUtil.getShell(), SWT.SAVE);\r
+               dialog.setFileName("export.xml");\r
+               String filePath = dialog.open();\r
+               file = new File(filePath);              \r
+       }\r
+}\r
index 987c4aef9dd9e605a7a6df2569a8d7cd0e52699e..ff66615258e0097b7a46b86f2b69018b4d179d54 100644 (file)
@@ -11,21 +11,17 @@ package eu.etaxonomy.taxeditor.actions.io;
 \r
 import java.io.File;\r
 import java.net.MalformedURLException;\r
-import java.util.UUID;\r
 \r
 import org.apache.log4j.Logger;\r
 import org.eclipse.jface.action.Action;\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.eclipse.swt.widgets.FileDialog;\r
 \r
-import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
 import eu.etaxonomy.cdm.database.ICdmDataSource;\r
-import eu.etaxonomy.cdm.io.common.CdmDefaultImport;\r
-import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;\r
-import eu.etaxonomy.cdm.io.tcs.TcsImportConfigurator;\r
+import eu.etaxonomy.cdm.io.common.ImportWrapper;\r
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
 import eu.etaxonomy.taxeditor.UiUtil;\r
-import eu.etaxonomy.taxeditor.io.InputWizard2;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -40,61 +36,62 @@ public class ImportAction extends Action {
        public static final String ID = "eu.etaxonomy.taxeditor.actions.io.importaction"; //$NON-NLS-1$\r
 \r
        private FileDialog dialog;\r
-\r
        private File file;\r
-\r
-       private InputWizard2 wizard;\r
+       private ImportWrapper importWrapper;\r
        \r
        public ImportAction() {\r
                super(text);\r
                setImageDescriptor(image);\r
                setId(ID);\r
        }\r
-       \r
+\r
+       public ImportAction(ImportWrapper importWrapper) {\r
+               this();\r
+               \r
+               this.importWrapper = importWrapper;\r
+               setText(importWrapper.getLabel());\r
+       }\r
+\r
        public void run() {\r
+\r
+               // Use same title "Import FORMAT" for all message dialogs\r
+               String title = "Import " + getText();\r
+               \r
+               // Make sure user is aware of the implications of an import\r
+               boolean doProceed = MessageDialog.openConfirm(UiUtil.getShell(), title, \r
+                               "Import may require a great deal of time and system resources.\n\n" +\r
+                               "Are you sure you would like to proceed?");\r
+               if (!doProceed) {\r
+                       return;\r
+               }\r
+               \r
+               // Get file from user\r
                dialog = new FileDialog(UiUtil.getShell());\r
                String filePath = dialog.open();\r
                file = new File(filePath);\r
-               \r
-//             wizard = new InputWizard2();\r
-               \r
-//             WizardDialog dialog = new WizardDialog(UiUtil.getShell(), wizard);\r
-//             dialog.create();\r
-//             dialog.open();\r
-               \r
+                               \r
+               // Get current data source\r
                ICdmDataSource destination = TaxEditorPlugin.getDefault().getCdmDataSource();\r
+               \r
+               // Format file path \r
                String source = null;\r
                try {\r
                        source = file.toURI().toURL().toString();\r
                } catch (MalformedURLException e) {\r
-                       // TODO Auto-generated catch block\r
-                       e.printStackTrace();\r
+                       MessageDialog.openError(UiUtil.getShell(), title, "File could not be read.");\r
+                       return;\r
                }\r
                \r
-               TcsImportConfigurator tcsImportConfigurator = TcsImportConfigurator.NewInstance(source,  destination);\r
-               \r
-//             tcsImportConfigurator.setSecUuid(UUID.fromString("5f32b8af-0c97-48ac-8d33-6099ed68c625"));\r
-//             tcsImportConfigurator.setSourceSecId("palm_pub_ed_999999");\r
-//             \r
-//             tcsImportConfigurator.setDoAuthors(false);\r
-//             tcsImportConfigurator.setDoReferences(DO_REFERENCES.ALL);\r
-//             tcsImportConfigurator.setDoTaxonNames(false);\r
-//             tcsImportConfigurator.setDoRelNames(false);\r
-               //tcsImportConfigurator.setDoNameStatus(doNameStatus);\r
-               //tcsImportConfigurator.setDoTypes(doTypes);\r
-               //tcsImportConfigurator.setDoNameFacts(doNameFacts);\r
-//             \r
-//             tcsImportConfigurator.setDoTaxa(false);\r
-//             tcsImportConfigurator.setDoRelTaxa(false);\r
-//             tcsImportConfigurator.setDoFacts(false);\r
-               \r
-               tcsImportConfigurator.setCheck(CHECK.IMPORT_WITHOUT_CHECK);\r
-               tcsImportConfigurator.setDbSchemaValidation(DbSchemaValidation.CREATE);\r
+               // Start import\r
+               boolean isSuccessfulImport = importWrapper.invoke(source, destination, null);\r
                \r
+               // Tell user whether import was a success or a dismal failure\r
+               String msg = null;\r
+               if (isSuccessfulImport) {\r
+                       MessageDialog.openInformation(UiUtil.getShell(), title, "Import successful");\r
+               } else {\r
+                       MessageDialog.openError(UiUtil.getShell(), title, "Import was unsuccessful.");\r
+               }\r
                \r
-               CdmDefaultImport<TcsImportConfigurator> tcsImport = new CdmDefaultImport<TcsImportConfigurator>();\r
-               //new Test().invoke(tcsImportConfigurator);\r
-               boolean successful = tcsImport.invoke(tcsImportConfigurator);           \r
-               logger.warn("Successful? " + successful);\r
        }\r
 }\r
index 2210732907ca4bbeea846e6be5e8a8ec291ed4d1..49d97157098cfe5bf5b4e447e3e3a37625b10c6f 100644 (file)
@@ -414,40 +414,68 @@ public class CdmUtil {
 //             return CdmUtils.Nz(nomenclaturalReference.getNomenclaturalCitation(microReference));\r
        }\r
        \r
+       /**\r
+        * Checks whether a String is either a valid year \r
+        *  or two valid years\r
+        * with the format "XXXX-XXXX". \r
+        *\r
+        * @see #getValidYear(String yearStr)\r
+        * @param refYear\r
+        * @return\r
+        * @throws NumberFormatException\r
+        */\r
        public static TimePeriod getDatePublished(String refYear) throws NumberFormatException {\r
-               if (refYear == null){\r
+               \r
+               if (refYear == null || ("").equals(refYear)){\r
                        return null;\r
                }\r
                \r
+               TimePeriod datePublished = TimePeriod.NewInstance();\r
+               \r
+               // In case format is "xxxx-xxxx"\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
+               // Unlikely case of "xxx-xx-xxx..."\r
+               if (years.length > 2) {\r
+                       throw new NumberFormatException();\r
                }\r
-               TimePeriod result = TimePeriod.NewInstance(calStart, calEnd);\r
-               return result;\r
+               \r
+               // Set startYear\r
+               datePublished.setStartYear(getValidYear(years[0]));\r
+\r
+               // Format is "xxx-xxxx"\r
+               if (years.length == 2) {\r
+                       datePublished.setEndYear(getValidYear(years[1]));\r
+               }\r
+               \r
+               return datePublished;\r
        }\r
        \r
-       public static Calendar getCalendar(String strYear) throws NumberFormatException {\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
-                       Integer year = Integer.valueOf(strYear.trim());\r
-                       if (year > 1750 && year < 2030){\r
-                               cal.set(year, Calendar.JANUARY, 1, 0, 0, 0);\r
-                       } else {\r
-                               throw new NumberFormatException();\r
-                       }\r
-               } else throw new NumberFormatException();\r
+       /**\r
+        * Checks whether a <code>String</code> is a valid year between\r
+        * 1750 and 2030. Throws a <code>NumberFormatException</code> if not.\r
+        * \r
+        * @param yearStr\r
+        * @return\r
+        * @throws NumberFormatException\r
+        */\r
+       public static Integer getValidYear(String yearStr) throws NumberFormatException {\r
+               \r
+               Integer yearInt = null;\r
+               \r
+               // Try casting string - don't catch number format exception\r
+               try {\r
+                       yearInt = new Integer(yearStr);\r
+               } catch (ClassCastException e) {\r
+                       throw new NumberFormatException();\r
+               }\r
+               \r
+               // Is year in valid range?\r
+               if (yearInt < 1750 || yearInt > 2030) {\r
+                       throw new NumberFormatException();\r
+               }\r
                \r
-               return cal;\r
+               return yearInt;\r
        }\r
 }\r
index 71c38bde22c0ba5d3a6527e8565c7b3baa2630d9..967a6f9f6beccc94fb54145cefb2d5190cc12453 100644 (file)
@@ -13,7 +13,6 @@ import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;\r
 import java.text.DateFormat;\r
 import java.text.SimpleDateFormat;\r
-import java.util.Calendar;\r
 import java.util.Vector;\r
 \r
 import org.apache.log4j.Logger;\r
@@ -57,7 +56,7 @@ public class TimePeriodPropertySource implements IPropertySource {
                new String[] {P_ID_STARTYEAR, P_ID_STARTMONTH, P_ID_STARTDAY, \r
                                                P_ID_ENDYEAR, P_ID_ENDMONTH, P_ID_ENDDAY};\r
                        \r
-       private static final String[] P_MONTH_MENU = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};\r
+       private static final String[] P_MONTH_MENU = new String[] {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};\r
        \r
        public TimePeriodPropertySource(TimePeriod timePeriod) {\r
                super();\r
@@ -68,27 +67,11 @@ public class TimePeriodPropertySource implements IPropertySource {
                this.timePeriod = timePeriod;\r
 \r
                // Add property sheet descriptors\r
-               addDescriptor(P_ID_STARTYEAR);\r
-               if (!getPropertyValue(P_ID_STARTYEAR).equals("")) {\r
-                       \r
-                       // Only show start month and start day after start year has been populated\r
-                       addDescriptor(P_ID_STARTMONTH);\r
-                       addDescriptor(P_ID_STARTDAY);\r
-                       \r
-                       // Only show end if start has been populated\r
-                       addDescriptor(P_ID_ENDYEAR);\r
-                       \r
-                       if (!getPropertyValue(P_ID_ENDYEAR).equals("")) {\r
-                               // Only show end month and end day after end year has been populated\r
-                               addDescriptor(P_ID_ENDMONTH);\r
-                               addDescriptor(P_ID_ENDDAY);                             \r
-                       }       \r
+               for (String key : TOP_LEVEL_PROPERTIES) {\r
+                       addDescriptor(key);\r
                }\r
-//             for (String key : TOP_LEVEL_PROPERTIES) {\r
-//                     addDescriptor(key);\r
-//             }\r
        }\r
-       \r
+               \r
     //static date formatter\r
     private static final DateFormat formatter = new SimpleDateFormat(\r
             "EEEE, MMMM d, yyyy"); //$NON-NLS-1$\r
@@ -149,31 +132,34 @@ public class TimePeriodPropertySource implements IPropertySource {
 \r
     public Object getPropertyValue(Object id) {\r
        \r
-       Calendar start = timePeriod.getStart();\r
-       Calendar end = timePeriod.getEnd();\r
-       \r
        if (id.equals(P_ID_STARTYEAR)) {\r
-               return (start == null) ? "" : String.valueOf(start.get(Calendar.YEAR));\r
+               Integer startYear = timePeriod.getStartYear();\r
+               return (startYear == null) ? "" : String.valueOf(startYear);\r
        }\r
-       \r
+\r
        if (id.equals(P_ID_STARTMONTH)) {\r
-               return (start == null) ? 0 : Integer.valueOf(start.get(Calendar.MONTH));\r
+               Integer startMonth = timePeriod.getStartMonth();\r
+               return (startMonth == null) ? 0 : startMonth;\r
        }\r
 \r
        if (id.equals(P_ID_STARTDAY)) {\r
-               return (start == null) ? "" : String.valueOf(start.get(Calendar.DAY_OF_MONTH));\r
+               Integer startDay = timePeriod.getStartDay();                    \r
+               return (startDay == null) ? "" : String.valueOf(startDay);\r
        }\r
        \r
        if (id.equals(P_ID_ENDYEAR)) {\r
-               return (end == null) ? "" : String.valueOf(end.get(Calendar.YEAR));\r
+               Integer endYear = timePeriod.getEndYear();\r
+               return (endYear == null) ? "" : String.valueOf(endYear);\r
        }\r
 \r
        if (id.equals(P_ID_ENDMONTH)) {\r
-               return (end == null) ? 0 : Integer.valueOf(end.get(Calendar.MONTH));\r
+               Integer endMonth = timePeriod.getEndMonth();\r
+               return (endMonth == null) ? 0 : endMonth;\r
        }\r
 \r
        if (id.equals(P_ID_ENDDAY)) {\r
-               return (end == null) ? "" : String.valueOf(end.get(Calendar.DAY_OF_MONTH));\r
+               Integer endDay = timePeriod.getEndDay();\r
+               return (endDay == null) ? "" : String.valueOf(endDay);\r
        }\r
        \r
         return "";\r
@@ -192,82 +178,53 @@ public class TimePeriodPropertySource implements IPropertySource {
     public void resetPropertyValue(Object property) {}\r
 \r
     public void setPropertyValue(Object id, Object value) {\r
-       Calendar start = timePeriod.getStart();\r
-       Calendar end = timePeriod.getEnd();\r
-       \r
-       // Init start if necessary\r
-       if (id.equals(P_ID_STARTYEAR) || id.equals(P_ID_STARTMONTH) || \r
-                       id.equals(P_ID_STARTDAY) ) {\r
-               if (start == null) {\r
-                       start = Calendar.getInstance();\r
-                       timePeriod.setStart(start);\r
-                       \r
-                       // Default to January 1\r
-                       start.set(Calendar.DAY_OF_YEAR, 1);\r
-               }                               \r
-       }\r
 \r
-       // Init end if necessary\r
-       if (id.equals(P_ID_ENDYEAR) || id.equals(P_ID_ENDMONTH) || \r
-                       id.equals(P_ID_ENDDAY) ) {\r
-               if (end == null) {\r
-                       end = Calendar.getInstance();\r
-                       timePeriod.setEnd(end);\r
-                       \r
-                       // Default to January 1\r
-                       end.set(Calendar.DAY_OF_YEAR, 1);\r
-               }                               \r
-       }\r
+               if (id.equals(P_ID_STARTYEAR)) {\r
+                       timePeriod.setStartYear(castToInteger(value));\r
+               }\r
+       \r
+               if (id.equals(P_ID_STARTMONTH)) {\r
+                       timePeriod.setStartMonth(castToInteger(value));\r
+               }\r
+       \r
+               if (id.equals(P_ID_STARTDAY)) {\r
+                       timePeriod.setStartDay(castToInteger(value));\r
+               }\r
+               \r
+               if (id.equals(P_ID_ENDYEAR)) {\r
+                       timePeriod.setEndYear(castToInteger(value));\r
+               }\r
+       \r
+               if (id.equals(P_ID_ENDMONTH)) {\r
+                       timePeriod.setEndMonth(castToInteger(value));\r
+               }\r
+       \r
+               if (id.equals(P_ID_ENDDAY)) {\r
+                       timePeriod.setEndDay(castToInteger(value));\r
+               }\r
        \r
-       if (id.equals(P_ID_STARTYEAR)) {\r
-               \r
-                       // Empty year string, set start and end to null\r
-               if (((String) value).equals("")) {\r
-                       start = null;\r
-                       end = null;\r
-               } else {\r
-                       start.set(Calendar.YEAR, castToInteger(value));\r
-               }\r
-       }\r
-\r
-       if (id.equals(P_ID_STARTMONTH)) {\r
-               start.set(Calendar.MONTH, (Integer) value);\r
-       }\r
+       propertyChangeSupport.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, timePeriod);\r
+    }\r
 \r
-       if (id.equals(P_ID_STARTDAY)) {\r
-               start.set(Calendar.DAY_OF_MONTH, castToInteger(value));\r
-       }\r
+    private Integer castToInteger(Object value) {\r
        \r
-       if (id.equals(P_ID_ENDYEAR)) {\r
-\r
-                       // Empty year string, set end to null\r
-               if (((String) value).equals("")) {\r
-                       timePeriod.setEnd(null);\r
+       // Dropdown lists return an Integer index\r
+       if (value instanceof Integer) {\r
+               \r
+               // First entry in dropdown is empty\r
+               if (((Integer) value).equals(0)) {\r
+                       return null;\r
                } else {\r
-                       end.set(Calendar.YEAR, castToInteger(value));\r
+                       return (Integer) value; \r
                }\r
        }\r
-\r
-       if (id.equals(P_ID_ENDMONTH)) {\r
-               end.set(Calendar.MONTH, (Integer) value);\r
-       }\r
-\r
-       if (id.equals(P_ID_ENDDAY)) {\r
-               end.set(Calendar.DAY_OF_MONTH, castToInteger(value));\r
-       }\r
-       \r
-       propertyChangeSupport.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, timePeriod);\r
-    }\r
-\r
-    private int castToInteger(Object value) {\r
-       Integer integer;\r
+        \r
+       Integer integer = null;\r
                try {\r
                        integer = new Integer((String) value);\r
+                       \r
                } catch (ClassCastException e) {\r
-                       integer = 0;\r
                } catch (NumberFormatException e) {\r
-                       // Likely because value = ""\r
-                       integer = 0;\r
                }\r
        return integer;\r
     }\r
@@ -277,9 +234,6 @@ public class TimePeriodPropertySource implements IPropertySource {
      * @return java.lang.String\r
      */\r
     public String toString() {\r
-//        Date bday = (new GregorianCalendar(getYear().intValue(), getMonth()\r
-//                .intValue() - 1, getDay().intValue())).getTime();\r
-//        return formatter.format(bday);\r
        return "";\r
     }  \r
 \r
index de8b4c99732608ca4ee6714ce7fa398aad0bebdf..e82e1d574dc2a8e9aa325b1c6478de3ae7594f2e 100644 (file)
@@ -32,7 +32,7 @@ import eu.etaxonomy.cdm.model.description.TaxonInteraction;
 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.ReferencePropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
 \r
 /**\r
  * @author p.ciardelli\r
index e21d84da8e1d7db41db692cb2913f474a8338c0d..ebe9ce189d8712c76af92e5a53384907b153ada0 100644 (file)
@@ -9,6 +9,7 @@
 \r
 package eu.etaxonomy.taxeditor.propertysheet.name;\r
 \r
+import java.beans.PropertyChangeEvent;\r
 import java.beans.PropertyChangeListener;\r
 import java.beans.PropertyChangeSupport;\r
 import java.util.ArrayList;\r
@@ -38,6 +39,7 @@ import eu.etaxonomy.cdm.model.reference.Book;
 import eu.etaxonomy.cdm.model.reference.BookSection;\r
 import eu.etaxonomy.cdm.model.reference.Generic;\r
 import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.taxeditor.ITaxEditorConstants;\r
 import eu.etaxonomy.taxeditor.TaxEditorPlugin;\r
 import eu.etaxonomy.taxeditor.UiUtil;\r
@@ -45,6 +47,8 @@ import eu.etaxonomy.taxeditor.model.CdmUtil;
 import eu.etaxonomy.taxeditor.propertysheet.AnnotationPropertySource;\r
 import eu.etaxonomy.taxeditor.propertysheet.AnnotationsPropertyDescriptor;\r
 import eu.etaxonomy.taxeditor.propertysheet.MarkersPropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.NomenclaturalReferencePropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -454,19 +458,34 @@ public class NonViralNamePropertySource implements IPropertySource {
                return "none (nonviral name)";\r
         }\r
         if (id.equals(P_ID_NOMENCLATURAL_REF)) {\r
+                       \r
 //             INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-//             if (nomenclaturalReference == null) {\r
+//             if (name.getNomenclaturalReference() == null) {\r
 //                     return "";\r
-//             }               \r
-//             String microReference = name.getNomenclaturalMicroReference();\r
-//                     return CdmUtils.Nz(nomenclaturalReference.getNomenclaturalCitation(microReference));\r
+//             } else {\r
+//                     return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields());\r
+//             }\r
+               \r
+               ReferenceBase nomRef = (ReferenceBase) name.getNomenclaturalReference();\r
                        \r
-               INomenclaturalReference nomenclaturalReference = (INomenclaturalReference) name.getNomenclaturalReference();\r
-               if (name.getNomenclaturalReference() == null) {\r
-                       return "";\r
-               } else {\r
-                       return new NonViralNamePropertySource(name, P_ID_NOMENCLATURAL_REF, getReferenceFields());\r
-               }\r
+                       // Create nom. reference as necessary\r
+                       if (nomRef == null) {\r
+                               nomRef = Generic.NewInstance();\r
+                       }\r
+                       \r
+                       // Create property source for submenu\r
+                       ReferencePropertySource nomRefPropertySource = new NomenclaturalReferencePropertySource(nomRef);\r
+                       \r
+                       // Add listener to notify name of all changes to nom. reference\r
+                       nomRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       if (evt.getNewValue() instanceof INomenclaturalReference) {\r
+                                               name.setNomenclaturalReference((INomenclaturalReference) evt.getNewValue());\r
+                                       }\r
+                               }\r
+                       });\r
+                       return nomRefPropertySource;\r
+               \r
         }\r
         if (id.equals(P_ID_NOMENCLATURAL_MICROREF)) {\r
                        return CdmUtils.Nz(name.getNomenclaturalMicroReference());\r
index d32493cc829faac482b130847881da54e517c11d..79d6b91ffb6a869cbddb8fd1d090b691caad6552 100644 (file)
@@ -17,7 +17,6 @@ import org.apache.log4j.Logger;
 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.name.BotanicalName;\r
 import eu.etaxonomy.cdm.model.name.NonViralName;\r
@@ -27,7 +26,7 @@ import eu.etaxonomy.cdm.model.name.ZoologicalName;
 import eu.etaxonomy.cdm.model.reference.Generic;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.taxeditor.propertysheet.bibref.ReferencePropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;\r
 \r
 /**\r
  * @author p.ciardelli\r
@@ -93,22 +92,13 @@ public class TaxonBasePropertySource implements IPropertySource {
                if (id.equals(P_ID_TAXONNAME)) {\r
                        \r
                        TaxonNameBase name = taxon.getName();\r
+                       \r
+                       // Create taxon name as necessary\r
                        if (name == null) {\r
                                name = NonViralName.NewInstance(Rank.SPECIES());\r
                        }\r
                        \r
-//                     ReferencePropertySource bibRefPropertySource = new ReferencePropertySource(sec);\r
-                       // Hmmm ... maybe the listeners on the NameComposite will take care of this ...\r
-//                     bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
-//                             public void propertyChange(PropertyChangeEvent evt) {\r
-//                                     if (evt.getNewValue() instanceof TaxonNameBase) {       \r
-//                                             taxon.setName((TaxonNameBase) evt.getNewValue());\r
-//                                             ((NonViralName) taxon).setN\r
-//                                             \r
-//                                     }\r
-//                             }\r
-//                     });\r
-//                     return bibRefPropertySource;\r
+                       // Send taxon name to appropriate property source for submenu\r
                        if (name instanceof BotanicalName) {\r
                                return new BotanicalNamePropertySource((BotanicalName) name);\r
                        }\r
@@ -125,11 +115,16 @@ public class TaxonBasePropertySource implements IPropertySource {
                if (id.equals(P_ID_TAXONSEC)) {\r
                        \r
                        ReferenceBase sec = taxon.getSec();\r
+                       \r
+                       // Create sec reference as necessary\r
                        if (sec == null) {\r
                                sec = Generic.NewInstance();\r
                        }\r
                        \r
+                       // Create property source for submenu\r
                        ReferencePropertySource secPropertySource = new ReferencePropertySource(sec);\r
+                       \r
+                       // Add listener to notify taxon of all changes to sec\r
                        secPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
                                public void propertyChange(PropertyChangeEvent evt) {\r
                                        if (evt.getNewValue() instanceof ReferenceBase) {       \r
@@ -159,14 +154,6 @@ public class TaxonBasePropertySource implements IPropertySource {
         * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)\r
         */\r
        public void setPropertyValue(Object id, Object value) {\r
-               // Edit taxon's name\r
-               if (id.equals(P_ID_TAXONNAME)) {\r
-                       \r
-               }\r
-               \r
-               // Edit taxon's sec. reference\r
-               if (id.equals(P_ID_TAXONSEC)) {\r
-                       \r
-               }\r
+               // All setting done in submenus\r
        }\r
 }\r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/NomenclaturalReferencePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/NomenclaturalReferencePropertySource.java
new file mode 100644 (file)
index 0000000..51f33ca
--- /dev/null
@@ -0,0 +1,159 @@
+/**\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.reference;\r
+\r
+import java.util.ArrayList;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
+\r
+import org.apache.log4j.Logger;\r
+\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.PrintedUnitBase;\r
+import eu.etaxonomy.cdm.model.reference.PublicationBase;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
+import eu.etaxonomy.cdm.model.reference.SectionBase;\r
+import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;\r
+\r
+/**\r
+ * Quick and dirty subclass of <code>ReferencePropertySource</code>.\r
+ * <p>\r
+ * TODO: reprogram to only use <code>ReferenceBase</code> classes which implement\r
+ * <code>INomenclaturalReference</code>.\r
+ *  \r
+ * @author p.ciardelli\r
+ * @created 12.11.2008\r
+ * @version 1.0\r
+ */\r
+public class NomenclaturalReferencePropertySource extends\r
+               ReferencePropertySource {\r
+       private static final Logger logger = Logger\r
+                       .getLogger(NomenclaturalReferencePropertySource.class);\r
+       \r
+       public NomenclaturalReferencePropertySource(ReferenceBase reference) {\r
+               super(reference);\r
+       }\r
+       \r
+       protected 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(Book.class, "Book");\r
+               referenceTypeMap.put(BookSection.class, "Book Section");\r
+       }\r
+       \r
+       protected void initDescriptors() {\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
+               }\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_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_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 (reference instanceof PublicationBase) {\r
+       \r
+                               displayFields.add(P_ID_PLACEPUBLISHED);\r
+                               displayFields.add(P_ID_PUBLISHER);\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
+                                               displayFields.add(P_ID_EDITION);\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
+                               }\r
+                       }\r
+               }\r
+               \r
+               for (String field : displayFields) {\r
+                       addDescriptor(field);\r
+               }\r
+       }\r
+}\r
diff --git a/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/ReferencePropertySource.java b/eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/reference/ReferencePropertySource.java
new file mode 100644 (file)
index 0000000..5ad59fd
--- /dev/null
@@ -0,0 +1,1003 @@
+/**\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.reference;\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.agent.Team;\r
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
+import eu.etaxonomy.cdm.model.common.TimePeriod;\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
+import eu.etaxonomy.taxeditor.model.CdmUtil;\r
+import eu.etaxonomy.taxeditor.propertysheet.TimePeriodPropertySource;\r
+import eu.etaxonomy.taxeditor.propertysheet.YearValidator;\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
+ *                     ReferencePropertySource bibRefPropertySource = new ReferencePropertySource(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 ReferencePropertySource implements IPropertySource {\r
+       private static final Logger logger = Logger\r
+                       .getLogger(ReferencePropertySource.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_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
+       \r
+    // Property display keys\r
+       public static final String P_REFERENCETYPE = "00:Reference Type";\r
+       public static final String P_AUTHORTEAM = "01:Author Team (Cache)";\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_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
+       \r
+       protected static HashMap<Class, String> referenceTypeMap = null;\r
+       \r
+       private static final String[] P_BIBTEX_ENTRYTYPE_MENU = new String[] {"ARTICLE", "BOOK", "BOOKLET", "INBOOK", "INCOLLECTION", "PROCEEDINGS", "INPROCEEDINGS", "CONFERENCE", "MANUAL", "MASTERTHESIS", "PHDTHESIS", "TECHREPORT", "UNPUBLISHED", "MISC"};\r
+       \r
+       protected 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 ReferencePropertySource(ReferenceBase reference) {\r
+               super();\r
+               \r
+               // Default type of ReferenceBase is Generic\r
+               if (reference == null) {\r
+                       reference = Generic.NewInstance();\r
+               }               \r
+               this.reference = reference;\r
+\r
+               initDescriptors();\r
+       }\r
+\r
+       protected void initDescriptors() {\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
+               }\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_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_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
+                                               displayFields.add(P_ID_EDITION);\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
+                               }\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
+               \r
+               // Reference type\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
+               \r
+               // Author team\r
+               if (id.equals(P_ID_AUTHORTEAM)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_AUTHORTEAM, P_AUTHORTEAM));                     \r
+               }\r
+               \r
+               // Year\r
+               if (id.equals(P_ID_YEAR)) {\r
+                       TextPropertyDescriptor yearDescriptor = new TextPropertyDescriptor(P_ID_YEAR, P_YEAR);\r
+                       \r
+                       // BibtexReference.setYear() takes a String, no need for validation\r
+                       if (!(reference instanceof BibtexReference)) {\r
+                               yearDescriptor.setValidator(new YearValidator());\r
+                       }\r
+                       descriptors.addElement(yearDescriptor);         \r
+               }\r
+               \r
+               // Citation\r
+               if (id.equals(P_ID_CITATION)) {\r
+                       descriptors.addElement(\r
+                                       new PropertyDescriptor(P_ID_CITATION, P_CITATION));                     \r
+               }\r
+               \r
+               // URI\r
+               if (id.equals(P_ID_URI)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_URI, P_URI));                   \r
+               } \r
+               \r
+               // Date published\r
+               if (id.equals(P_ID_DATEPUBLISHED)) {\r
+                       descriptors.addElement(\r
+                                       new PropertyDescriptor(P_ID_DATEPUBLISHED, P_DATEPUBLISHED));                   \r
+               } \r
+               \r
+               // Title\r
+               if (id.equals(P_ID_TITLE)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_TITLE, P_TITLE));                       \r
+               } \r
+               \r
+               // In journal\r
+               if (id.equals(P_ID_INJOURNAL)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INJOURNAL, P_INJOURNAL));                       \r
+               }\r
+               \r
+               // Pages\r
+               if (id.equals(P_ID_PAGES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PAGES, P_PAGES));                       \r
+               } \r
+               \r
+               // Series\r
+               if (id.equals(P_ID_SERIES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SERIES, P_SERIES));                     \r
+               } \r
+               \r
+               // Volume\r
+               if (id.equals(P_ID_VOLUME )) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_VOLUME, P_VOLUME));                     \r
+               }\r
+               \r
+               // Editor\r
+               if (id.equals(P_ID_EDITOR)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_EDITOR, P_EDITOR));                     \r
+               } \r
+\r
+               // Edition\r
+               if (id.equals(P_ID_EDITION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_EDITION, P_EDITION));                   \r
+               } \r
+               \r
+               // Place published\r
+               if (id.equals(P_ID_PLACEPUBLISHED)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PLACEPUBLISHED, P_PLACEPUBLISHED));                     \r
+               }\r
+               \r
+               // Publisher\r
+               if (id.equals(P_ID_PUBLISHER)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PUBLISHER, P_PUBLISHER));                       \r
+               } \r
+               \r
+               // ISSN\r
+               if (id.equals(P_ID_ISSN)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ISSN, P_ISSN));                 \r
+               } \r
+               \r
+               // Institution\r
+               if (id.equals(P_ID_INSTITUTION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INSTITUTION, P_INSTITUTION));                   \r
+               } \r
+               \r
+               // School\r
+               if (id.equals(P_ID_SCHOOL)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SCHOOL, P_SCHOOL));                     \r
+               } \r
+               \r
+               // In series\r
+               if (id.equals(P_ID_INSERIES)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INSERIES, P_INSERIES));                 \r
+               } \r
+               \r
+               // Series part\r
+               if (id.equals(P_ID_SERIESPART)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_SERIESPART, P_SERIESPART));                     \r
+               } \r
+               \r
+               // ISBN\r
+               if (id.equals(P_ID_ISBN)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ISBN, P_ISBN));\r
+               }\r
+               \r
+               // Organization\r
+               if (id.equals(P_ID_ORGANIZATION)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_ORGANIZATION, P_ORGANIZATION));                 \r
+               } \r
+               \r
+               // Printed unit\r
+               if (id.equals(P_ID_PRINTEDUNIT)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_PRINTEDUNIT, P_PRINTEDUNIT));                   \r
+               } \r
+               \r
+               // In book\r
+               if (id.equals(P_ID_INBOOK)) {\r
+                       descriptors.addElement(\r
+                                       new TextPropertyDescriptor(P_ID_INBOOK, P_INBOOK));                     \r
+               }\r
+               \r
+               // Bibtex entry type\r
+               if (id.equals(P_ID_BIBTEX_ENTRYTYPE)) {\r
+                       descriptors.addElement(\r
+                                       new ComboBoxPropertyDescriptor(P_ID_BIBTEX_ENTRYTYPE, P_BIBTEX_ENTRYTYPE, P_BIBTEX_ENTRYTYPE_MENU));                    \r
+               }\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()\r
+        */\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
+       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
+       public Object getPropertyValue(Object id) {\r
+                               \r
+               // Reference Type: get integer index of drop-down menu\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
+\r
+               // Author Team: for now, just edit the cache\r
+               // TODO AuthorTeamPropertySource\r
+               if (id.equals(P_ID_AUTHORTEAM)) {\r
+                       TeamOrPersonBase authorTeam = reference.getAuthorTeam();\r
+                       \r
+                       if (authorTeam == null) {\r
+                               return "";\r
+                       }\r
+                       \r
+                       return CdmUtils.Nz(authorTeam.getTitleCache());\r
+               }\r
+               \r
+               // Year\r
+               if (id.equals(P_ID_YEAR)) {\r
+                       return CdmUtils.Nz(reference.getYear());\r
+               }\r
+               \r
+               // Citation\r
+               if (id.equals(P_ID_CITATION)) {\r
+                       return CdmUtils.Nz(reference.getCitation());\r
+               }\r
+               \r
+               // URI\r
+               if (id.equals(P_ID_URI)) {\r
+                       return CdmUtils.Nz(reference.getUri());\r
+               }\r
+               \r
+               // Date published\r
+               if (id.equals(P_ID_DATEPUBLISHED)) {\r
+                       TimePeriod datePublished = (TimePeriod) invokeMethod(reference, "getDatePublished", null);\r
+                       \r
+                       if (datePublished == null) {\r
+                               datePublished = TimePeriod.NewInstance();\r
+                       }\r
+                       \r
+                       TimePeriodPropertySource timePeriodPropertySource = \r
+                                       new TimePeriodPropertySource(datePublished);\r
+                       timePeriodPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       if (reference instanceof StrictReferenceBase && evt.getNewValue() instanceof TimePeriod) {      \r
+                                               ((StrictReferenceBase) reference).setDatePublished((TimePeriod) evt.getNewValue());\r
+                                       }\r
+                               }\r
+                       });\r
+                       return timePeriodPropertySource;\r
+               }\r
+               \r
+               // Title: used by StrictReferenceBase\r
+               if (id.equals(P_ID_TITLE)) {\r
+                       String title = (String) invokeMethod(reference, "getTitle", null);\r
+                       return CdmUtils.Nz(title);\r
+               }\r
+               \r
+               // InJournal: return an instance of ReferencePropertySource\r
+               if (id.equals(P_ID_INJOURNAL)) {\r
+                               \r
+                       Journal inJournal = (Journal) invokeMethod(reference, "getInJournal", null);\r
+                       \r
+                       if (inJournal == null) {\r
+                               inJournal = Journal.NewInstance();\r
+                       }\r
+                       \r
+                       ReferencePropertySource bibRefPropertySource = new ReferencePropertySource(inJournal);\r
+                       bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       if (reference instanceof Article && evt.getNewValue() instanceof Journal) {     \r
+                                               ((Article) reference).setInJournal((Journal) evt.getNewValue());\r
+                                       }\r
+                               }\r
+                       });\r
+                       return bibRefPropertySource;\r
+               }\r
+               \r
+               // Pages\r
+               if (id.equals(P_ID_PAGES)) {\r
+                       String pages = (String) invokeMethod(reference, "getPages", null);\r
+                       return CdmUtils.Nz(pages);\r
+               }\r
+               \r
+               // Series\r
+               if (id.equals(P_ID_SERIES)) {\r
+                       String series = (String) invokeMethod(reference, "getSeries", null);\r
+                       return CdmUtils.Nz(series); \r
+               }\r
+\r
+               // Volume\r
+               if (id.equals(P_ID_VOLUME)) {\r
+                       String volume = (String) invokeMethod(reference, "getVolume", null);\r
+                       return CdmUtils.Nz(volume);                     \r
+               }\r
+\r
+               // Editor\r
+               if (id.equals(P_ID_EDITOR)) {\r
+                       String editor = (String) invokeMethod(reference, "getEditor", null);\r
+                       return CdmUtils.Nz(editor);                     \r
+               }\r
+\r
+               // Edition\r
+               if (id.equals(P_ID_EDITION)) {\r
+                       String edition = (String) invokeMethod(reference, "getEdition", null);\r
+                       return CdmUtils.Nz(edition);                    \r
+               }\r
+               \r
+               // Place published\r
+               if (id.equals(P_ID_PLACEPUBLISHED)) {\r
+                       String placePublished = (String) invokeMethod(reference, "getPlacePublished", null);\r
+                       return CdmUtils.Nz(placePublished);\r
+               }\r
+               \r
+               // Publisher\r
+               if (id.equals(P_ID_PUBLISHER)) {\r
+                       String publisher = (String) invokeMethod(reference, "getPublisher", null);\r
+                       return CdmUtils.Nz(publisher);                  \r
+               }\r
+\r
+               // ISSN\r
+               if (id.equals(P_ID_ISSN)) {\r
+                       String issn = (String) invokeMethod(reference, "getIssn", null);\r
+                       return CdmUtils.Nz(issn);                       \r
+               }\r
+\r
+               // Institution\r
+               if (id.equals(P_ID_INSTITUTION)) {\r
+                       String institution = (String) invokeMethod(reference, "getInstitution", null);\r
+                       return CdmUtils.Nz(institution);                        \r
+               }\r
+\r
+               // In series\r
+               if (id.equals(P_ID_INSERIES)) {\r
+                       \r
+               }\r
+               \r
+               // ISBN\r
+               if (id.equals(P_ID_ISBN)) {\r
+                       String isbn = (String) invokeMethod(reference, "getIsbn", null);\r
+                       return CdmUtils.Nz(isbn);                               \r
+               }\r
+\r
+               // Organization\r
+               if (id.equals(P_ID_ORGANIZATION)) {\r
+                       String organization = (String) invokeMethod(reference, "getOrganization", null);\r
+                       return CdmUtils.Nz(organization);                       \r
+               }\r
+               \r
+               // In book\r
+               if (id.equals(P_ID_INBOOK)) {\r
+                       \r
+                       Book inBook = (Book) invokeMethod(reference, "getInBook", null);\r
+                       \r
+                       if (inBook == null) {\r
+                               inBook = Book.NewInstance();\r
+                       }\r
+                       \r
+                       ReferencePropertySource bibRefPropertySource = new ReferencePropertySource(inBook);\r
+                       bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {\r
+                               public void propertyChange(PropertyChangeEvent evt) {\r
+                                       if (reference instanceof BookSection && evt.getNewValue() instanceof Book) {    \r
+                                               ((BookSection) reference).setInBook((Book) evt.getNewValue());\r
+                                       }\r
+                               }\r
+                       });\r
+                       return bibRefPropertySource;\r
+               }\r
+\r
+               // Bibtex entry type\r
+               if (id.equals(P_ID_BIBTEX_ENTRYTYPE)) {\r
+                       \r
+               }\r
+               \r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Executes <code>methodName</code> on <code>obj</code> with\r
+        * the argument <code>arg</code>.\r
+        * <p>\r
+        * On failure, returns <code>null</code>.\r
+        * <p>\r
+        * NOTE:  both <code>Class.getMethod()</code> and <code>Method.invoke()</code>\r
+        * can be called with the <code>Object... args</code> approach, which allows\r
+        * the user to pass in a varying number of arguments. To keep it simple, and since\r
+        * this is usually only getters or setters, we are using only one argument.\r
+        * @param obj\r
+        * @param methodName\r
+        * @param args\r
+        * @return\r
+        */\r
+       private Object invokeMethod(Object obj, String methodName, Object arg) {\r
+               try {\r
+                       Method method = null;\r
+                       if (arg == null) {\r
+                               method = obj.getClass().getMethod(methodName);\r
+                               return method.invoke(obj);\r
+                       } else {\r
+                               method = obj.getClass().getMethod(methodName, arg.getClass());\r
+                               return method.invoke(obj, arg);\r
+                       }\r
+               } catch (SecurityException e) {\r
+                       logger.error(e.getMessage());\r
+               } catch (IllegalArgumentException e) {\r
+                       logger.error(e.getMessage());\r
+               } catch (NoSuchMethodException e) {\r
+                       logger.error(e.getMessage());\r
+               } catch (IllegalAccessException e) {\r
+                       logger.error(e.getMessage());\r
+               } catch (InvocationTargetException e) {\r
+                       logger.error(e.getMessage());\r
+               }\r
+               return null;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)\r
+        */\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
+       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
+       public void setPropertyValue(Object id, Object value) {\r
+               \r
+               // Reference Type\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
+                       // Grab reference's title cache\r
+                       String oldTitleCache = reference.getTitleCache();\r
+                       \r
+                       // Get reference's class\r
+                       int menuIndex;\r
+                       try {\r
+                               menuIndex = ((Integer) value).intValue();\r
+                       } catch (ClassCastException e) {\r
+                               // Leave method / no change on class cast error\r
+                               logger.error(e.getMessage());\r
+                               return;\r
+                       }                       \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
+               // Author Team\r
+               if (id.equals(P_ID_AUTHORTEAM)) {\r
+                       TeamOrPersonBase authorTeam = reference.getAuthorTeam();\r
+                       if (authorTeam == null) {\r
+                               authorTeam = Team.NewInstance();\r
+                               reference.setAuthorTeam(authorTeam);\r
+                       }\r
+                       try {\r
+                               authorTeam.setTitleCache((String) value);\r
+                       } catch (ClassCastException e) {\r
+                               // Leave method / no change on class cast error\r
+                               logger.error(e.getMessage());\r
+                               return;\r
+                       }\r
+               }\r
+               \r
+               // Citation\r
+               if (id.equals(P_ID_URI)) {\r
+                       String uri = (String) value;\r
+                       reference.setUri(uri);\r
+               }\r
+               \r
+               // Year\r
+               if (id.equals(P_ID_YEAR)) {\r
+                       String year = (String) value;\r
+                       if (reference instanceof BibtexReference) {\r
+                               ((BibtexReference) reference).setYear(year);\r
+                       }\r
+                       if (reference instanceof StrictReferenceBase) {\r
+                               try {\r
+                                       TimePeriod datePublished = null;\r
+                                       if (!year.equals("")) {\r
+                                               datePublished = CdmUtil.getDatePublished(year);                                         \r
+                                       }\r
+                                       ((StrictReferenceBase) reference).setDatePublished(datePublished);\r
+                               } catch (NumberFormatException e) {\r
+                                       // Validator should prevent this from ever happening ...\r
+                                       return; \r
+                               }\r
+                       }\r
+               }\r
+\r
+               // Title: used by StrictReferenceBase\r
+               if (id.equals(P_ID_TITLE)) {\r
+                       String title = null;\r
+                       try {\r
+                               title = (String) value;\r
+                       } catch (ClassCastException e) {\r
+                               // Leave method / no change on class cast error\r
+                               logger.error(e.getMessage());\r
+                               return;\r
+                       }\r
+                       invokeMethod(reference, "setTitle", title);\r
+               }\r
+\r
+               // Pages\r
+               if (id.equals(P_ID_PAGES)) {\r
+                       invokeMethod(reference, "setPages", (String) value);\r
+               }\r
+\r
+               // Series\r
+               if (id.equals(P_ID_SERIES)) {\r
+                       invokeMethod(reference, "setSeries", (String) value);\r
+               }\r
+               \r
+               // Volume\r
+               if (id.equals(P_ID_VOLUME)) {\r
+                       invokeMethod(reference, "setVolume", (String) value);\r
+               }\r
+               \r
+               // Editor\r
+               if (id.equals(P_ID_EDITOR)) {\r
+                       invokeMethod(reference, "setEditor", (String) value);\r
+               }\r
+\r
+               // Edition\r
+               if (id.equals(P_ID_EDITION)) {\r
+                       invokeMethod(reference, "setEdition", (String) value);\r
+               }\r
+               \r
+               // Place published\r
+               if (id.equals(P_ID_PLACEPUBLISHED)) {\r
+                       invokeMethod(reference, "setPlacePublished", (String) value);\r
+               }\r
+\r
+               // Publisher\r
+               if (id.equals(P_ID_PUBLISHER)) {\r
+                       invokeMethod(reference, "setPublisher", (String) value);\r
+               }\r
+\r
+               // ISSN\r
+               if (id.equals(P_ID_ISSN)) {\r
+                       invokeMethod(reference, "setIssn", (String) value);\r
+               }\r
+\r
+               // Institution\r
+               if (id.equals(P_ID_INSTITUTION)) {\r
+                       invokeMethod(reference, "setInstitution", (String) value);                      \r
+               }\r
+               \r
+               // ISBN\r
+               if (id.equals(P_ID_ISBN)) {\r
+                       invokeMethod(reference, "setIsbn", (String) value);\r
+               }\r
+\r
+               // Organization\r
+               if (id.equals(P_ID_ORGANIZATION)) {\r
+                       invokeMethod(reference, "setOrganization", (String) value);\r
+               }\r
+\r
+               // In book\r
+               if (id.equals(P_ID_INBOOK)) {\r
+                       Book inBook = (Book) invokeMethod(reference, "getInBook", null);\r
+                       if (inBook == null) {\r
+                               inBook = Book.NewInstance();\r
+                               invokeMethod(reference, "setInBook", inBook);\r
+                       }\r
+                       inBook.setTitleCache((String) value);\r
+               }\r
+               \r
+               propertyChangeSupport.firePropertyChange(ITaxEditorConstants.PROPERTY_SHEET_CHANGE, null, reference);           \r
+       }\r
+       \r
+       static boolean isMessageDialogOpen;\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