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
) {
216 label
= "Print Series";
224 createInReferenceWidget
= false;
227 if (createInReferenceWidget
) {
228 selection_inReference
= formFactory
229 .createSelectionElement(Reference
.class,
230 getConversationHolder(), element
, label
,
231 reference
.getInReference(),
232 EntitySelectionElement
.ALL
, style
);
237 * Creates additional controls to edit a generic reference
244 private void createGenericControls(ICdmFormElement element
,
245 Reference reference
, int style
) {
248 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
249 reference
.getEditor(), style
);
252 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
253 reference
.getSeriesPart(), style
);
256 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
257 reference
.getVolume(), style
);
260 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
261 reference
.getPages(), style
);
265 * Creates additional controls to edit a publication
272 private void createPublicationControls(ICdmFormElement element
,
273 ReferenceType referenceType
, Reference reference
, int style
) {
276 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
277 "Place Published", reference
.getPlacePublished(), style
);
280 text_publisher
= formFactory
.createTextWithLabelElement(element
,
281 "Publisher", reference
.getPublisher(), style
);
283 if (referenceType
.equals(ReferenceType
.Journal
)) {
285 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
286 reference
.getIssn(), style
);
289 if (referenceType
.equals(ReferenceType
.Report
)) {
291 selection_institution
= formFactory
292 .createSelectionElement(Institution
.class,
293 getConversationHolder(), element
, "Institution",
294 reference
.getInstitution(),
295 EntitySelectionElement
.ALL
, style
);
298 if (referenceType
.equals(ReferenceType
.Thesis
)) {
300 selection_institution
= formFactory
301 .createSelectionElement(Institution
.class,
302 getConversationHolder(), element
, "School",
303 reference
.getSchool(),
304 EntitySelectionElement
.ALL
, style
);
307 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
309 text_organisation
= formFactory
.createTextWithLabelElement(element
,
310 "Organisation", reference
.getOrganization(), style
);
315 * Creates additional controls to edit a section
321 private void createSectionControls(ICdmFormElement element
,
322 Reference reference
, int style
) {
324 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
325 reference
.getPages(), style
);
329 * Creates additional controls to edit a volume
335 private void createVolumeControls(ICdmFormElement element
,
336 Reference reference
, int style
) {
338 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
339 reference
.getVolume(), style
);
341 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
342 reference
.getSeriesPart(), style
);
348 * @param referenceType
352 private void createPrintedUnitControls(ICdmFormElement element
,
353 ReferenceType referenceType
, Reference reference
, int style
) {
355 selection_inSeries
= formFactory
356 .createSelectionElement(Reference
.class,
357 getConversationHolder(), element
, "In Series",
358 (Reference
) reference
.getInSeries(),
359 EntitySelectionElement
.ALL
, style
);
362 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
363 reference
.getEditor(), style
);
366 text_seriesPart
= formFactory
.createTextWithLabelElement(element
,
367 "Series", reference
.getSeriesPart(), style
);
369 if (referenceType
.equals(ReferenceType
.Book
)) {
371 text_edition
= formFactory
.createTextWithLabelElement(element
,
372 "Edition", reference
.getEdition(), style
);
375 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
376 reference
.getIsbn(), style
);
380 private void createUriAndAbstract(ICdmFormElement element
,
381 Reference reference
, int style
) {
383 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
384 reference
.getUri(), style
);
386 text_referenceAbstract
= formFactory
.createMultiLineTextWithLabel(
387 element
, "Reference Abstract", 100, style
);
388 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
393 public void handleEvent(Object eventSource
) {
394 if (eventSource
== combo_referenceType
) {
395 getEntity().setType(combo_referenceType
.getSelection());
397 } else if (eventSource
== element_timePeriod
) {
398 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
402 else if (eventSource
== selection_authorTeam
) {
403 getEntity().setAuthorship(
404 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
405 } else if (eventSource
== selection_inReference
) {
406 getEntity().setInReference(selection_inReference
.getSelection());
407 } else if (eventSource
== selection_inSeries
) {
408 getEntity().setInReference(selection_inSeries
.getSelection());
409 } else if (eventSource
== selection_institution
) {
410 getEntity().setInstitution(selection_institution
.getSelection());
414 else if (eventSource
== toggleable_cache
) {
415 handleToggleableCacheField();
417 else if (eventSource
== toggleableAbbrevCache
) {
418 handleToggleableAbbrevTitleField();
419 } else if (eventSource
== text_edition
) {
420 getEntity().setEdition(text_edition
.getText());
421 } else if (eventSource
== text_editor
) {
422 getEntity().setEditor(text_editor
.getText());
423 } else if (eventSource
== text_isbn
) {
424 getEntity().setIsbn(text_isbn
.getText());
425 } else if (eventSource
== text_issn
) {
426 getEntity().setIssn(text_issn
.getText());
427 } else if (eventSource
== text_organisation
) {
428 getEntity().setOrganization(text_organisation
.getText());
429 } else if (eventSource
== text_pages
) {
430 getEntity().setPages(text_pages
.getText());
431 } else if (eventSource
== text_placePublished
) {
432 getEntity().setPlacePublished(text_placePublished
.getText());
433 } else if (eventSource
== text_publisher
) {
434 getEntity().setPublisher(text_publisher
.getText());
435 } else if (eventSource
== text_referenceAbstract
) {
436 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
437 } else if (eventSource
== text_seriesPart
) {
438 getEntity().setSeriesPart(text_seriesPart
.getText());
439 } else if (eventSource
== text_title
) {
440 getEntity().setTitle(text_title
.getText());
441 toggleable_cache
.setText(text_title
.getText());
442 } else if (eventSource
== text_abbrevTitle
) {
443 getEntity().setAbbrevTitle(text_abbrevTitle
.getText());
444 toggleableAbbrevCache
.setText(text_abbrevTitle
.getText());
445 } else if (eventSource
== text_uri
) {
447 getEntity().setUri(text_uri
.getUri());
448 } catch (URISyntaxException e
) {
449 MessagingUtils
.warningDialog("Invalid URI", getClass(),
450 e
.getLocalizedMessage());
452 } else if (eventSource
== text_volume
) {
453 getEntity().setVolume(text_volume
.getText());
456 if (eventSource
!= text_title
&& eventSource
!= text_abbrevTitle
) {
457 // set abbrev title cache to null to force new generation
458 // for the standard title cache this is done by a PropertyChangeListener registered
459 // in IdentifiableEntity.initListeners()
460 if(!getEntity().isProtectedAbbrevTitleCache()){
461 getEntity().setAbbrevTitleCache(null, getEntity().isProtectedAbbrevTitleCache());
463 toggleable_cache
.setText(getEntity().getTitleCache());
464 toggleableAbbrevCache
.setText(getEntity().getAbbrevTitleCache());
467 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
472 public void updateToggleableCacheField() {
473 if (!getEntity().isProtectedTitleCache()) {
474 toggleable_cache
.setText(getEntity().generateTitle());
476 if (!getEntity().isProtectedAbbrevTitleCache()) {
477 toggleableAbbrevCache
.setText(getEntity().generateAbbrevTitle());
481 protected void handleToggleableAbbrevTitleField() {
482 boolean pushedAbbrevState
= toggleableAbbrevCache
.getState();
483 getEntity().setAbbrevTitleCache(toggleableAbbrevCache
.getText(), pushedAbbrevState
);
484 setIrrelevant(pushedAbbrevState
, Arrays
.asList(new Object
[] { toggleableAbbrevCache
, toggleable_cache
, text_title
}));
485 updateToggleableCacheField();
492 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
493 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
497 public void handleException(CdmPropertyChangeEvent event
) {
498 exceptionOccurred(event
);
504 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
508 public void clearException() {
509 exceptionOccurred(null);
512 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
518 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
519 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
523 public void addExceptionHandler(IExceptionHandler handler
) {
524 exceptionHandlers
.add(handler
);
531 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
532 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
536 public void removeExceptionHandler(IExceptionHandler handler
) {
537 exceptionHandlers
.remove(handler
);
544 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
545 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
549 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
550 for (IExceptionHandler handler
: exceptionHandlers
) {
552 handler
.clearException();
554 handler
.handleException(event
);