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
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
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
\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
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
* @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
--- /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.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