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
.net
.URISyntaxException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
18 import org
.eclipse
.swt
.SWT
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
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
.model
.AuthorHelper
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
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
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
43 * ReferenceBaseDetailElement class.
47 * @created Mar 2, 2010
50 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
51 implements IErrorIntolerableElement
, IExceptionHandler
{
53 private ToggleableTextElement toggleableAbbrevCache
;
55 private TextWithLabelElement text_edition
;
56 private TextWithLabelElement text_editor
;
57 private TextWithLabelElement text_isbn
;
58 private TextWithLabelElement text_issn
;
59 private TextWithLabelElement text_organisation
;
60 private TextWithLabelElement text_pages
;
61 private TextWithLabelElement text_placePublished
;
62 private TextWithLabelElement text_publisher
;
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 UriWithLabelElement text_uri
;
70 private EntitySelectionElement
<AgentBase
> selection_authorTeam
;
71 private TimePeriodElement element_timePeriod
;
72 private EntitySelectionElement
<Reference
> selection_inReference
;
73 private EntitySelectionElement
<Institution
> selection_institution
;
74 private EnumComboElement
<ReferenceType
> combo_referenceType
;
76 private EntitySelectionElement
<Reference
> selection_inSeries
;
80 * Constructor for ReferenceBaseDetailElement.
83 * @param cdmFormFactory
84 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
87 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
92 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
93 ICdmFormElement formElement
, int style
) {
94 super(cdmFormFactory
, formElement
);
101 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
102 * #createControl(org.eclipse.swt.widgets.Composite, int)
106 protected void createControls(ICdmFormElement formElement
,
107 Reference entity
, int style
) {
108 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
109 "Reference Cache", entity
.getTitleCache(),
110 entity
.isProtectedTitleCache(), style
);
112 toggleableAbbrevCache
= formFactory
.createToggleableTextField(formElement
,
113 "Abbrev. Cache", entity
.getAbbrevTitleCache(),
114 entity
.isProtectedAbbrevTitleCache(), style
);
116 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
119 combo_referenceType
.setSelection(entity
.getType());
122 text_title
= formFactory
.createTextWithLabelElement(formElement
,
123 "Title", entity
.getTitle(), style
);
125 text_abbrevTitle
= formFactory
.createTextWithLabelElement(formElement
,
126 "Abbrev. Title", entity
.getAbbrevTitle(), style
);
129 selection_authorTeam
= formFactory
130 .createSelectionElement(AgentBase
.class,
131 getConversationHolder(), formElement
, "Author",
132 AuthorHelper
.getAuthor(entity
.getAuthorship()),
133 EntitySelectionElement
.ALL
, style
);
135 ReferenceType referenceType
= entity
.getType();
137 if (referenceType
!= null) {
139 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
141 if (referenceType
.equals(ReferenceType
.Generic
)) {
142 createGenericControls(this, entity
, SWT
.NULL
);
143 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
145 if (referenceType
.isPrintedUnit()) {
146 createPrintedUnitControls(this, referenceType
, entity
,
149 if (referenceType
.isPublication()) {
150 createPublicationControls(this, referenceType
, entity
,
153 if (referenceType
.isVolumeReference()) {
154 createVolumeControls(this, entity
, SWT
.NULL
);
156 if (referenceType
.isSection()) {
157 createSectionControls(this, entity
, SWT
.NULL
);
163 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
,
164 "Date Published", entity
.getDatePublished(), style
);
166 createUriAndAbstract(this, entity
, SWT
.NULL
);
173 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
178 protected void updateContent() {
179 if (getEntity() == null) {
180 setEntity(ReferenceFactory
.newGeneric());
183 super.updateContent();
185 // enable elements according to state of cache protection
186 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
187 // Object[]{text_cache}));
188 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
189 toggleableAbbrevCache
.setEnabled(getEntity().isProtectedAbbrevTitleCache());
190 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[] { toggleable_cache
}));
191 setIrrelevant(toggleableAbbrevCache
.getState(), Arrays
.asList(new Object
[] { toggleableAbbrevCache
}));
195 * Creates an in reference for reference types that do hav this.
198 * @param referenceType
202 private void createInReferenceByType(ICdmFormElement element
,
203 ReferenceType referenceType
, Reference reference
, int style
) {
204 boolean createInReferenceWidget
= true;
205 String label
= "In Reference";
207 switch (referenceType
) {
214 label
= "Print Series";
222 createInReferenceWidget
= false;
225 if (createInReferenceWidget
) {
226 selection_inReference
= formFactory
227 .createSelectionElement(Reference
.class,
228 getConversationHolder(), element
, label
,
229 reference
.getInReference(),
230 EntitySelectionElement
.ALL
, style
);
235 * Creates additional controls to edit a generic reference
242 private void createGenericControls(ICdmFormElement element
,
243 Reference reference
, int style
) {
246 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
247 reference
.getEditor(), style
);
250 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
251 reference
.getSeriesPart(), style
);
254 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
255 reference
.getVolume(), style
);
258 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
259 reference
.getPages(), style
);
263 * Creates additional controls to edit a publication
270 private void createPublicationControls(ICdmFormElement element
,
271 ReferenceType referenceType
, Reference reference
, int style
) {
274 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
275 "Place Published", reference
.getPlacePublished(), style
);
278 text_publisher
= formFactory
.createTextWithLabelElement(element
,
279 "Publisher", reference
.getPublisher(), style
);
281 if (referenceType
.equals(ReferenceType
.Journal
)) {
283 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
284 reference
.getIssn(), style
);
287 if (referenceType
.equals(ReferenceType
.Report
)) {
289 selection_institution
= formFactory
290 .createSelectionElement(Institution
.class,
291 getConversationHolder(), element
, "Institution",
292 reference
.getInstitution(),
293 EntitySelectionElement
.ALL
, style
);
296 if (referenceType
.equals(ReferenceType
.Thesis
)) {
298 selection_institution
= formFactory
299 .createSelectionElement(Institution
.class,
300 getConversationHolder(), element
, "School",
301 reference
.getSchool(),
302 EntitySelectionElement
.ALL
, style
);
305 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
307 text_organisation
= formFactory
.createTextWithLabelElement(element
,
308 "Organisation", reference
.getOrganization(), style
);
313 * Creates additional controls to edit a section
319 private void createSectionControls(ICdmFormElement element
,
320 Reference reference
, int style
) {
322 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
323 reference
.getPages(), style
);
327 * Creates additional controls to edit a volume
333 private void createVolumeControls(ICdmFormElement element
,
334 Reference reference
, int style
) {
336 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
337 reference
.getVolume(), style
);
339 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
340 reference
.getSeriesPart(), style
);
346 * @param referenceType
350 private void createPrintedUnitControls(ICdmFormElement element
,
351 ReferenceType referenceType
, Reference reference
, int style
) {
353 selection_inSeries
= formFactory
354 .createSelectionElement(Reference
.class,
355 getConversationHolder(), element
, "In Series",
356 (Reference
) reference
.getInSeries(),
357 EntitySelectionElement
.ALL
, style
);
360 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
361 reference
.getEditor(), style
);
364 text_seriesPart
= formFactory
.createTextWithLabelElement(element
,
365 "Series", reference
.getSeriesPart(), style
);
367 if (referenceType
.equals(ReferenceType
.Book
)) {
369 text_edition
= formFactory
.createTextWithLabelElement(element
,
370 "Edition", reference
.getEdition(), style
);
373 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
374 reference
.getIsbn(), style
);
378 private void createUriAndAbstract(ICdmFormElement element
,
379 Reference reference
, int style
) {
381 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
382 reference
.getUri(), style
);
384 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
385 element
, "Reference Abstract", 100, style
);
386 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
391 public void handleEvent(Object eventSource
) {
392 if (eventSource
== combo_referenceType
) {
393 getEntity().setType(combo_referenceType
.getSelection());
395 } else if (eventSource
== element_timePeriod
) {
396 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
400 else if (eventSource
== selection_authorTeam
) {
401 getEntity().setAuthorship(
402 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
403 } else if (eventSource
== selection_inReference
) {
404 getEntity().setInReference(selection_inReference
.getSelection());
405 } else if (eventSource
== selection_inSeries
) {
406 getEntity().setInReference(selection_inSeries
.getSelection());
407 } else if (eventSource
== selection_institution
) {
408 getEntity().setInstitution(selection_institution
.getSelection());
412 else if (eventSource
== toggleable_cache
) {
413 handleToggleableCacheField();
415 else if (eventSource
== toggleableAbbrevCache
) {
416 handleToggleableAbbrevTitleField();
417 } else if (eventSource
== text_edition
) {
418 getEntity().setEdition(text_edition
.getText());
419 } else if (eventSource
== text_editor
) {
420 getEntity().setEditor(text_editor
.getText());
421 } else if (eventSource
== text_isbn
) {
422 getEntity().setIsbn(text_isbn
.getText());
423 } else if (eventSource
== text_issn
) {
424 getEntity().setIssn(text_issn
.getText());
425 } else if (eventSource
== text_organisation
) {
426 getEntity().setOrganization(text_organisation
.getText());
427 } else if (eventSource
== text_pages
) {
428 getEntity().setPages(text_pages
.getText());
429 } else if (eventSource
== text_placePublished
) {
430 getEntity().setPlacePublished(text_placePublished
.getText());
431 } else if (eventSource
== text_publisher
) {
432 getEntity().setPublisher(text_publisher
.getText());
433 } else if (eventSource
== text_referenceAbstract
) {
434 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
435 } else if (eventSource
== text_seriesPart
) {
436 getEntity().setSeriesPart(text_seriesPart
.getText());
437 } else if (eventSource
== text_title
) {
438 getEntity().setTitle(text_title
.getText());
439 toggleable_cache
.setText(text_title
.getText());
440 } else if (eventSource
== text_abbrevTitle
) {
441 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
442 toggleableAbbrevCache
.setText(text_abbrevTitle
.getText());
443 } else if (eventSource
== text_uri
) {
445 getEntity().setUri(text_uri
.getUri());
446 } catch (URISyntaxException e
) {
447 MessagingUtils
.warningDialog("Invalid URI", getClass(),
448 e
.getLocalizedMessage());
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 setIrrelevant(pushedAbbrevState
, Arrays
.asList(new Object
[] { toggleableAbbrevCache
, toggleable_cache
, text_title
}));
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
);