2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.propertysheet
.reference
;
12 import java
.beans
.PropertyChangeEvent
;
13 import java
.beans
.PropertyChangeListener
;
14 import java
.beans
.PropertyChangeSupport
;
15 import java
.lang
.reflect
.Constructor
;
16 import java
.lang
.reflect
.InvocationTargetException
;
17 import java
.lang
.reflect
.Method
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.LinkedHashMap
;
21 import java
.util
.List
;
23 import java
.util
.Vector
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.eclipse
.ui
.views
.properties
.ComboBoxPropertyDescriptor
;
27 import org
.eclipse
.ui
.views
.properties
.IPropertyDescriptor
;
28 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
29 import org
.eclipse
.ui
.views
.properties
.PropertyDescriptor
;
30 import org
.eclipse
.ui
.views
.properties
.TextPropertyDescriptor
;
32 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
33 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
34 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
37 import eu
.etaxonomy
.cdm
.model
.reference
.Article
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.BibtexReference
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.Book
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.BookSection
;
41 import eu
.etaxonomy
.cdm
.model
.reference
.CdDvd
;
42 import eu
.etaxonomy
.cdm
.model
.reference
.Database
;
43 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
44 import eu
.etaxonomy
.cdm
.model
.reference
.InProceedings
;
45 import eu
.etaxonomy
.cdm
.model
.reference
.Journal
;
46 import eu
.etaxonomy
.cdm
.model
.reference
.Map
;
47 import eu
.etaxonomy
.cdm
.model
.reference
.Patent
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.PersonalCommunication
;
49 import eu
.etaxonomy
.cdm
.model
.reference
.PrintSeries
;
50 import eu
.etaxonomy
.cdm
.model
.reference
.PrintedUnitBase
;
51 import eu
.etaxonomy
.cdm
.model
.reference
.Proceedings
;
52 import eu
.etaxonomy
.cdm
.model
.reference
.PublicationBase
;
53 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
54 import eu
.etaxonomy
.cdm
.model
.reference
.Report
;
55 import eu
.etaxonomy
.cdm
.model
.reference
.SectionBase
;
56 import eu
.etaxonomy
.cdm
.model
.reference
.StrictReferenceBase
;
57 import eu
.etaxonomy
.cdm
.model
.reference
.Thesis
;
58 import eu
.etaxonomy
.cdm
.model
.reference
.WebPage
;
59 import eu
.etaxonomy
.taxeditor
.propertysheet
.TimePeriodPropertySource
;
60 import eu
.etaxonomy
.taxeditor
.propertysheet
.YearValidator
;
61 import eu
.etaxonomy
.taxeditor
.store
.model
.Resources
;
62 import eu
.etaxonomy
.taxeditor
.store
.model
.TimeUtil
;
65 * Supplies the properties of a <code>ReferenceBase</code> object for display by
66 * a <code>PropertySheet</code>.
68 * Includes a drop-down menu that allows the user to change <code>ReferenceBase</code>
69 * subclasses. This causes all fields except <code>TitleCache</code> to be wiped clean.
71 * Normally, this would be called from another <code>IPropertySource</code>
74 * public Object getPropertyValue(Object id) {
78 * if (id.equals(P_ID_BIBREF)) {
79 * ReferenceBase citation = descriptionElement.getCitation();
80 * ReferencePropertySource bibRefPropertySource = new ReferencePropertySource(citation);
81 * bibRefPropertySource.addPropertyChangeListener(new PropertyChangeListener() {
83 * public void propertyChange(PropertyChangeEvent evt) {
84 * descriptionElement.setCitation((ReferenceBase) evt.getNewValue());
87 * return bibRefPropertySource;
91 * Note: if <code>P_ID_BIBREF</code> in the above example is associated with an editable
92 * <code>TextPropertyDescriptor</code>, it will initalize its cell editor by calling
93 * <code>getEditableValue()</code>. If associated with a non-editable <code>PropertyDescriptor</code>,
94 * it will get its value from <code>getString()</code>.
99 public class ReferencePropertySource
implements IPropertySource
{
100 private static final Logger logger
= Logger
101 .getLogger(ReferencePropertySource
.class);
103 ReferenceBase reference
;
105 // Property unique keys
106 public static final String P_ID_SEARCH
= "P_ID_SEARCH";
107 public static final String P_ID_EDITABLECACHE
= "P_ID_EDITABLECACHE";
108 public static final String P_ID_REFERENCETYPE
= "P_ID_REFERENCETYPE";
109 public static final String P_ID_AUTHORTEAM
= "P_ID_AUTHORTEAM";
110 public static final String P_ID_YEAR
= "P_ID_YEAR";
111 public static final String P_ID_URI
= "P_ID_URI";
112 public static final String P_ID_DATEPUBLISHED
= "P_ID_DATEPUBLISHED";
113 public static final String P_ID_TITLE
= "P_ID_TITLE";
114 public static final String P_ID_INJOURNAL
= "P_ID_INJOURNAL";
115 public static final String P_ID_PAGES
= "P_ID_PAGES";
116 public static final String P_ID_SERIES
= "P_ID_SERIES";
117 public static final String P_ID_VOLUME
= "P_ID_VOLUME";
118 public static final String P_ID_EDITOR
= "P_ID_EDITOR";
119 public static final String P_ID_PLACEPUBLISHED
= "P_ID_PLACEPUBLISHED";
120 public static final String P_ID_PUBLISHER
= "P_ID_PUBLISHER";
121 public static final String P_ID_ISSN
= "P_ID_ISSN";
122 public static final String P_ID_INSTITUTION
= "P_ID_INSTITUTION";
123 public static final String P_ID_SCHOOL
= "P_ID_SCHOOL";
124 public static final String P_ID_INSERIES
= "P_ID_INSERIES";
125 public static final String P_ID_SERIESPART
= "P_ID_SERIESPART";
126 public static final String P_ID_ISBN
= "P_ID_ISBN";
127 public static final String P_ID_ORGANIZATION
= "P_ID_ORGANIZATION";
128 public static final String P_ID_PRINTEDUNIT
= "P_ID_PRINTEDUNIT";
129 public static final String P_ID_INBOOK
= "P_ID_INBOOK";
130 public static final String P_ID_INPROCEEDINGS
= "P_ID_INPROCEEDINGS";
131 public static final String P_ID_BIBTEX_ENTRYTYPE
= "P_ID_BIBTEX_ENTRYTYPE";
132 public static final String P_ID_JOURNAL
= "P_ID_JOURNAL";
133 public static final String P_ID_BOOKTITLE
= "P_ID_BOOKTITLE";
134 public static final String P_ID_CHAPTER
= "P_ID_CHAPTER";
135 public static final String P_ID_EDITION
= "P_ID_EDITION";
136 public static final String P_ID_NUMBER
= "P_ID_NUMBER";
137 public static final String P_ID_ANNOTE
= "P_ID_ANNOTE";
138 public static final String P_ID_ADDRESS
= "P_ID_ADDRESS";
139 public static final String P_ID_HOWPUBLISHED
= "P_ID_HOWPUBLISHED";
140 public static final String P_ID_REPORTTYPE
= "P_ID_REPORTTYPE";
141 public static final String P_ID_MONTH
= "P_ID_MONTH";
142 public static final String P_ID_EPRINT
= "P_ID_EPRINT";
143 public static final String P_ID_NOTE
= "P_ID_NOTE";
144 public static final String P_ID_CROSSREF
= "P_ID_CROSSREF";
145 public static final String P_ID_PROTECT_CACHE
= "P_ID_PROTECT_CACHE";
147 // Property display keys
148 public static final String P_SEARCH
= "Search";
149 public static final String P_EDITABLECACHE
= "Editable Cache";
150 public static final String P_PROTECT_CACHE
= "Protect Cache from overwriting?";
151 public static final String P_REFERENCETYPE
= "Reference Type";
152 public static final String P_AUTHORTEAM
= "Author Team (Cache)";
153 public static final String P_YEAR
= "Year";
154 public static final String P_DATEPUBLISHED
= "Date Published";
155 public static final String P_TITLE
= "Title";
156 public static final String P_INJOURNAL
= "In Journal";
157 public static final String P_VOLUME
= "Volume";
158 public static final String P_EDITION
= "Edition";
159 public static final String P_SERIES
= "Series";
160 public static final String P_PAGES
= "Pages";
161 public static final String P_EDITOR
= "Editor";
162 public static final String P_PUBLISHER
= "Publisher";
163 public static final String P_PLACEPUBLISHED
= "Place Published";
164 public static final String P_ISSN
= "ISSN";
165 public static final String P_INSTITUTION
= "Institution";
166 public static final String P_SCHOOL
= "School";
167 public static final String P_INSERIES
= "In Series";
168 public static final String P_SERIESPART
= "Series Part";
169 public static final String P_ISBN
= "ISBN";
170 public static final String P_URI
= "URI";
171 public static final String P_ORGANIZATION
= "Organization";
172 public static final String P_PRINTEDUNIT
= "Printed Unit";
173 public static final String P_INBOOK
= "In Book";
174 public static final String P_INPROCEEDINGS
= "In Proceedings";
175 public static final String P_BIBTEX_ENTRYTYPE
= "BibTeX Entry Type";
176 public static final String P_JOURNAL
= "Journal";
177 public static final String P_BOOKTITLE
= "Book Title";
178 public static final String P_CHAPTER
= "Chapter";
179 public static final String P_NUMBER
= "Number";
180 public static final String P_ANNOTE
= "Annote";
181 public static final String P_ADDRESS
= "Address";
182 public static final String P_HOWPUBLISHED
= "How Published";
183 public static final String P_REPORTTYPE
= "Report Type";
184 public static final String P_MONTH
= "Month";
185 public static final String P_EPRINT
= "E-Print";
186 public static final String P_NOTE
= "Note";
187 public static final String P_CROSSREF
= "BibTeX Crossref";
189 protected static HashMap
<Class
, String
> referenceTypeMap
= null;
191 private static final String
[] P_BIBTEX_ENTRYTYPE_MENU
= new String
[] {"ARTICLE", "BOOK", "BOOKLET", "INBOOK", "INCOLLECTION", "PROCEEDINGS", "INPROCEEDINGS", "CONFERENCE", "MANUAL", "MASTERTHESIS", "PHDTHESIS", "TECHREPORT", "UNPUBLISHED", "MISC"};
193 private static final int CACHE_NOT_PROTECTED
= 0;
194 private static final int CACHE_PROTECTED
= 1;
196 protected void populateReferenceTypes() {
198 // LinkedHashMap maintains insertion order
199 referenceTypeMap
= new LinkedHashMap
<Class
, String
>();
201 referenceTypeMap
.put(ReferenceBase
.class, "");
202 // referenceTypeMap.put(BibtexReference.class, "BibTeX Reference");
203 referenceTypeMap
.put(Article
.class, "Article");
204 referenceTypeMap
.put(Generic
.class, "Generic");
205 referenceTypeMap
.put(Patent
.class, "Patent");
206 referenceTypeMap
.put(PersonalCommunication
.class, "Personal Communication");
207 referenceTypeMap
.put(CdDvd
.class, "CD / DVD");
208 referenceTypeMap
.put(Database
.class, "Database");
209 referenceTypeMap
.put(Journal
.class, "Journal");
210 referenceTypeMap
.put(Map
.class, "Map");
211 referenceTypeMap
.put(Book
.class, "Book");
212 referenceTypeMap
.put(Proceedings
.class, "Proceedings");
213 referenceTypeMap
.put(PrintSeries
.class, "Print Series");
214 referenceTypeMap
.put(Report
.class, "Report");
215 referenceTypeMap
.put(Thesis
.class, "Thesis");
216 referenceTypeMap
.put(WebPage
.class, "Web Page");
217 referenceTypeMap
.put(BookSection
.class, "Book Section");
218 referenceTypeMap
.put(InProceedings
.class, "In Proceedings");
221 protected String
[] getReferenceTypeArray() {
222 if (referenceTypeMap
== null) {
223 populateReferenceTypes();
225 return referenceTypeMap
.values().toArray(new String
[] {});
228 protected Set
<Class
> getReferenceClassSet() {
229 return referenceTypeMap
.keySet();
232 public ReferencePropertySource(ReferenceBase reference
) {
234 // Default type of ReferenceBase is Generic
235 if (reference
== null) {
236 reference
= Generic
.NewInstance();
238 // this.reference = CdmBase.deproxy(object, clazz)reference;
239 this.reference
= reference
;
244 protected void initDescriptors() {
246 List
<String
> displayFields
= new ArrayList
<String
>();
248 // Drop-down menu to change reference type
249 displayFields
.add(P_ID_REFERENCETYPE
);
251 // ReferenceBase fields
252 displayFields
.add(P_ID_SEARCH
);
253 displayFields
.add(P_ID_EDITABLECACHE
);
254 displayFields
.add(P_ID_PROTECT_CACHE
);
255 displayFields
.add(P_ID_AUTHORTEAM
);
256 displayFields
.add(P_ID_URI
);
258 Class referenceClass
= reference
.getClass();
260 // if (reference instanceof BibtexReference) {
262 // displayFields.add(P_ID_BIBTEX_ENTRYTYPE);
263 // displayFields.add(P_ID_YEAR);
264 // displayFields.add(P_ID_JOURNAL);
265 // displayFields.add(P_ID_BOOKTITLE);
266 // displayFields.add(P_ID_CHAPTER);
267 // displayFields.add(P_ID_TITLE);
268 // displayFields.add(P_ID_SERIES);
269 // displayFields.add(P_ID_EDITION);
270 // displayFields.add(P_ID_VOLUME);
271 // displayFields.add(P_ID_NUMBER);
272 // displayFields.add(P_ID_PAGES);
273 // displayFields.add(P_ID_ANNOTE);
274 // displayFields.add(P_ID_EDITOR);
275 // displayFields.add(P_ID_INSTITUTION);
276 // displayFields.add(P_ID_SCHOOL);
277 // displayFields.add(P_ID_ORGANIZATION);
278 // displayFields.add(P_ID_PUBLISHER);
279 // displayFields.add(P_ID_ADDRESS);
280 // displayFields.add(P_ID_HOWPUBLISHED);
281 // displayFields.add(P_ID_REPORTTYPE);
282 // displayFields.add(P_ID_MONTH);
283 // displayFields.add(P_ID_EPRINT);
284 // displayFields.add(P_ID_NOTE);
285 // displayFields.add(P_ID_CROSSREF);
288 if (reference
instanceof StrictReferenceBase
) {
290 displayFields
.add(P_ID_DATEPUBLISHED
);
291 displayFields
.add(P_ID_TITLE
);
293 if (referenceClass
== Article
.class) {
294 displayFields
.add(P_ID_INJOURNAL
);
295 displayFields
.add(P_ID_PAGES
);
296 displayFields
.add(P_ID_SERIES
);
297 displayFields
.add(P_ID_VOLUME
);
300 if (referenceClass
== Generic
.class) {
301 displayFields
.add(P_ID_PAGES
);
302 displayFields
.add(P_ID_SERIES
);
303 displayFields
.add(P_ID_VOLUME
);
304 displayFields
.add(P_ID_EDITOR
);
305 // displayFields.add(P_ID_PLACEPUBLISHED);
306 // displayFields.add(P_ID_PUBLISHER);
309 if (referenceClass
== Patent
.class) {
310 // No additional fields
313 if (referenceClass
== PersonalCommunication
.class) {
314 // No additional fields
316 if (reference
instanceof PublicationBase
) {
318 displayFields
.add(P_ID_PLACEPUBLISHED
);
319 displayFields
.add(P_ID_PUBLISHER
);
321 if (referenceClass
== CdDvd
.class) {
322 // No additional fields
325 if (referenceClass
== Database
.class) {
326 // No additional fields
329 if (referenceClass
== Journal
.class) {
330 displayFields
.add(P_ID_ISSN
);
333 if (referenceClass
== Map
.class) {
334 // No additional fields
337 if (referenceClass
== PrintSeries
.class) {
338 displayFields
.add(P_ID_SERIES
);
341 if (referenceClass
== Report
.class) {
342 displayFields
.add(P_ID_INSTITUTION
);
345 if (referenceClass
== Thesis
.class) {
346 displayFields
.add(P_ID_SCHOOL
);
349 if (referenceClass
== WebPage
.class) {
350 // No additional fields
353 if (reference
instanceof PrintedUnitBase
) {
355 displayFields
.add(P_ID_EDITOR
);
356 displayFields
.add(P_ID_INSERIES
);
357 displayFields
.add(P_ID_PAGES
);
358 displayFields
.add(P_ID_SERIESPART
);
359 displayFields
.add(P_ID_VOLUME
);
361 if (referenceClass
== Book
.class) {
362 displayFields
.add(P_ID_ISBN
);
363 displayFields
.add(P_ID_EDITION
);
366 if (referenceClass
== Proceedings
.class) {
367 displayFields
.add(P_ID_ORGANIZATION
);
372 if (reference
instanceof SectionBase
) {
374 displayFields
.add(P_ID_PAGES
);
375 displayFields
.add(P_ID_PRINTEDUNIT
);
377 if (referenceClass
== BookSection
.class) {
378 displayFields
.add(P_ID_INBOOK
);
381 if (referenceClass
== InProceedings
.class) {
382 displayFields
.add(P_ID_INPROCEEDINGS
);
387 // There was a problem with duplicate descriptors in the above code
388 List
<String
> displayFieldsTemp
= new ArrayList
<String
>();
389 for (String field
: displayFields
) {
390 if (displayFieldsTemp
.contains(field
)) {
393 addDescriptor(field
);
394 displayFieldsTemp
.add(field
);
398 protected Vector
<PropertyDescriptor
> descriptors
= new Vector
<PropertyDescriptor
>();
400 protected void addDescriptor(String id
) {
403 if (id
.equals(P_ID_SEARCH
)) {
404 descriptors
.addElement(
405 new ReferenceSearchDescriptor(P_ID_SEARCH
, P_SEARCH
, getSearchType()) {
406 protected void saveReference(ReferenceBase reference
) {
407 setPropertyValue(P_ID_SEARCH
, reference
);
413 if (id
.equals(P_ID_EDITABLECACHE
)) {
414 descriptors
.addElement(
415 new TextPropertyDescriptor(P_ID_EDITABLECACHE
, P_EDITABLECACHE
));
419 if (id
.equals(P_ID_PROTECT_CACHE
)) {
420 descriptors
.addElement(
421 new ComboBoxPropertyDescriptor(P_ID_PROTECT_CACHE
, P_PROTECT_CACHE
,
422 new String
[] {"no", "yes"}));
423 // descriptors.addElement(
424 // new CheckboxPropertyDescriptor(P_ID_PROTECT_CACHE, P_PROTECT_CACHE));
428 if (id
.equals(P_ID_REFERENCETYPE
)) {
429 descriptors
.addElement(createReferenceTypeDescriptor());
432 boolean isProtectedCache
= reference
.isProtectedTitleCache();
435 if (id
.equals(P_ID_AUTHORTEAM
)) {
436 descriptors
.addElement(
438 new PropertyDescriptor(P_ID_AUTHORTEAM
, P_AUTHORTEAM
) :
439 new TextPropertyDescriptor(P_ID_AUTHORTEAM
, P_AUTHORTEAM
));
443 if (id
.equals(P_ID_YEAR
)) {
444 descriptors
.addElement(
446 new PropertyDescriptor(P_ID_YEAR
, P_YEAR
) :
447 new TextPropertyDescriptor(P_ID_YEAR
, P_YEAR
));
451 if (id
.equals(P_ID_DATEPUBLISHED
)) {
453 // TimePeriodPropertySource returns TimePeriod.getYear() - make this editable
454 if (isProtectedCache
) {
455 descriptors
.addElement(new PropertyDescriptor(
456 P_ID_DATEPUBLISHED
, P_DATEPUBLISHED
));
458 TextPropertyDescriptor yearDescriptor
= new TextPropertyDescriptor(
459 P_ID_DATEPUBLISHED
, P_DATEPUBLISHED
);
460 yearDescriptor
.setValidator(new YearValidator());
461 descriptors
.addElement(yearDescriptor
);
466 if (id
.equals(P_ID_URI
)) {
467 descriptors
.addElement(
469 new PropertyDescriptor(P_ID_URI
, P_URI
) :
470 new TextPropertyDescriptor(P_ID_URI
, P_URI
));
474 if (id
.equals(P_ID_TITLE
)) {
475 descriptors
.addElement(
477 new PropertyDescriptor(P_ID_TITLE
, P_TITLE
) :
478 new TextPropertyDescriptor(P_ID_TITLE
, P_TITLE
));
482 if (id
.equals(P_ID_INJOURNAL
)) {
483 descriptors
.addElement(
485 new PropertyDescriptor(P_ID_INJOURNAL
, P_INJOURNAL
) :
486 new TextPropertyDescriptor(P_ID_INJOURNAL
, P_INJOURNAL
));
490 if (id
.equals(P_ID_PAGES
)) {
491 descriptors
.addElement(
493 new PropertyDescriptor(P_ID_PAGES
, P_PAGES
) :
494 new TextPropertyDescriptor(P_ID_PAGES
, P_PAGES
));
498 if (id
.equals(P_ID_SERIES
)) {
499 descriptors
.addElement(
501 new PropertyDescriptor(P_ID_SERIES
, P_SERIES
) :
502 new TextPropertyDescriptor(P_ID_SERIES
, P_SERIES
));
506 if (id
.equals(P_ID_VOLUME
)) {
507 descriptors
.addElement(
509 new PropertyDescriptor(P_ID_VOLUME
, P_VOLUME
) :
510 new TextPropertyDescriptor(P_ID_VOLUME
, P_VOLUME
));
514 if (id
.equals(P_ID_EDITOR
)) {
515 descriptors
.addElement(
517 new PropertyDescriptor(P_ID_EDITOR
, P_EDITOR
) :
518 new TextPropertyDescriptor(P_ID_EDITOR
, P_EDITOR
));
522 if (id
.equals(P_ID_EDITION
)) {
523 descriptors
.addElement(
525 new PropertyDescriptor(P_ID_EDITION
, P_EDITION
) :
526 new TextPropertyDescriptor(P_ID_EDITION
, P_EDITION
));
530 if (id
.equals(P_ID_PLACEPUBLISHED
)) {
531 descriptors
.addElement(
533 new PropertyDescriptor(P_ID_PLACEPUBLISHED
, P_PLACEPUBLISHED
) :
534 new TextPropertyDescriptor(P_ID_PLACEPUBLISHED
, P_PLACEPUBLISHED
));
538 if (id
.equals(P_ID_PUBLISHER
)) {
539 descriptors
.addElement(
541 new PropertyDescriptor(P_ID_PUBLISHER
, P_PUBLISHER
) :
542 new TextPropertyDescriptor(P_ID_PUBLISHER
, P_PUBLISHER
));
546 if (id
.equals(P_ID_ISSN
)) {
547 descriptors
.addElement(
549 new PropertyDescriptor(P_ID_ISSN
, P_ISSN
) :
550 new TextPropertyDescriptor(P_ID_ISSN
, P_ISSN
));
554 if (id
.equals(P_ID_INSTITUTION
)) {
555 descriptors
.addElement(
557 new PropertyDescriptor(P_ID_INSTITUTION
, P_INSTITUTION
) :
558 new TextPropertyDescriptor(P_ID_INSTITUTION
, P_INSTITUTION
));
562 if (id
.equals(P_ID_SCHOOL
)) {
563 descriptors
.addElement(
565 new PropertyDescriptor(P_ID_SCHOOL
, P_SCHOOL
) :
566 new TextPropertyDescriptor(P_ID_SCHOOL
, P_SCHOOL
));
570 if (id
.equals(P_ID_INSERIES
)) {
571 descriptors
.addElement(
573 new PropertyDescriptor(P_ID_INSERIES
, P_INSERIES
) :
574 new TextPropertyDescriptor(P_ID_INSERIES
, P_INSERIES
));
578 if (id
.equals(P_ID_SERIESPART
)) {
579 descriptors
.addElement(
581 new PropertyDescriptor(P_ID_SERIESPART
, P_SERIESPART
) :
582 new TextPropertyDescriptor(P_ID_SERIESPART
, P_SERIESPART
));
586 if (id
.equals(P_ID_ISBN
)) {
587 descriptors
.addElement(
589 new PropertyDescriptor(P_ID_ISBN
, P_ISBN
) :
590 new TextPropertyDescriptor(P_ID_ISBN
, P_ISBN
));
594 if (id
.equals(P_ID_ORGANIZATION
)) {
595 descriptors
.addElement(
597 new PropertyDescriptor(P_ID_ORGANIZATION
, P_ORGANIZATION
) :
598 new TextPropertyDescriptor(P_ID_ORGANIZATION
, P_ORGANIZATION
));
602 if (id
.equals(P_ID_PRINTEDUNIT
)) {
603 descriptors
.addElement(
605 new PropertyDescriptor(P_ID_PRINTEDUNIT
, P_PRINTEDUNIT
) :
606 new TextPropertyDescriptor(P_ID_PRINTEDUNIT
, P_PRINTEDUNIT
));
610 if (id
.equals(P_ID_INBOOK
)) {
611 descriptors
.addElement(
613 new PropertyDescriptor(P_ID_INBOOK
, P_INBOOK
) :
614 new TextPropertyDescriptor(P_ID_INBOOK
, P_INBOOK
));
618 if (id
.equals(P_ID_BIBTEX_ENTRYTYPE
)) {
619 descriptors
.addElement(
621 new PropertyDescriptor(P_ID_BIBTEX_ENTRYTYPE
, P_BIBTEX_ENTRYTYPE
) :
622 new ComboBoxPropertyDescriptor(P_ID_BIBTEX_ENTRYTYPE
, P_BIBTEX_ENTRYTYPE
, P_BIBTEX_ENTRYTYPE_MENU
));
627 * The default implementation of <code>ReferencePropertySource</code> will
628 * search all <code>ReferenceBase</code> classes.
632 protected int getSearchType() {
633 return IReferenceSearch
.BIBREF
;
637 * The default implementation of <code>ReferencePropertySource</code> will show
638 * a drop-down of reference types, but subclasses may want to show a non-editable
639 * text descriptor of the reference type.
641 protected PropertyDescriptor
createReferenceTypeDescriptor() {
642 return new ComboBoxPropertyDescriptor(
643 P_ID_REFERENCETYPE
, P_REFERENCETYPE
, getReferenceTypeArray());
647 * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
649 public Object
getEditableValue() {
650 return CdmUtils
.Nz(reference
.getTitleCache());
654 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
656 public IPropertyDescriptor
[] getPropertyDescriptors() {
657 return (IPropertyDescriptor
[]) descriptors
.toArray(
658 new IPropertyDescriptor
[descriptors
.size()]);
662 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
664 public Object
getPropertyValue(Object id
) {
666 // Reference Type: get integer index of drop-down menu
667 if (id
.equals(P_ID_REFERENCETYPE
)) {
668 Class referenceClass
= reference
.getClass();
670 // for (Class clazz : referenceTypeMap.keySet()) {
671 for (Class clazz
: getReferenceClassSet()) {
672 if (clazz
== referenceClass
) {
677 logger
.warn("Reference class type " + referenceClass
+ " not in reference type menu.");
682 if (id
.equals(P_ID_EDITABLECACHE
)) {
683 return (CdmUtils
.Nz(reference
.getTitleCache()));
687 if (id
.equals(P_ID_PROTECT_CACHE
)) {
688 if (reference
.isProtectedTitleCache()) {
689 return CACHE_PROTECTED
;
691 return CACHE_NOT_PROTECTED
;
693 // return reference.isProtectedTitleCache();
696 // Author Team: for now, just edit the cache
697 // TODO AuthorTeamPropertySource
698 if (id
.equals(P_ID_AUTHORTEAM
)) {
699 TeamOrPersonBase authorTeam
= reference
.getAuthorTeam();
701 if (authorTeam
== null) {
705 return CdmUtils
.Nz(authorTeam
.getTitleCache());
709 if (id
.equals(P_ID_YEAR
)) {
710 return CdmUtils
.Nz(reference
.getYear());
714 if (id
.equals(P_ID_URI
)) {
715 return CdmUtils
.Nz(reference
.getUri());
719 if (id
.equals(P_ID_DATEPUBLISHED
)) {
720 TimePeriod datePublished
= (TimePeriod
) invokeMethod(reference
, "getDatePublished", null);
722 if (datePublished
== null) {
723 datePublished
= TimePeriod
.NewInstance();
726 if (reference
.isProtectedTitleCache()) {
727 return CdmUtils
.Nz(reference
.getYear());
730 TimePeriodPropertySource timePeriodPropertySource
=
731 new TimePeriodPropertySource(datePublished
);
732 timePeriodPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
733 public void propertyChange(PropertyChangeEvent evt
) {
734 if (reference
instanceof StrictReferenceBase
&& evt
.getNewValue() instanceof TimePeriod
) {
735 ((StrictReferenceBase
) reference
).setDatePublished((TimePeriod
) evt
.getNewValue());
739 return timePeriodPropertySource
;
742 // Title: used by StrictReferenceBase
743 if (id
.equals(P_ID_TITLE
)) {
744 String title
= (String
) invokeMethod(reference
, "getTitle", null);
745 return CdmUtils
.Nz(title
);
748 // InJournal: return an instance of ReferencePropertySource
749 if (id
.equals(P_ID_INJOURNAL
)) {
751 Journal inJournal
= (Journal
) invokeMethod(reference
, "getInJournal", null);
753 if (inJournal
== null) {
754 inJournal
= Journal
.NewInstance();
757 if (reference
.isProtectedTitleCache()) {
758 return inJournal
.getTitleCache();
761 ReferencePropertySource bibRefPropertySource
= new SingleRefTypePropertySource(
762 inJournal
, SingleRefTypePropertySource
.JOURNAL
);
763 bibRefPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
764 public void propertyChange(PropertyChangeEvent evt
) {
765 if (reference
instanceof Article
&& evt
.getNewValue() instanceof Journal
) {
766 ((Article
) reference
).setInJournal((Journal
) evt
.getNewValue());
770 return bibRefPropertySource
;
774 if (id
.equals(P_ID_PAGES
)) {
775 String pages
= (String
) invokeMethod(reference
, "getPages", null);
776 return CdmUtils
.Nz(pages
);
780 if (id
.equals(P_ID_SERIES
)) {
781 String series
= (String
) invokeMethod(reference
, "getSeries", null);
782 return CdmUtils
.Nz(series
);
786 if (id
.equals(P_ID_VOLUME
)) {
787 String volume
= (String
) invokeMethod(reference
, "getVolume", null);
788 return CdmUtils
.Nz(volume
);
792 if (id
.equals(P_ID_EDITOR
)) {
793 String editor
= (String
) invokeMethod(reference
, "getEditor", null);
794 return CdmUtils
.Nz(editor
);
798 if (id
.equals(P_ID_EDITION
)) {
799 String edition
= (String
) invokeMethod(reference
, "getEdition", null);
800 return CdmUtils
.Nz(edition
);
804 if (id
.equals(P_ID_PLACEPUBLISHED
)) {
805 String placePublished
= (String
) invokeMethod(reference
, "getPlacePublished", null);
806 return CdmUtils
.Nz(placePublished
);
810 if (id
.equals(P_ID_PUBLISHER
)) {
811 String publisher
= (String
) invokeMethod(reference
, "getPublisher", null);
812 return CdmUtils
.Nz(publisher
);
816 if (id
.equals(P_ID_ISSN
)) {
817 String issn
= (String
) invokeMethod(reference
, "getIssn", null);
818 return CdmUtils
.Nz(issn
);
822 if (id
.equals(P_ID_INSTITUTION
)) {
823 String institution
= (String
) invokeMethod(reference
, "getInstitution", null);
824 return CdmUtils
.Nz(institution
);
828 if (id
.equals(P_ID_INSERIES
)) {
833 if (id
.equals(P_ID_ISBN
)) {
834 String isbn
= (String
) invokeMethod(reference
, "getIsbn", null);
835 return CdmUtils
.Nz(isbn
);
839 if (id
.equals(P_ID_ORGANIZATION
)) {
840 String organization
= (String
) invokeMethod(reference
, "getOrganization", null);
841 return CdmUtils
.Nz(organization
);
845 if (id
.equals(P_ID_INBOOK
)) {
847 Book inBook
= (Book
) invokeMethod(reference
, "getInBook", null);
849 if (inBook
== null) {
850 inBook
= Book
.NewInstance();
853 ReferencePropertySource bibRefPropertySource
= new SingleRefTypePropertySource(
854 inBook
, SingleRefTypePropertySource
.BOOK
);
855 bibRefPropertySource
.addPropertyChangeListener(new PropertyChangeListener() {
856 public void propertyChange(PropertyChangeEvent evt
) {
857 if (reference
instanceof BookSection
&& evt
.getNewValue() instanceof Book
) {
858 ((BookSection
) reference
).setInBook((Book
) evt
.getNewValue());
862 return bibRefPropertySource
;
866 if (id
.equals(P_ID_BIBTEX_ENTRYTYPE
)) {
874 * Executes <code>methodName</code> on <code>obj</code> with
875 * the argument <code>arg</code>.
877 * On failure, returns <code>null</code>.
879 * NOTE: both <code>Class.getMethod()</code> and <code>Method.invoke()</code>
880 * can be called with the <code>Object... args</code> approach, which allows
881 * the user to pass in a varying number of arguments. To keep it simple, and since
882 * this is usually only getters or setters, we are using only one argument.
888 private Object
invokeMethod(Object obj
, String methodName
, Object arg
) {
890 Method method
= null;
892 method
= obj
.getClass().getMethod(methodName
);
893 return method
.invoke(obj
);
895 method
= obj
.getClass().getMethod(methodName
, arg
.getClass());
896 return method
.invoke(obj
, arg
);
898 } catch (SecurityException e
) {
899 logger
.error(e
.getMessage());
900 } catch (IllegalArgumentException e
) {
901 logger
.error(e
.getMessage());
902 } catch (NoSuchMethodException e
) {
903 logger
.error(e
.getMessage());
904 } catch (IllegalAccessException e
) {
905 logger
.error(e
.getMessage());
906 } catch (InvocationTargetException e
) {
907 logger
.error(e
.getMessage());
913 * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
915 public boolean isPropertySet(Object id
) {
920 * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
922 public void resetPropertyValue(Object id
) {}
925 * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
927 public void setPropertyValue(Object id
, Object value
) {
930 if (id
.equals(P_ID_SEARCH
)) {
931 if (value
instanceof ReferenceBase
) {
932 reference
= (ReferenceBase
) value
;
937 if (id
.equals(P_ID_PROTECT_CACHE
)) {
938 if (((Integer
) value
).intValue() == CACHE_PROTECTED
) {
939 reference
.setProtectedTitleCache(true);
941 reference
.setProtectedTitleCache(false);
943 // reference.setProtectedTitleCache(((Boolean) value).booleanValue());
947 if (id
.equals(P_ID_REFERENCETYPE
)) {
949 // NOTE: this code will only be reached if user actually changes choice in reference type
950 // dropdown list, not if focus is merely gained and lost without changing the value
952 // Grab reference's title cache
953 String oldTitleCache
= reference
.getTitleCache();
955 // Get reference's class
958 menuIndex
= ((Integer
) value
).intValue();
959 } catch (ClassCastException e
) {
960 // Leave method / no change on class cast error
961 logger
.error(e
.getMessage());
964 Class referenceClass
= (Class
)(getReferenceClassSet().toArray())[menuIndex
];
966 // Make a new reference using the class
967 reference
= makeNewReference(referenceClass
);
969 // Set new reference's title cache
970 reference
.setTitleCache(oldTitleCache
);
974 if (id
.equals(P_ID_AUTHORTEAM
)) {
975 TeamOrPersonBase authorTeam
= reference
.getAuthorTeam();
976 if (authorTeam
== null) {
977 authorTeam
= Team
.NewInstance();
978 reference
.setAuthorTeam(authorTeam
);
981 authorTeam
.setTitleCache((String
) value
);
982 } catch (ClassCastException e
) {
983 // Leave method / no change on class cast error
984 logger
.error(e
.getMessage());
990 if (id
.equals(P_ID_URI
)) {
991 String uri
= (String
) value
;
992 reference
.setUri(uri
);
995 // Year - only set directly by Bibtex refs
996 if (id
.equals(P_ID_YEAR
)) {
997 String year
= (String
) value
;
998 if (reference
instanceof BibtexReference
) {
999 ((BibtexReference
) reference
).setYear(year
);
1003 // Title: used by StrictReferenceBase
1004 if (id
.equals(P_ID_TITLE
)) {
1005 String title
= null;
1007 title
= (String
) value
;
1008 } catch (ClassCastException e
) {
1009 // Leave method / no change on class cast error
1010 logger
.error(e
.getMessage());
1013 invokeMethod(reference
, "setTitle", title
);
1017 if (id
.equals(P_ID_PAGES
)) {
1018 invokeMethod(reference
, "setPages", (String
) value
);
1022 if (id
.equals(P_ID_SERIES
)) {
1023 invokeMethod(reference
, "setSeries", (String
) value
);
1027 if (id
.equals(P_ID_VOLUME
)) {
1028 invokeMethod(reference
, "setVolume", (String
) value
);
1032 if (id
.equals(P_ID_EDITOR
)) {
1033 invokeMethod(reference
, "setEditor", (String
) value
);
1037 if (id
.equals(P_ID_EDITION
)) {
1038 invokeMethod(reference
, "setEdition", (String
) value
);
1042 if (id
.equals(P_ID_PLACEPUBLISHED
)) {
1043 invokeMethod(reference
, "setPlacePublished", (String
) value
);
1047 if (id
.equals(P_ID_PUBLISHER
)) {
1048 invokeMethod(reference
, "setPublisher", (String
) value
);
1052 if (id
.equals(P_ID_ISSN
)) {
1053 invokeMethod(reference
, "setIssn", (String
) value
);
1057 if (id
.equals(P_ID_INSTITUTION
)) {
1058 invokeMethod(reference
, "setInstitution", (String
) value
);
1062 if (id
.equals(P_ID_ISBN
)) {
1063 invokeMethod(reference
, "setIsbn", (String
) value
);
1067 if (id
.equals(P_ID_ORGANIZATION
)) {
1068 invokeMethod(reference
, "setOrganization", (String
) value
);
1072 if (id
.equals(P_ID_INBOOK
)) {
1073 Book inBook
= (Book
) invokeMethod(reference
, "getInBook", null);
1074 if (inBook
== null) {
1075 inBook
= Book
.NewInstance();
1076 invokeMethod(reference
, "setInBook", inBook
);
1078 inBook
.setTitleCache((String
) value
);
1082 if (id
.equals(P_ID_DATEPUBLISHED
)) {
1084 if (!(reference
instanceof StrictReferenceBase
)) {
1088 if (value
instanceof String
) {
1089 String year
= (String
) value
;
1090 TimePeriod yearsPublished
= null;
1092 // If not empty, format is either "xxxx" or "xxxx-xxxx", thanks to validator
1093 if (!year
.equals("")) {
1095 // Convert to a TimePeriod
1096 yearsPublished
= TimeUtil
.convertTimePeriod(year
);
1098 // Update reference's dataPublished field
1099 TimePeriod datePublished
= ((StrictReferenceBase
) reference
).getDatePublished();
1101 if (datePublished
== null) {
1102 ((StrictReferenceBase
) reference
).setDatePublished(yearsPublished
);
1105 // Any months or days should be left as is - only update years
1106 datePublished
.setStartYear(yearsPublished
.getStartYear());
1107 datePublished
.setEndYear(yearsPublished
.getEndYear());
1110 ((StrictReferenceBase
) reference
).setDatePublished(null);
1118 if (id
.equals(P_ID_EDITABLECACHE
)) {
1119 reference
.setTitleCache((String
) value
);
1121 reference
.setTitleCache(reference
.generateTitle(), reference
.isProtectedTitleCache());
1124 propertyChangeSupport
.firePropertyChange(Resources
.PROPERTY_SHEET_CHANGE
, null, reference
);
1128 * Takes a <code>referenceClass</code>, then executes either its <code>NewInstance()</code>
1129 * method or its constructor. Puts the resulting object in <code>this.reference</code> and
1132 * If unsuccessful, <code>this.reference</code> keeps its old value and is returned.
1133 * @param referenceClass
1136 private ReferenceBase
makeNewReference(Class referenceClass
) {
1138 // Check whether the class has a method "NewInstance()";
1140 Method method
= referenceClass
.getMethod("NewInstance", null);
1141 reference
= (ReferenceBase
) method
.invoke(null, null);
1142 } catch (NoSuchMethodException e
) {
1144 // If not, use its constructor
1145 Constructor constructor
= referenceClass
.getConstructor(null);
1146 reference
= (ReferenceBase
) constructor
.newInstance(null);
1147 } catch (SecurityException e1
) {
1148 e1
.printStackTrace();
1149 } catch (NoSuchMethodException e1
) {
1150 e1
.printStackTrace();
1151 } catch (IllegalArgumentException e1
) {
1152 e1
.printStackTrace();
1153 } catch (InstantiationException e1
) {
1154 e1
.printStackTrace();
1155 } catch (IllegalAccessException e1
) {
1156 e1
.printStackTrace();
1157 } catch (InvocationTargetException e1
) {
1158 e1
.printStackTrace();
1160 } catch (SecurityException e
) {
1161 e
.printStackTrace();
1162 } catch (IllegalArgumentException e
) {
1163 e
.printStackTrace();
1164 } catch (IllegalAccessException e
) {
1165 e
.printStackTrace();
1166 } catch (InvocationTargetException e
) {
1167 e
.printStackTrace();
1173 public String
toString() {
1174 return CdmUtils
.Nz(reference
.getTitleCache());
1177 private PropertyChangeSupport propertyChangeSupport
= new PropertyChangeSupport(this);
1179 public void addPropertyChangeListener(
1180 PropertyChangeListener listener
) {
1181 propertyChangeSupport
.addPropertyChangeListener(listener
);