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
.ui
.section
.reference
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.joda
.time
.DateTime
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
27 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.DoiWithLabelElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.LsidWithExceptionLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.element
.VerbatimTimePeriodElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.mvc
.element
.DateElement
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
41 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
45 * ReferenceBaseDetailElement class.
49 * @created Mar 2, 2010
51 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
52 implements IErrorIntolerableElement
, IExceptionHandler
{
56 private ToggleableTextElement toggleableAbbrevCache
;
58 private TextWithLabelElement text_edition
;
59 private TextWithLabelElement text_editor
;
60 private TextWithLabelElement text_isbn
;
61 private TextWithLabelElement text_issn
;
62 private TextWithLabelElement text_organisation
;
63 private TextWithLabelElement text_pages
;
64 private TextWithLabelElement text_placePublished
;
65 private TextWithLabelElement text_publisher
;
66 private TextWithLabelElement text_referenceAbstract
;
67 private TextWithLabelElement text_series
;
68 // private TextWithLabelElement text_seriesPart;
69 private TextWithLabelElement text_volume
;
70 private TextWithLabelElement text_abbrevTitle
;
71 private TextWithLabelElement text_title
;
72 private DoiWithLabelElement text_doi
;
73 private UriWithLabelElement text_uri
;
74 private LsidWithExceptionLabelElement text_lsid
;
75 private DateElement text_accessed
;
76 private EntitySelectionElement
<TeamOrPersonBase
> selection_authorTeam
;
77 private VerbatimTimePeriodElement element_timePeriod
;
78 private EntitySelectionElement
<Reference
> selection_inReference
;
79 private EntitySelectionElement
<Institution
> selection_institution
;
80 private EnumComboElement
<ReferenceType
> combo_referenceType
;
82 private EntitySelectionElement
<Reference
> selection_inSeries
;
83 private boolean isWizard
;
87 * Constructor for ReferenceBaseDetailElement.
90 * @param cdmFormFactory
91 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
94 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
99 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
100 ICdmFormElement formElement
, int style
, boolean isWizard
) {
101 super(cdmFormFactory
, formElement
);
102 this.isWizard
= isWizard
;
108 protected void createControls(ICdmFormElement formElement
,
109 Reference entity
, int style
) {
110 setWarnForReferencingObjects(formElement
);
111 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
112 "Reference Cache", entity
.getTitleCache(),
113 entity
.isProtectedTitleCache(), style
);
115 toggleableAbbrevCache
= formFactory
.createToggleableTextField(formElement
,
116 "Nomencl. Cache", entity
.getAbbrevTitleCache(),
117 entity
.isProtectedAbbrevTitleCache(), style
);
119 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
122 combo_referenceType
.setSelection(entity
.getType());
125 text_title
= formFactory
.createMultiLineTextWithLabel(formElement
,
127 text_title
.setText(entity
.getTitle());
129 text_abbrevTitle
= formFactory
.createTextWithLabelElement(formElement
,
130 "Nomencl. Title", entity
.getAbbrevTitle(), style
);
131 ReferenceType referenceType
= entity
.getType();
133 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) ) {
134 selection_authorTeam
= formFactory
135 .createSelectionElement(TeamOrPersonBase
.class,//getConversationHolder(),
136 formElement
, "Author",
137 entity
.getAuthorship(),
138 EntitySelectionElement
.ALL
, style
);
143 if (referenceType
!= null) {
145 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
147 if (referenceType
.equals(ReferenceType
.Generic
)) {
148 createGenericControls(this, entity
, SWT
.NULL
);
149 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
152 if (referenceType
.isPrintedUnit()) {
153 createPrintedUnitControls(this, referenceType
, entity
,
156 // if (referenceType.equals(ReferenceType.Proceedings)) {
157 // text_isbn = formFactory.createTextWithLabelElement(this, "ISBN",
158 // entity.getIsbn(), style);
160 if (referenceType
.isPublication()) {
161 createPublicationControls(this, referenceType
, entity
,
164 if (referenceType
.isVolumeReference()) {
165 createVolumeControls(this, entity
, SWT
.NULL
);
167 if (referenceType
.isSection()) {
168 createSectionControls(this, entity
, SWT
.NULL
);
175 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
)){
176 element_timePeriod
= formFactory
.createVerbatimTimePeriodElement(formElement
,
177 "Date Published", entity
.getDatePublished(), style
);
180 createUri(this, entity
, SWT
.NULL
);
181 if(referenceType
!= null && (!referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) && !referenceType
.equals(ReferenceType
.PersonalCommunication
))) {
182 text_doi
= formFactory
.createDoiWithLabelElement(formElement
, "DOI", entity
.getDoi(), style
);
185 createLsid(this, entity
, SWT
.NULL
);
186 createAbstract(this, entity
, SWT
.NULL
);
188 handleToggleableAbbrevTitleField();
189 handleToggleableCacheField();
192 private void createWebPageControls(ReferenceDetailElement referenceDetailElement
, Reference reference
, int style
) {
193 DateTime accessed
= reference
.getAccessed();
195 text_accessed
= formFactory
.createDateElement(referenceDetailElement
, "Accessed", accessed
, style
, false);
203 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
208 protected void updateContent() {
209 if (getEntity() == null) {
210 setEntity(ReferenceFactory
.newGeneric());
213 super.updateContent();
215 // enable elements according to state of cache protection
216 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
217 // Object[]{text_cache}));
218 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
219 toggleableAbbrevCache
.setEnabled(getEntity().isProtectedAbbrevTitleCache());
220 setIrrelevantReferenceDetail(false);
221 setIrrelevantReferenceDetail(true);
225 * Creates an in reference for reference types that do hav this.
228 * @param referenceType
232 private void createInReferenceByType(ICdmFormElement element
,
233 ReferenceType referenceType
, Reference reference
, int style
) {
234 boolean createInReferenceWidget
= true;
235 String label
= "In Reference";
237 switch (referenceType
) {
246 label
= "Proceedings";
254 createInReferenceWidget
= false;
257 if (createInReferenceWidget
) {
258 selection_inReference
= formFactory
259 .createSelectionElement(Reference
.class,//getConversationHolder(),
261 reference
.getInReference(),
262 EntitySelectionElement
.ALL
, style
);
267 * Creates additional controls to edit a generic reference
274 private void createGenericControls(ICdmFormElement element
,
275 Reference reference
, int style
) {
278 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
279 reference
.getEditor(), style
);
282 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
283 reference
.getSeriesPart(), style
);
286 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
287 reference
.getVolume(), style
);
290 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
291 reference
.getPages(), style
);
297 * Creates additional controls to edit a publication
304 private void createPublicationControls(ICdmFormElement element
,
305 ReferenceType referenceType
, Reference reference
, int style
) {
308 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
309 "Place Published", reference
.getPlacePublished(), style
);
312 text_publisher
= formFactory
.createTextWithLabelElement(element
,
313 "Publisher", reference
.getPublisher(), style
);
315 if (referenceType
.equals(ReferenceType
.Journal
)) {
317 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
318 reference
.getIssn(), style
);
321 if (referenceType
.equals(ReferenceType
.Report
)) {
323 selection_institution
= formFactory
324 .createSelectionElement(Institution
.class,//getConversationHolder(),
325 element
, "Institution",
326 reference
.getInstitution(),
327 EntitySelectionElement
.ALL
, style
);
330 if (referenceType
.equals(ReferenceType
.Thesis
)) {
332 selection_institution
= formFactory
333 .createSelectionElement(Institution
.class,//getConversationHolder(),
335 reference
.getSchool(),
336 EntitySelectionElement
.ALL
, style
);
339 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
341 text_organisation
= formFactory
.createTextWithLabelElement(element
,
342 "Organisation", reference
.getOrganization(), style
);
347 * Creates additional controls to edit a section
353 private void createSectionControls(ICdmFormElement element
,
354 Reference reference
, int style
) {
356 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
357 reference
.getPages(), style
);
361 * Creates additional controls to edit a volume
367 private void createVolumeControls(ICdmFormElement element
,
368 Reference reference
, int style
) {
370 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
371 reference
.getVolume(), style
);
373 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
374 reference
.getSeriesPart(), style
);
380 * @param referenceType
384 private void createPrintedUnitControls(ICdmFormElement element
,
385 ReferenceType referenceType
, Reference reference
, int style
) {
387 selection_inSeries
= formFactory
388 .createSelectionElement(Reference
.class,//getConversationHolder(),
389 element
, "In Series",
390 (Reference
) reference
.getInSeries(),
391 EntitySelectionElement
.ALL
, style
);
394 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
395 reference
.getEditor(), style
);
398 text_seriesPart = formFactory.createTextWithLabelElement(element,
399 "Series", reference.getSeriesPart(), style);
401 if (referenceType
.equals(ReferenceType
.Book
)) {
403 text_edition
= formFactory
.createTextWithLabelElement(element
,
404 "Edition", reference
.getEdition(), style
);
408 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
409 reference
.getIsbn(), style
);
412 private void createAbstract(ICdmFormElement element
,
413 Reference reference
, int style
) {
415 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
416 element
, "Reference Abstract", 100, style
);
417 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
420 private void createLsid(ICdmFormElement element
,
421 Reference reference
, int style
) {
422 text_lsid
= formFactory
.createLsidWithExceptionLabelElement(element
, "LSID",
423 reference
.getLsid(), style
);
426 private void createUri(ICdmFormElement element
,
427 Reference reference
, int style
) {
429 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
430 reference
.getUri(), style
);
431 if (reference
.getType().equals(ReferenceType
.WebPage
)){
432 createWebPageControls(this, reference
, style
);
438 public void handleEvent(Object eventSource
) {
439 if (eventSource
== combo_referenceType
) {
440 getEntity().setType(combo_referenceType
.getSelection());
442 //this is needed for the "new" wizards in order to redraw correctly
443 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
444 } else if (eventSource
== element_timePeriod
) {
445 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
449 else if (eventSource
== selection_authorTeam
) {
450 getEntity().setAuthorship(
451 selection_authorTeam
.getEntity());
452 } else if (eventSource
== selection_inReference
) {
453 getEntity().setInReference(selection_inReference
.getSelection());
454 } else if (eventSource
== selection_inSeries
) {
455 getEntity().setInReference(selection_inSeries
.getSelection());
456 } else if (eventSource
== selection_institution
) {
457 getEntity().setInstitution(selection_institution
.getSelection());
461 else if (eventSource
== toggleable_cache
) {
462 handleToggleableCacheField();
464 else if (eventSource
== toggleableAbbrevCache
) {
465 handleToggleableAbbrevTitleField();
466 } else if (eventSource
== text_edition
) {
467 getEntity().setEdition(text_edition
.getText());
468 } else if (eventSource
== text_editor
) {
469 getEntity().setEditor(text_editor
.getText());
470 } else if (eventSource
== text_isbn
) {
471 getEntity().setIsbn(text_isbn
.getText());
472 } else if (eventSource
== text_issn
) {
473 getEntity().setIssn(text_issn
.getText());
474 } else if (eventSource
== text_organisation
) {
475 getEntity().setOrganization(text_organisation
.getText());
476 } else if (eventSource
== text_pages
) {
477 getEntity().setPages(text_pages
.getText());
478 } else if (eventSource
== text_placePublished
) {
479 getEntity().setPlacePublished(text_placePublished
.getText());
480 } else if (eventSource
== text_publisher
) {
481 getEntity().setPublisher(text_publisher
.getText());
482 } else if (eventSource
== text_referenceAbstract
) {
483 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
484 } else if (eventSource
== text_series
) {
485 getEntity().setSeriesPart(text_series
.getText());
486 } else if (eventSource
== text_title
) {
487 getEntity().setTitle(text_title
.getText());
488 if (!toggleable_cache
.isEnabled()){
489 toggleable_cache
.setText(getEntity().generateTitle());
491 } else if (eventSource
== text_abbrevTitle
) {
492 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
493 if (!toggleableAbbrevCache
.isEnabled()){
494 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
496 } else if (eventSource
== text_uri
) {
497 getEntity().setUri(text_uri
.parseText());
498 } else if (eventSource
== text_lsid
) {
499 getEntity().setLsid(text_lsid
.parseText());
500 } else if (eventSource
== text_volume
) {
501 getEntity().setVolume(text_volume
.getText());
502 }else if (eventSource
== text_doi
) {
503 getEntity().setDoi(text_doi
.parseText());
504 }else if (eventSource
== text_accessed
.getController()) {
505 getEntity().setAccessed(text_accessed
.getController().getDateTime());
508 if (eventSource
!= text_title
&& eventSource
!= text_abbrevTitle
) {
509 // set abbrev title cache to null to force new generation
510 // for the standard title cache this is done by a PropertyChangeListener registered
511 // in IdentifiableEntity.initListeners()
512 if(!getEntity().isProtectedAbbrevTitleCache()){
513 getEntity().setAbbrevTitleCache(null, getEntity().isProtectedAbbrevTitleCache());
515 if(!getEntity().isProtectedTitleCache()){
516 getEntity().setTitleCache(null, getEntity().isProtectedTitleCache());
519 toggleable_cache
.setText(getEntity().getTitleCache());
520 toggleableAbbrevCache
.setText(getEntity().getAbbrevTitleCache());
523 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
528 public void updateToggleableCacheField() {
529 if (!getEntity().isProtectedTitleCache()) {
530 toggleable_cache
.setText(getEntity().generateTitle());
532 if (!getEntity().isProtectedAbbrevTitleCache()) {
533 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
537 protected void handleToggleableAbbrevTitleField() {
538 boolean pushedAbbrevState
= toggleableAbbrevCache
.getState();
539 getEntity().setAbbrevTitleCache(toggleableAbbrevCache
.getText(), pushedAbbrevState
);
540 setIrrelevantReferenceDetail(true);
541 updateToggleableCacheField();
548 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
549 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
553 public void handleException(CdmPropertyChangeEvent event
) {
554 exceptionOccurred(event
);
560 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
564 public void clearException() {
565 exceptionOccurred(null);
568 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
574 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
575 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
579 public void addExceptionHandler(IExceptionHandler handler
) {
580 exceptionHandlers
.add(handler
);
587 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
588 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
592 public void removeExceptionHandler(IExceptionHandler handler
) {
593 exceptionHandlers
.remove(handler
);
600 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
601 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
605 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
606 for (IExceptionHandler handler
: exceptionHandlers
) {
608 handler
.clearException();
610 handler
.handleException(event
);
616 protected void handleToggleableCacheField() {
618 boolean pushedState
= toggleable_cache
.getState();
619 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
620 setIrrelevantReferenceDetail(false);
621 updateToggleableCacheField();
624 protected void setIrrelevantReferenceDetail(boolean abbrev
){
626 List
<Object
> except
= new ArrayList();
628 except
.addAll( Arrays
.asList(new Object
[] { toggleable_cache
, toggleableAbbrevCache
, text_editor
, text_isbn
, text_issn
, text_organisation
, text_pages
, text_placePublished
, text_publisher
, text_referenceAbstract
, text_uri
, selection_institution
}));
631 except
.add(text_title
);
633 except
.add(text_abbrevTitle
);
635 pushedState
= toggleableAbbrevCache
.getState() || toggleable_cache
.getState();
637 switch( getEntity().getType()){
639 except
.add(element_timePeriod
);
642 except
.remove(text_series
);
643 except
.remove(text_edition
);
649 setIrrelevant(pushedState
, except
);
650 text_title
.setIrrelevant(toggleable_cache
.getState());
651 text_abbrevTitle
.setIrrelevant(toggleableAbbrevCache
.getState());