3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.reference
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
17 import org
.eclipse
.swt
.SWT
;
19 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.Institution
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
25 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
40 * ReferenceBaseDetailElement class.
44 * @created Mar 2, 2010
47 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
48 implements IErrorIntolerableElement
, IExceptionHandler
{
50 private ToggleableTextElement toggleableAbbrevCache
;
52 private TextWithLabelElement text_edition
;
53 private TextWithLabelElement text_editor
;
54 private TextWithLabelElement text_isbn
;
55 private TextWithLabelElement text_issn
;
56 private TextWithLabelElement text_organisation
;
57 private TextWithLabelElement text_pages
;
58 private TextWithLabelElement text_placePublished
;
59 private TextWithLabelElement text_publisher
;
60 private TextWithLabelElement text_referenceAbstract
;
61 private TextWithLabelElement text_series
;
62 // private TextWithLabelElement text_seriesPart;
63 private TextWithLabelElement text_volume
;
64 private TextWithLabelElement text_abbrevTitle
;
65 private TextWithLabelElement text_title
;
66 private UriWithLabelElement text_uri
;
67 private EntitySelectionElement
<AgentBase
> selection_authorTeam
;
68 private TimePeriodElement element_timePeriod
;
69 private EntitySelectionElement
<Reference
> selection_inReference
;
70 private EntitySelectionElement
<Institution
> selection_institution
;
71 private EnumComboElement
<ReferenceType
> combo_referenceType
;
73 private EntitySelectionElement
<Reference
> selection_inSeries
;
77 * Constructor for ReferenceBaseDetailElement.
80 * @param cdmFormFactory
81 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
84 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
89 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
90 ICdmFormElement formElement
, int style
) {
91 super(cdmFormFactory
, formElement
);
98 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
99 * #createControl(org.eclipse.swt.widgets.Composite, int)
103 protected void createControls(ICdmFormElement formElement
,
104 Reference entity
, int style
) {
105 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
106 "Reference Cache", entity
.getTitleCache(),
107 entity
.isProtectedTitleCache(), style
);
109 toggleableAbbrevCache
= formFactory
.createToggleableTextField(formElement
,
110 "Abbrev. Cache", entity
.getAbbrevTitleCache(),
111 entity
.isProtectedAbbrevTitleCache(), style
);
113 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
116 combo_referenceType
.setSelection(entity
.getType());
119 text_title
= formFactory
.createTextWithLabelElement(formElement
,
120 "Title", entity
.getTitle(), style
);
122 text_abbrevTitle
= formFactory
.createTextWithLabelElement(formElement
,
123 "Nomenclatural Title", entity
.getAbbrevTitle(), style
);
126 selection_authorTeam
= formFactory
127 .createSelectionElement(AgentBase
.class,
128 getConversationHolder(), formElement
, "Author",
129 entity
.getAuthorship(),
130 EntitySelectionElement
.ALL
, style
);
132 ReferenceType referenceType
= entity
.getType();
134 if (referenceType
!= null) {
136 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
138 if (referenceType
.equals(ReferenceType
.Generic
)) {
139 createGenericControls(this, entity
, SWT
.NULL
);
140 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
142 if (referenceType
.isPrintedUnit()) {
143 createPrintedUnitControls(this, referenceType
, entity
,
146 if (referenceType
.isPublication()) {
147 createPublicationControls(this, referenceType
, entity
,
150 if (referenceType
.isVolumeReference()) {
151 createVolumeControls(this, entity
, SWT
.NULL
);
153 if (referenceType
.isSection()) {
154 createSectionControls(this, entity
, SWT
.NULL
);
160 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
,
161 "Date Published", entity
.getDatePublished(), style
);
163 createUriAndAbstract(this, entity
, SWT
.NULL
);
164 handleToggleableAbbrevTitleField();
165 handleToggleableCacheField();
172 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
177 protected void updateContent() {
178 if (getEntity() == null) {
179 setEntity(ReferenceFactory
.newGeneric());
182 super.updateContent();
184 // enable elements according to state of cache protection
185 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
186 // Object[]{text_cache}));
187 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
188 toggleableAbbrevCache
.setEnabled(getEntity().isProtectedAbbrevTitleCache());
189 setIrrelevantReferenceDetail(false);
190 setIrrelevantReferenceDetail(true);
194 * Creates an in reference for reference types that do hav this.
197 * @param referenceType
201 private void createInReferenceByType(ICdmFormElement element
,
202 ReferenceType referenceType
, Reference reference
, int style
) {
203 boolean createInReferenceWidget
= true;
204 String label
= "In Reference";
206 switch (referenceType
) {
215 label
= "Print Series";
223 createInReferenceWidget
= false;
226 if (createInReferenceWidget
) {
227 selection_inReference
= formFactory
228 .createSelectionElement(Reference
.class,
229 getConversationHolder(), element
, label
,
230 reference
.getInReference(),
231 EntitySelectionElement
.ALL
, style
);
236 * Creates additional controls to edit a generic reference
243 private void createGenericControls(ICdmFormElement element
,
244 Reference reference
, int style
) {
247 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
248 reference
.getEditor(), style
);
251 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
252 reference
.getSeriesPart(), style
);
255 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
256 reference
.getVolume(), style
);
259 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
260 reference
.getPages(), style
);
264 * Creates additional controls to edit a publication
271 private void createPublicationControls(ICdmFormElement element
,
272 ReferenceType referenceType
, Reference reference
, int style
) {
275 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
276 "Place Published", reference
.getPlacePublished(), style
);
279 text_publisher
= formFactory
.createTextWithLabelElement(element
,
280 "Publisher", reference
.getPublisher(), style
);
282 if (referenceType
.equals(ReferenceType
.Journal
)) {
284 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
285 reference
.getIssn(), style
);
288 if (referenceType
.equals(ReferenceType
.Report
)) {
290 selection_institution
= formFactory
291 .createSelectionElement(Institution
.class,
292 getConversationHolder(), element
, "Institution",
293 reference
.getInstitution(),
294 EntitySelectionElement
.ALL
, style
);
297 if (referenceType
.equals(ReferenceType
.Thesis
)) {
299 selection_institution
= formFactory
300 .createSelectionElement(Institution
.class,
301 getConversationHolder(), element
, "School",
302 reference
.getSchool(),
303 EntitySelectionElement
.ALL
, style
);
306 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
308 text_organisation
= formFactory
.createTextWithLabelElement(element
,
309 "Organisation", reference
.getOrganization(), style
);
314 * Creates additional controls to edit a section
320 private void createSectionControls(ICdmFormElement element
,
321 Reference reference
, int style
) {
323 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
324 reference
.getPages(), style
);
328 * Creates additional controls to edit a volume
334 private void createVolumeControls(ICdmFormElement element
,
335 Reference reference
, int style
) {
337 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
338 reference
.getVolume(), style
);
340 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
341 reference
.getSeriesPart(), style
);
347 * @param referenceType
351 private void createPrintedUnitControls(ICdmFormElement element
,
352 ReferenceType referenceType
, Reference reference
, int style
) {
354 selection_inSeries
= formFactory
355 .createSelectionElement(Reference
.class,
356 getConversationHolder(), element
, "In Series",
357 (Reference
) reference
.getInSeries(),
358 EntitySelectionElement
.ALL
, style
);
361 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
362 reference
.getEditor(), style
);
365 text_seriesPart = formFactory.createTextWithLabelElement(element,
366 "Series", reference.getSeriesPart(), style);
368 if (referenceType
.equals(ReferenceType
.Book
)) {
370 text_edition
= formFactory
.createTextWithLabelElement(element
,
371 "Edition", reference
.getEdition(), style
);
374 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
375 reference
.getIsbn(), style
);
379 private void createUriAndAbstract(ICdmFormElement element
,
380 Reference reference
, int style
) {
382 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
383 reference
.getUri(), style
);
385 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
386 element
, "Reference Abstract", 100, style
);
387 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
392 public void handleEvent(Object eventSource
) {
393 if (eventSource
== combo_referenceType
) {
394 getEntity().setType(combo_referenceType
.getSelection());
396 } else if (eventSource
== element_timePeriod
) {
397 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
401 else if (eventSource
== selection_authorTeam
) {
402 getEntity().setAuthorship(
403 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
404 } else if (eventSource
== selection_inReference
) {
405 getEntity().setInReference(selection_inReference
.getSelection());
406 } else if (eventSource
== selection_inSeries
) {
407 getEntity().setInReference(selection_inSeries
.getSelection());
408 } else if (eventSource
== selection_institution
) {
409 getEntity().setInstitution(selection_institution
.getSelection());
413 else if (eventSource
== toggleable_cache
) {
414 handleToggleableCacheField();
416 else if (eventSource
== toggleableAbbrevCache
) {
417 handleToggleableAbbrevTitleField();
418 } else if (eventSource
== text_edition
) {
419 getEntity().setEdition(text_edition
.getText());
420 } else if (eventSource
== text_editor
) {
421 getEntity().setEditor(text_editor
.getText());
422 } else if (eventSource
== text_isbn
) {
423 getEntity().setIsbn(text_isbn
.getText());
424 } else if (eventSource
== text_issn
) {
425 getEntity().setIssn(text_issn
.getText());
426 } else if (eventSource
== text_organisation
) {
427 getEntity().setOrganization(text_organisation
.getText());
428 } else if (eventSource
== text_pages
) {
429 getEntity().setPages(text_pages
.getText());
430 } else if (eventSource
== text_placePublished
) {
431 getEntity().setPlacePublished(text_placePublished
.getText());
432 } else if (eventSource
== text_publisher
) {
433 getEntity().setPublisher(text_publisher
.getText());
434 } else if (eventSource
== text_referenceAbstract
) {
435 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
436 } else if (eventSource
== text_series
) {
437 getEntity().setSeriesPart(text_series
.getText());
438 } else if (eventSource
== text_title
) {
439 getEntity().setTitle(text_title
.getText());
440 if (!toggleable_cache
.isEnabled()){
441 toggleable_cache
.setText(getEntity().generateTitle());
443 } else if (eventSource
== text_abbrevTitle
) {
444 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
445 if (!toggleableAbbrevCache
.isEnabled()){
446 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
448 } else if (eventSource
== text_uri
) {
449 getEntity().setUri(text_uri
.parseText());
450 } else if (eventSource
== text_volume
) {
451 getEntity().setVolume(text_volume
.getText());
454 if (eventSource
!= text_title
&& eventSource
!= text_abbrevTitle
) {
455 // set abbrev title cache to null to force new generation
456 // for the standard title cache this is done by a PropertyChangeListener registered
457 // in IdentifiableEntity.initListeners()
458 if(!getEntity().isProtectedAbbrevTitleCache()){
459 getEntity().setAbbrevTitleCache(null, getEntity().isProtectedAbbrevTitleCache());
461 toggleable_cache
.setText(getEntity().getTitleCache());
462 toggleableAbbrevCache
.setText(getEntity().getAbbrevTitleCache());
465 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
470 public void updateToggleableCacheField() {
471 if (!getEntity().isProtectedTitleCache()) {
472 toggleable_cache
.setText(getEntity().generateTitle());
474 if (!getEntity().isProtectedAbbrevTitleCache()) {
475 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
479 protected void handleToggleableAbbrevTitleField() {
480 boolean pushedAbbrevState
= toggleableAbbrevCache
.getState();
481 getEntity().setAbbrevTitleCache(toggleableAbbrevCache
.getText(), pushedAbbrevState
);
482 setIrrelevantReferenceDetail(true);
483 updateToggleableCacheField();
490 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
491 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
495 public void handleException(CdmPropertyChangeEvent event
) {
496 exceptionOccurred(event
);
502 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
506 public void clearException() {
507 exceptionOccurred(null);
510 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
516 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
517 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
521 public void addExceptionHandler(IExceptionHandler handler
) {
522 exceptionHandlers
.add(handler
);
529 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
530 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
534 public void removeExceptionHandler(IExceptionHandler handler
) {
535 exceptionHandlers
.remove(handler
);
542 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
543 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
547 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
548 for (IExceptionHandler handler
: exceptionHandlers
) {
550 handler
.clearException();
552 handler
.handleException(event
);
558 protected void handleToggleableCacheField() {
560 boolean pushedState
= toggleable_cache
.getState();
561 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
562 setIrrelevantReferenceDetail(false);
563 updateToggleableCacheField();
566 protected void setIrrelevantReferenceDetail(boolean abbrev
){
568 List
<Object
> except
= new ArrayList();
569 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
}));
572 except
.add(text_title
);
573 pushedState
= toggleableAbbrevCache
.getState();
575 except
.add(text_abbrevTitle
);
576 pushedState
= toggleable_cache
.getState();
578 switch( getEntity().getType()){
580 except
.add(element_timePeriod
);
583 except
.remove(text_series
);
584 except
.remove(text_edition
);
589 setIrrelevant(pushedState
, except
);