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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.reference
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.List
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.joda
.time
.DateTime
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
23 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
24 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CacheRelevance
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.DoiWithLabelElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.LsidWithExceptionLabelElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.VerbatimTimePeriodElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.mvc
.element
.DateElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.common
.ExternalLinksSection
;
40 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
44 * @created Mar 2, 2010
46 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
47 implements IErrorIntolerableElement
, IExceptionHandler
{
49 boolean isNomenclaturalReference
= false;
51 private ToggleableTextElement toggleableAbbrevCache
;
53 private TextWithLabelElement text_edition
;
54 private TextWithLabelElement text_editor
;
55 private TextWithLabelElement text_isbn
;
56 private TextWithLabelElement text_issn
;
57 private TextWithLabelElement text_organisation
;
58 private TextWithLabelElement text_pages
;
59 private TextWithLabelElement text_placePublished
;
60 private TextWithLabelElement text_placePublished2
;
61 private TextWithLabelElement text_publisher
;
62 private TextWithLabelElement text_publisher2
;
63 private TextWithLabelElement text_referenceAbstract
;
64 private TextWithLabelElement text_series
;
65 // private TextWithLabelElement text_seriesPart;
66 private TextWithLabelElement text_volume
;
67 private TextWithLabelElement text_abbrevTitle
;
68 private TextWithLabelElement text_title
;
69 private DoiWithLabelElement text_doi
;
70 private UriWithLabelElement text_uri
;
71 private LsidWithExceptionLabelElement text_lsid
;
72 private DateElement text_accessed
;
73 private EntitySelectionElement
<TeamOrPersonBase
> selection_authorTeam
;
74 private VerbatimTimePeriodElement element_timePeriod
;
75 private EntitySelectionElement
<Reference
> selection_inReference
;
76 private EntitySelectionElement
<Institution
> selection_institution
;
77 private EnumComboElement
<ReferenceType
> combo_referenceType
;
78 private ExternalLinksSection externalLinks
;
79 private EntitySelectionElement
<Reference
> selection_inSeries
;
81 private void registerCacheElements() {
82 registerCacheRelevance(text_edition
, toggleable_cache
, toggleableAbbrevCache
);
83 registerCacheRelevance(text_pages
, toggleable_cache
);
84 registerCacheRelevance(text_series
, toggleable_cache
, toggleableAbbrevCache
);
85 registerCacheRelevance(text_volume
, toggleable_cache
, toggleableAbbrevCache
);
86 registerCacheRelevance(text_abbrevTitle
, toggleableAbbrevCache
);
87 registerCacheRelevance(text_title
, toggleable_cache
);
88 registerCacheRelevance(text_accessed
, toggleable_cache
, toggleableAbbrevCache
);
89 registerCacheRelevance(selection_authorTeam
, toggleable_cache
, toggleableAbbrevCache
);
90 registerCacheRelevance(element_timePeriod
, toggleable_cache
, toggleableAbbrevCache
);
91 registerCacheRelevance(selection_inReference
, toggleable_cache
, toggleableAbbrevCache
);
92 registerCacheRelevance(combo_referenceType
, toggleable_cache
, toggleableAbbrevCache
);
96 * Constructor for ReferenceBaseDetailElement.
98 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
99 ICdmFormElement formElement
, int style
) {
100 super(cdmFormFactory
, formElement
);
103 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
104 ICdmFormElement formElement
, boolean isNomenclaturalReference
, int style
) {
105 this(cdmFormFactory
, formElement
, style
);
106 this.isNomenclaturalReference
= isNomenclaturalReference
;
109 public boolean isNomenclaturalReference() {
110 return isNomenclaturalReference
;
113 public void setNomenclaturalReference(boolean isNomenclaturalReference
) {
114 this.isNomenclaturalReference
= isNomenclaturalReference
;
118 protected void createControls(ICdmFormElement formElement
,
119 Reference entity
, int style
) {
120 setWarnForReferencingObjects(formElement
);
121 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
122 "Reference Cache", entity
.getTitleCache(),
123 entity
.isProtectedTitleCache(), style
);
125 toggleableAbbrevCache
= formFactory
.createToggleableTextField(formElement
,
126 "Nomencl. Cache", entity
.getAbbrevTitleCache(),
127 entity
.isProtectedAbbrevTitleCache(), CacheRelevance
.CACHE2
, style
);
129 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
132 combo_referenceType
.setSelection(entity
.getType());
135 text_title
= formFactory
.createMultiLineTextWithLabel(formElement
,
137 text_title
.setText(entity
.getTitle());
139 text_abbrevTitle
= formFactory
.createTextWithLabelElement(formElement
,
140 "Nomencl. Title", entity
.getAbbrevTitle(), style
);
141 ReferenceType referenceType
= entity
.getType();
143 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) ) {
144 if (isNomenclaturalReference
){
145 selection_authorTeam
= formFactory
146 .createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
147 formElement
, "Author",
148 entity
.getAuthorship(),
149 EntitySelectionElement
.ALL
, style
);
151 selection_authorTeam
= formFactory
152 .createSelectionElement(TeamOrPersonBase
.class,
153 formElement
, "Author",
154 entity
.getAuthorship(),
155 EntitySelectionElement
.ALL
, style
);
159 if (referenceType
!= null) {
161 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
163 if (referenceType
.equals(ReferenceType
.Generic
)) {
164 createGenericControls(this, entity
, SWT
.NULL
);
165 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
168 if (referenceType
.isPrintedUnit()) {
169 createPrintedUnitControls(this, referenceType
, entity
,
172 // if (referenceType.equals(ReferenceType.Proceedings)) {
173 // text_isbn = formFactory.createTextWithLabelElement(this, "ISBN",
174 // entity.getIsbn(), style);
176 if (referenceType
.isPublication()) {
177 createPublicationControls(this, referenceType
, entity
,
180 if (referenceType
.isVolumeReference()) {
181 createVolumeControls(this, entity
, SWT
.NULL
);
183 if (referenceType
.isSection()) {
184 createSectionControls(this, entity
, SWT
.NULL
);
190 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
)){
191 element_timePeriod
= formFactory
.createVerbatimTimePeriodElement(formElement
,
192 "Date Published", entity
.getDatePublished(), style
);
195 createUri(this, entity
, SWT
.NULL
);
197 // externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
198 // externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
199 // externalLinks.setEntity(entity);
200 // externalLinks.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
201 // externalLinks.setEmptySectionString("No links yet.");
203 if(referenceType
!= null && (!referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) && !referenceType
.equals(ReferenceType
.PersonalCommunication
))) {
204 text_doi
= formFactory
.createDoiWithLabelElement(formElement
, "DOI", entity
.getDoi(), style
);
207 createLsid(this, entity
, SWT
.NULL
);
208 createAbstract(this, entity
, SWT
.NULL
);
210 registerCacheElements();
212 handleToggleableAbbrevTitleField();
213 handleToggleableCacheField();
217 private void createWebPageControls(ICdmFormElement element
, Reference reference
, int style
) {
218 DateTime accessed
= reference
.getAccessed();
220 text_accessed
= formFactory
.createDateElement(element
, "Accessed", accessed
, style
, false);
224 protected void updateContent() {
225 if (getEntity() == null) {
226 setEntity(ReferenceFactory
.newGeneric());
229 super.updateContent();
231 // enable elements according to state of cache protection
232 toggleable_cache
.setCacheEnabled(getEntity().isProtectedTitleCache());
233 toggleableAbbrevCache
.setCacheEnabled(getEntity().isProtectedAbbrevTitleCache());
237 * Creates an in reference for reference types that do hav this.
239 private void createInReferenceByType(ICdmFormElement element
,
240 ReferenceType referenceType
, Reference reference
, int style
) {
244 switch (referenceType
) {
253 label
= "Proceedings";
259 label
= "In Reference";
262 boolean createInReferenceWidget
= !ReferenceType
.inReferenceContraints(referenceType
).isEmpty();
264 if (createInReferenceWidget
) {
265 selection_inReference
= formFactory
266 .createSelectionElement(Reference
.class,
268 reference
.getInReference(),
269 EntitySelectionElement
.ALL
, style
);
274 * Creates additional controls to edit a generic reference
276 private void createGenericControls(ICdmFormElement element
,
277 Reference reference
, int style
) {
280 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
281 reference
.getEditor(), style
);
284 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
285 reference
.getSeriesPart(), style
);
288 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
289 reference
.getVolume(), style
);
292 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
293 reference
.getPages(), style
);
297 * Creates additional controls to edit a publication
299 private void createPublicationControls(ICdmFormElement element
,
300 ReferenceType referenceType
, Reference reference
, int style
) {
303 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
304 "Place Published", reference
.getPlacePublished(), style
);
307 text_publisher
= formFactory
.createTextWithLabelElement(element
,
308 "Publisher", reference
.getPublisher(), style
);
311 text_placePublished2
= formFactory
.createTextWithLabelElement(element
,
312 "Second Place Published", reference
.getPlacePublished2(), style
);
315 text_publisher2
= formFactory
.createTextWithLabelElement(element
,
316 "Second Publisher", reference
.getPublisher2(), style
);
318 if (referenceType
.equals(ReferenceType
.Journal
)) {
320 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
321 reference
.getIssn(), style
);
324 if (referenceType
.equals(ReferenceType
.Report
)) {
326 selection_institution
= formFactory
327 .createSelectionElement(Institution
.class,
328 element
, "Institution",
329 reference
.getInstitution(),
330 EntitySelectionElement
.ALL
, style
);
333 if (referenceType
.equals(ReferenceType
.Thesis
)) {
335 selection_institution
= formFactory
336 .createSelectionElement(Institution
.class,
338 reference
.getSchool(),
339 EntitySelectionElement
.ALL
, style
);
342 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
344 text_organisation
= formFactory
.createTextWithLabelElement(element
,
345 "Organisation", reference
.getOrganization(), style
);
350 * Creates additional controls to edit a section
352 private void createSectionControls(ICdmFormElement element
,
353 Reference reference
, int style
) {
355 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
356 reference
.getPages(), style
);
360 * Creates additional controls to edit a volume
362 private void createVolumeControls(ICdmFormElement element
,
363 Reference reference
, int style
) {
365 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
366 reference
.getVolume(), style
);
368 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
369 reference
.getSeriesPart(), style
);
372 private void createPrintedUnitControls(ICdmFormElement element
,
373 ReferenceType referenceType
, Reference reference
, int style
) {
375 //handled in generic in-Reference part
378 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
379 reference
.getEditor(), style
);
382 text_seriesPart = formFactory.createTextWithLabelElement(element,
383 "Series", reference.getSeriesPart(), style);
385 if (referenceType
.equals(ReferenceType
.Book
)) {
387 text_edition
= formFactory
.createTextWithLabelElement(element
,
388 "Edition", reference
.getEdition(), style
);
392 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
393 reference
.getIsbn(), style
);
396 private void createAbstract(ICdmFormElement element
,
397 Reference reference
, int style
) {
399 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
400 element
, "Reference Abstract", 100, style
);
401 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
404 private void createLsid(ICdmFormElement element
,
405 Reference reference
, int style
) {
406 text_lsid
= formFactory
.createLsidWithExceptionLabelElement(element
, "LSID",
407 reference
.getLsid(), style
);
410 private void createUri(ICdmFormElement element
,
411 Reference reference
, int style
) {
413 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
414 reference
.getUri(), style
);
415 if (reference
.isDynamic()){
416 createWebPageControls(element
, reference
, style
);
421 public void handleEvent(Object eventSource
) {
422 if (eventSource
== combo_referenceType
) {
423 getEntity().setType(combo_referenceType
.getSelection());
425 //this is needed for the "new" wizards in order to redraw correctly
426 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
427 } else if (eventSource
== element_timePeriod
) {
428 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
432 else if (eventSource
== selection_authorTeam
) {
433 getEntity().setAuthorship(
434 selection_authorTeam
.getEntity());
435 } else if (eventSource
== selection_inReference
) {
436 getEntity().setInReference(selection_inReference
.getSelection());
437 } else if (eventSource
== selection_inSeries
) {
438 getEntity().setInReference(selection_inSeries
.getSelection());
439 } else if (eventSource
== selection_institution
) {
440 getEntity().setInstitution(selection_institution
.getSelection());
444 else if (eventSource
== toggleable_cache
) {
445 handleToggleableCacheField();
447 else if (eventSource
== toggleableAbbrevCache
) {
448 handleToggleableAbbrevTitleField();
449 } else if (eventSource
== text_edition
) {
450 getEntity().setEdition(text_edition
.getText());
451 } else if (eventSource
== text_editor
) {
452 getEntity().setEditor(text_editor
.getText());
453 } else if (eventSource
== text_isbn
) {
454 getEntity().setIsbn(text_isbn
.getText());
455 } else if (eventSource
== text_issn
) {
456 getEntity().setIssn(text_issn
.getText());
457 } else if (eventSource
== text_organisation
) {
458 getEntity().setOrganization(text_organisation
.getText());
459 } else if (eventSource
== text_pages
) {
460 getEntity().setPages(text_pages
.getText());
461 } else if (eventSource
== text_placePublished
) {
462 getEntity().setPlacePublished(text_placePublished
.getText());
463 } else if (eventSource
== text_placePublished2
) {
464 getEntity().setPlacePublished2(text_placePublished2
.getText());
465 }else if (eventSource
== text_publisher
) {
466 getEntity().setPublisher(text_publisher
.getText());
467 } else if (eventSource
== text_publisher2
) {
468 getEntity().setPublisher2(text_publisher2
.getText());
469 }else if (eventSource
== text_referenceAbstract
) {
470 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
471 } else if (eventSource
== text_series
) {
472 getEntity().setSeriesPart(text_series
.getText());
473 } else if (eventSource
== text_title
) {
474 getEntity().setTitle(text_title
.getText());
475 if (!toggleable_cache
.isCacheEnabled()){
476 toggleable_cache
.setText(getEntity().generateTitle());
478 } else if (eventSource
== text_abbrevTitle
) {
479 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
480 if (!toggleableAbbrevCache
.isCacheEnabled()){
481 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
483 } else if (eventSource
== text_uri
) {
484 getEntity().setUri(text_uri
.parseText());
485 } else if (eventSource
== text_lsid
) {
486 getEntity().setLsid(text_lsid
.parseText());
487 } else if (eventSource
== text_volume
) {
488 getEntity().setVolume(text_volume
.getText());
489 }else if (eventSource
== text_doi
) {
490 getEntity().setDoi(text_doi
.parseText());
491 }else if (text_accessed
!= null && eventSource
== text_accessed
.getController()) {
492 getEntity().setAccessed(text_accessed
.getController().getDateTime());
495 if (eventSource
!= text_title
&& eventSource
!= text_abbrevTitle
) {
496 // set abbrev title cache to null to force new generation
497 // for the standard title cache this is done by a PropertyChangeListener registered
498 // in IdentifiableEntity.initListeners()
499 if(!getEntity().isProtectedAbbrevTitleCache()){
500 getEntity().setAbbrevTitleCache(null, getEntity().isProtectedAbbrevTitleCache());
502 if(!getEntity().isProtectedTitleCache()){
503 getEntity().setTitleCache(null, getEntity().isProtectedTitleCache());
506 toggleable_cache
.setText(getEntity().getTitleCache());
507 toggleableAbbrevCache
.setText(getEntity().getAbbrevTitleCache());
510 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
514 public void updateToggleableCacheField() {
515 if (!getEntity().isProtectedTitleCache()) {
516 toggleable_cache
.setText(getEntity().generateTitle());
518 if (!getEntity().isProtectedAbbrevTitleCache()) {
519 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
523 protected void handleToggleableAbbrevTitleField() {
524 getEntity().setAbbrevTitleCache(
525 toggleableAbbrevCache
.getText(), toggleableAbbrevCache
.getState());
526 updateToggleableCacheField();
527 updateCacheRelevance();
531 public void handleException(CdmPropertyChangeEvent event
) {
532 exceptionOccurred(event
);
536 public void clearException() {
537 exceptionOccurred(null);
540 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<>();
543 public void addExceptionHandler(IExceptionHandler handler
) {
544 exceptionHandlers
.add(handler
);
548 public void removeExceptionHandler(IExceptionHandler handler
) {
549 exceptionHandlers
.remove(handler
);
553 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
554 for (IExceptionHandler handler
: exceptionHandlers
) {
556 handler
.clearException();
558 handler
.handleException(event
);
564 protected void handleToggleableCacheField() {
565 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
566 updateToggleableCacheField();
567 updateCacheRelevance();
570 protected void setIrrelevantReferenceDetail(boolean abbrev
){
572 List
<Object
> except
= new ArrayList
<>();
574 except
.addAll( Arrays
.asList(new Object
[] { toggleable_cache
, toggleableAbbrevCache
, text_editor
, text_isbn
, text_issn
, text_organisation
, text_pages
, text_placePublished
,text_placePublished2
, text_publisher
, text_publisher2
, text_referenceAbstract
, text_uri
, selection_institution
}));
577 except
.add(text_title
);
579 except
.add(text_abbrevTitle
);
582 switch( getEntity().getType()){
584 except
.add(element_timePeriod
);
587 except
.remove(text_series
);
588 except
.remove(text_edition
);
594 updateCacheRelevance();
598 public void fillFields() {
599 // TODO Auto-generated method stub