--- /dev/null
+/**\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;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.eclipse.jface.viewers.ICellEditorValidator;\r
+\r
+import eu.etaxonomy.cdm.model.common.TimePeriod;\r
+import eu.etaxonomy.cdm.model.reference.BibtexReference;\r
+import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;\r
+import eu.etaxonomy.taxeditor.model.CdmUtil;\r
+\r
+/**\r
+ * @author p.ciardelli\r
+ * @created 10.11.2008\r
+ * @version 1.0\r
+ */\r
+public class YearValidator implements ICellEditorValidator {\r
+ private static final Logger logger = Logger.getLogger(YearValidator.class);\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.jface.viewers.ICellEditorValidator#isValid(java.lang.Object)\r
+ */\r
+ public String isValid(Object value) {\r
+ String year = (String) value;\r
+ if (year.equals("")) {\r
+ return null;\r
+ }\r
+ try {\r
+ TimePeriod datePublished = CdmUtil.getDatePublished(year);\r
+ } catch (NumberFormatException e) {\r
+ return "Year must be between 1750 and 2030. Two years can also be given in the format 'xxxx-xxxx'.";\r
+ }\r
+ return null;\r
+ }\r
+}
\ No newline at end of file
import java.util.Vector;\r
\r
import org.apache.log4j.Logger;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.viewers.ICellEditorValidator;\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 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.UiUtil;\r
import eu.etaxonomy.taxeditor.model.CdmUtil;\r
import eu.etaxonomy.taxeditor.propertysheet.CheckboxPropertyDescriptor;\r
+import eu.etaxonomy.taxeditor.propertysheet.YearValidator;\r
\r
/**\r
* Supplies the properties of a <code>ReferenceBase</code> object for display by\r
}\r
if (id.equals(P_ID_YEAR)) {\r
yearDescriptor = new TextPropertyDescriptor(P_ID_YEAR, P_YEAR);\r
- yearDescriptor.setValidator(new ICellEditorValidator() {\r
-\r
- public String isValid(Object value) {\r
- String year = (String) value;\r
- logger.warn(year);\r
- if (year.equals("")) {\r
- return null;\r
- }\r
- if (reference instanceof BibtexReference) {\r
- return null;\r
- }\r
- if (reference instanceof StrictReferenceBase) {\r
- try {\r
- TimePeriod datePublished = CdmUtil.getDatePublished(year);\r
- } catch (NumberFormatException e) {\r
- return "Year must be between 1750 and 2030.\n\nTwo years can also be given in the format 'xxxx-xxxx'.";\r
- }\r
- }\r
- return null;\r
- }\r
- \r
- });\r
- descriptors.addElement(yearDescriptor);\r
-// descriptors.addElement(\r
-// 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
if (id.equals(P_ID_CITATION)) {\r
descriptors.addElement(\r
});\r
return bibRefPropertySource;\r
}\r
- return null;\r
+ return "";\r
}\r
\r
/**\r
datePublished = CdmUtil.getDatePublished(year); \r
}\r
((StrictReferenceBase) reference).setDatePublished(datePublished);\r
- } catch (NumberFormatException e) { \r
- \r
- // HACK to deal with the following sequence of events:\r
- // 1) focus moved to another cell\r
- // 2) Year cell is notified, calls setPropertyValue\r
- // 3) setPropertyValue opens MessageDialog, and does not complete until user feedback\r
- // 4) the new cell checks whether there is another active cell in PropertySheetViewer\r
- // 5) since the MessageDialog is open, Year cell is still "active" in PropertySheetViewer\r
- // 6) therefore, the new cell tries to close the Year cell, in the process calling setPropertyViewer \r
- // again and causing MessageDialog to pop up again\r
-// if (!isMessageDialogOpen) {\r
-// isMessageDialogOpen = true;\r
-// MessageDialog.openError(UiUtil.getShell(), "Invalid year format", "Year must be between 1750 and 2030.\n\nTwo years can also be given in the format 'xxxx-xxxx'.");\r
-// isMessageDialogOpen = false;\r
-// }\r
- return;\r
+ } catch (NumberFormatException e) {\r
+ // Validator should prevent this from ever happening ...\r
+ return; \r
}\r
}\r
}\r