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
.AgentBase
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
27 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
28 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.DoiWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
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 DateElement text_accessed
;
75 private EntitySelectionElement
<AgentBase
> selection_authorTeam
;
76 private VerbatimTimePeriodElement element_timePeriod
;
77 private EntitySelectionElement
<Reference
> selection_inReference
;
78 private EntitySelectionElement
<Institution
> selection_institution
;
79 private EnumComboElement
<ReferenceType
> combo_referenceType
;
81 private EntitySelectionElement
<Reference
> selection_inSeries
;
82 private boolean isWizard
;
86 * Constructor for ReferenceBaseDetailElement.
89 * @param cdmFormFactory
90 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
93 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
98 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
99 ICdmFormElement formElement
, int style
, boolean isWizard
) {
100 super(cdmFormFactory
, formElement
);
101 this.isWizard
= isWizard
;
107 protected void createControls(ICdmFormElement formElement
,
108 Reference entity
, int style
) {
109 setWarnForReferencingObjects(formElement
);
110 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
111 "Reference Cache", entity
.getTitleCache(),
112 entity
.isProtectedTitleCache(), style
);
114 toggleableAbbrevCache
= formFactory
.createToggleableTextField(formElement
,
115 "Nomencl. Cache", entity
.getAbbrevTitleCache(),
116 entity
.isProtectedAbbrevTitleCache(), style
);
118 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
121 combo_referenceType
.setSelection(entity
.getType());
124 text_title
= formFactory
.createTextWithLabelElement(formElement
,
125 "Title", entity
.getTitle(), style
);
127 text_abbrevTitle
= formFactory
.createTextWithLabelElement(formElement
,
128 "Nomencl. Title", entity
.getAbbrevTitle(), style
);
129 ReferenceType referenceType
= entity
.getType();
131 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) ) {
132 selection_authorTeam
= formFactory
133 .createSelectionElement(AgentBase
.class,//getConversationHolder(),
134 formElement
, "Author",
135 entity
.getAuthorship(),
136 EntitySelectionElement
.ALL
, style
);
141 if (referenceType
!= null) {
143 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
145 if (referenceType
.equals(ReferenceType
.Generic
)) {
146 createGenericControls(this, entity
, SWT
.NULL
);
147 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
150 if (referenceType
.isPrintedUnit()) {
151 createPrintedUnitControls(this, referenceType
, entity
,
154 if (referenceType
.isPublication()) {
155 createPublicationControls(this, referenceType
, entity
,
158 if (referenceType
.isVolumeReference()) {
159 createVolumeControls(this, entity
, SWT
.NULL
);
161 if (referenceType
.isSection()) {
162 createSectionControls(this, entity
, SWT
.NULL
);
169 if(referenceType
!= null && !referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
)){
170 element_timePeriod
= formFactory
.createVerbatimTimePeriodElement(formElement
,
171 "Date Published", entity
.getDatePublished(), style
);
175 if(referenceType
!= null && (!referenceType
.equals(ReferenceType
.Journal
) && !referenceType
.equals(ReferenceType
.PrintSeries
) && !referenceType
.equals(ReferenceType
.PersonalCommunication
))) {
176 text_doi
= formFactory
.createDoiWithLabelElement(formElement
, "DOI", entity
.getDoi(), style
);
178 createUriAndAbstract(this, entity
, SWT
.NULL
);
180 handleToggleableAbbrevTitleField();
181 handleToggleableCacheField();
184 private void createWebPageControls(ReferenceDetailElement referenceDetailElement
, Reference reference
, int style
) {
185 DateTime accessed
= reference
.getAccessed();
187 text_accessed
= formFactory
.createDateElement(referenceDetailElement
, "Accessed", accessed
, style
, false);
195 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
200 protected void updateContent() {
201 if (getEntity() == null) {
202 setEntity(ReferenceFactory
.newGeneric());
205 super.updateContent();
207 // enable elements according to state of cache protection
208 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
209 // Object[]{text_cache}));
210 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
211 toggleableAbbrevCache
.setEnabled(getEntity().isProtectedAbbrevTitleCache());
212 setIrrelevantReferenceDetail(false);
213 setIrrelevantReferenceDetail(true);
217 * Creates an in reference for reference types that do hav this.
220 * @param referenceType
224 private void createInReferenceByType(ICdmFormElement element
,
225 ReferenceType referenceType
, Reference reference
, int style
) {
226 boolean createInReferenceWidget
= true;
227 String label
= "In Reference";
229 switch (referenceType
) {
238 label
= "Print Series";
246 createInReferenceWidget
= false;
249 if (createInReferenceWidget
) {
250 selection_inReference
= formFactory
251 .createSelectionElement(Reference
.class,//getConversationHolder(),
253 reference
.getInReference(),
254 EntitySelectionElement
.ALL
, style
);
259 * Creates additional controls to edit a generic reference
266 private void createGenericControls(ICdmFormElement element
,
267 Reference reference
, int style
) {
270 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
271 reference
.getEditor(), style
);
274 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
275 reference
.getSeriesPart(), style
);
278 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
279 reference
.getVolume(), style
);
282 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
283 reference
.getPages(), style
);
289 * Creates additional controls to edit a publication
296 private void createPublicationControls(ICdmFormElement element
,
297 ReferenceType referenceType
, Reference reference
, int style
) {
300 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
301 "Place Published", reference
.getPlacePublished(), style
);
304 text_publisher
= formFactory
.createTextWithLabelElement(element
,
305 "Publisher", reference
.getPublisher(), style
);
307 if (referenceType
.equals(ReferenceType
.Journal
)) {
309 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
310 reference
.getIssn(), style
);
313 if (referenceType
.equals(ReferenceType
.Report
)) {
315 selection_institution
= formFactory
316 .createSelectionElement(Institution
.class,//getConversationHolder(),
317 element
, "Institution",
318 reference
.getInstitution(),
319 EntitySelectionElement
.ALL
, style
);
322 if (referenceType
.equals(ReferenceType
.Thesis
)) {
324 selection_institution
= formFactory
325 .createSelectionElement(Institution
.class,//getConversationHolder(),
327 reference
.getSchool(),
328 EntitySelectionElement
.ALL
, style
);
331 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
333 text_organisation
= formFactory
.createTextWithLabelElement(element
,
334 "Organisation", reference
.getOrganization(), style
);
339 * Creates additional controls to edit a section
345 private void createSectionControls(ICdmFormElement element
,
346 Reference reference
, int style
) {
348 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
349 reference
.getPages(), style
);
353 * Creates additional controls to edit a volume
359 private void createVolumeControls(ICdmFormElement element
,
360 Reference reference
, int style
) {
362 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
363 reference
.getVolume(), style
);
365 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
366 reference
.getSeriesPart(), style
);
372 * @param referenceType
376 private void createPrintedUnitControls(ICdmFormElement element
,
377 ReferenceType referenceType
, Reference reference
, int style
) {
379 selection_inSeries
= formFactory
380 .createSelectionElement(Reference
.class,//getConversationHolder(),
381 element
, "In Series",
382 (Reference
) reference
.getInSeries(),
383 EntitySelectionElement
.ALL
, style
);
386 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
387 reference
.getEditor(), style
);
390 text_seriesPart = formFactory.createTextWithLabelElement(element,
391 "Series", reference.getSeriesPart(), style);
393 if (referenceType
.equals(ReferenceType
.Book
)) {
395 text_edition
= formFactory
.createTextWithLabelElement(element
,
396 "Edition", reference
.getEdition(), style
);
399 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
400 reference
.getIsbn(), style
);
404 private void createUriAndAbstract(ICdmFormElement element
,
405 Reference reference
, int style
) {
407 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
408 reference
.getUri(), style
);
409 if (reference
.getType().equals(ReferenceType
.WebPage
)){
410 createWebPageControls(this, reference
, style
);
413 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
414 element
, "Reference Abstract", 100, style
);
415 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
420 public void handleEvent(Object eventSource
) {
421 if (eventSource
== combo_referenceType
) {
422 getEntity().setType(combo_referenceType
.getSelection());
424 //this is needed for the "new" wizards in order to redraw correctly
425 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
426 } else if (eventSource
== element_timePeriod
) {
427 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
431 else if (eventSource
== selection_authorTeam
) {
432 getEntity().setAuthorship(
433 (TeamOrPersonBase
) selection_authorTeam
.getEntity());
434 } else if (eventSource
== selection_inReference
) {
435 getEntity().setInReference(selection_inReference
.getSelection());
436 } else if (eventSource
== selection_inSeries
) {
437 getEntity().setInReference(selection_inSeries
.getSelection());
438 } else if (eventSource
== selection_institution
) {
439 getEntity().setInstitution(selection_institution
.getSelection());
443 else if (eventSource
== toggleable_cache
) {
444 handleToggleableCacheField();
446 else if (eventSource
== toggleableAbbrevCache
) {
447 handleToggleableAbbrevTitleField();
448 } else if (eventSource
== text_edition
) {
449 getEntity().setEdition(text_edition
.getText());
450 } else if (eventSource
== text_editor
) {
451 getEntity().setEditor(text_editor
.getText());
452 } else if (eventSource
== text_isbn
) {
453 getEntity().setIsbn(text_isbn
.getText());
454 } else if (eventSource
== text_issn
) {
455 getEntity().setIssn(text_issn
.getText());
456 } else if (eventSource
== text_organisation
) {
457 getEntity().setOrganization(text_organisation
.getText());
458 } else if (eventSource
== text_pages
) {
459 getEntity().setPages(text_pages
.getText());
460 } else if (eventSource
== text_placePublished
) {
461 getEntity().setPlacePublished(text_placePublished
.getText());
462 } else if (eventSource
== text_publisher
) {
463 getEntity().setPublisher(text_publisher
.getText());
464 } else if (eventSource
== text_referenceAbstract
) {
465 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
466 } else if (eventSource
== text_series
) {
467 getEntity().setSeriesPart(text_series
.getText());
468 } else if (eventSource
== text_title
) {
469 getEntity().setTitle(text_title
.getText());
470 if (!toggleable_cache
.isEnabled()){
471 toggleable_cache
.setText(getEntity().generateTitle());
473 } else if (eventSource
== text_abbrevTitle
) {
474 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
475 if (!toggleableAbbrevCache
.isEnabled()){
476 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
478 } else if (eventSource
== text_uri
) {
479 getEntity().setUri(text_uri
.parseText());
480 } else if (eventSource
== text_volume
) {
481 getEntity().setVolume(text_volume
.getText());
482 }else if (eventSource
== text_doi
) {
483 getEntity().setDoi(text_doi
.parseText());
484 }else if (eventSource
== text_accessed
.getController()) {
485 getEntity().setAccessed(text_accessed
.getController().getDateTime());
488 if (eventSource
!= text_title
&& eventSource
!= text_abbrevTitle
) {
489 // set abbrev title cache to null to force new generation
490 // for the standard title cache this is done by a PropertyChangeListener registered
491 // in IdentifiableEntity.initListeners()
492 if(!getEntity().isProtectedAbbrevTitleCache()){
493 getEntity().setAbbrevTitleCache(null, getEntity().isProtectedAbbrevTitleCache());
495 if(!getEntity().isProtectedTitleCache()){
496 getEntity().setTitleCache(null, getEntity().isProtectedTitleCache());
499 toggleable_cache
.setText(getEntity().getTitleCache());
500 toggleableAbbrevCache
.setText(getEntity().getAbbrevTitleCache());
503 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
508 public void updateToggleableCacheField() {
509 if (!getEntity().isProtectedTitleCache()) {
510 toggleable_cache
.setText(getEntity().generateTitle());
512 if (!getEntity().isProtectedAbbrevTitleCache()) {
513 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
517 protected void handleToggleableAbbrevTitleField() {
518 boolean pushedAbbrevState
= toggleableAbbrevCache
.getState();
519 getEntity().setAbbrevTitleCache(toggleableAbbrevCache
.getText(), pushedAbbrevState
);
520 setIrrelevantReferenceDetail(true);
521 updateToggleableCacheField();
528 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
529 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
533 public void handleException(CdmPropertyChangeEvent event
) {
534 exceptionOccurred(event
);
540 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
544 public void clearException() {
545 exceptionOccurred(null);
548 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
554 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
555 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
559 public void addExceptionHandler(IExceptionHandler handler
) {
560 exceptionHandlers
.add(handler
);
567 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
568 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
572 public void removeExceptionHandler(IExceptionHandler handler
) {
573 exceptionHandlers
.remove(handler
);
580 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
581 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
585 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
586 for (IExceptionHandler handler
: exceptionHandlers
) {
588 handler
.clearException();
590 handler
.handleException(event
);
596 protected void handleToggleableCacheField() {
598 boolean pushedState
= toggleable_cache
.getState();
599 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
600 setIrrelevantReferenceDetail(false);
601 updateToggleableCacheField();
604 protected void setIrrelevantReferenceDetail(boolean abbrev
){
606 List
<Object
> except
= new ArrayList();
608 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
}));
611 except
.add(text_title
);
613 except
.add(text_abbrevTitle
);
615 pushedState
= toggleableAbbrevCache
.getState() || toggleable_cache
.getState();
617 switch( getEntity().getType()){
619 except
.add(element_timePeriod
);
622 except
.remove(text_series
);
623 except
.remove(text_edition
);
629 setIrrelevant(pushedState
, except
);
630 text_title
.setIrrelevant(toggleable_cache
.getState());
631 text_abbrevTitle
.setIrrelevant(toggleableAbbrevCache
.getState());