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
.TeamOrPersonBase
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
24 import eu
.etaxonomy
.taxeditor
.model
.AuthorHelper
;
25 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
26 import eu
.etaxonomy
.taxeditor
.ui
.combo
.EnumComboElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.IErrorIntolerableElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.IExceptionHandler
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.UriWithLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
.SelectionType
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.selection
.AgentSelectionElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.selection
.InstitutionSelectionElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.selection
.ReferenceSelectionElement
;
43 * ReferenceBaseDetailElement class.
47 * @created Mar 2, 2010
50 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
51 implements IErrorIntolerableElement
, IExceptionHandler
{
53 private TextWithLabelElement text_edition
;
54 private TextWithLabelElement text_editor
;
55 private TextWithLabelElement text_isbn
;
56 private TextWithLabelElement text_issn
;
57 private TextWithLabelElement text_organisation
;
58 private TextWithLabelElement text_pages
;
59 private TextWithLabelElement text_placePublished
;
60 private TextWithLabelElement text_publisher
;
61 private TextWithLabelElement text_referenceAbstract
;
62 private TextWithLabelElement text_series
;
63 private TextWithLabelElement text_seriesPart
;
64 private TextWithLabelElement text_title
;
65 private TextWithLabelElement text_volume
;
66 private UriWithLabelElement text_uri
;
67 private AgentSelectionElement selection_authorTeam
;
68 private TimePeriodElement element_timePeriod
;
69 private ReferenceSelectionElement selection_inReference
;
70 private InstitutionSelectionElement selection_institution
;
71 private EnumComboElement
<ReferenceType
> combo_referenceType
;
73 private ReferenceSelectionElement 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 combo_referenceType
= formFactory
.createEnumComboElement(ReferenceType
.class,
112 combo_referenceType
.setSelection(entity
.getType());
115 text_title
= formFactory
.createTextWithLabelElement(formElement
,
116 "Title", entity
.getTitle(), style
);
119 selection_authorTeam
= (AgentSelectionElement
) formFactory
120 .createSelectionElement(SelectionType
.AGENT
,
121 getConversationHolder(), formElement
, "Author",
122 AuthorHelper
.getAuthor(entity
.getAuthorTeam()),
123 AgentSelectionElement
.DEFAULT
, style
);
125 ReferenceType referenceType
= entity
.getType();
127 if (referenceType
!= null) {
129 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
131 if (referenceType
.equals(ReferenceType
.Generic
)) {
132 createGenericControls(this, entity
, SWT
.NULL
);
133 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
135 if (referenceType
.isPrintedUnit()) {
136 createPrintedUnitControls(this, referenceType
, entity
,
139 if (referenceType
.isPublication()) {
140 createPublicationControls(this, referenceType
, entity
,
143 if (referenceType
.isVolumeReference()) {
144 createVolumeControls(this, entity
, SWT
.NULL
);
146 if (referenceType
.isSection()) {
147 createSectionControls(this, entity
, SWT
.NULL
);
153 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
,
154 "Date Published", entity
.getDatePublished(), style
);
156 createUriAndAbstract(this, entity
, SWT
.NULL
);
163 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
168 protected void updateContent() {
169 if (getEntity() == null) {
170 setEntity(ReferenceFactory
.newGeneric());
173 super.updateContent();
175 // enable elements according to state of cache protection
176 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
177 // Object[]{text_cache}));
178 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
179 setIrrelevant(toggleable_cache
.getState(),
180 Arrays
.asList(new Object
[] { toggleable_cache
}));
184 * Creates an in reference for reference types that do hav this.
187 * @param referenceType
191 private void createInReferenceByType(ICdmFormElement element
,
192 ReferenceType referenceType
, Reference reference
, int style
) {
193 boolean createInReferenceWidget
= true;
194 String label
= "In Reference";
196 switch (referenceType
) {
203 label
= "Print Series";
211 createInReferenceWidget
= false;
214 if (createInReferenceWidget
) {
215 selection_inReference
= (ReferenceSelectionElement
) formFactory
216 .createSelectionElement(SelectionType
.REFERENCE
,
217 getConversationHolder(), element
, label
,
218 reference
.getInReference(),
219 ReferenceSelectionElement
.DEFAULT
, style
);
224 * Creates additional controls to edit a generic reference
231 private void createGenericControls(ICdmFormElement element
,
232 Reference reference
, int style
) {
235 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
236 reference
.getEditor(), style
);
239 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
240 reference
.getSeries(), style
);
243 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
244 reference
.getVolume(), style
);
247 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
248 reference
.getPages(), style
);
252 * Creates additional controls to edit a publication
259 private void createPublicationControls(ICdmFormElement element
,
260 ReferenceType referenceType
, Reference reference
, int style
) {
263 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
264 "Place Published", reference
.getPlacePublished(), style
);
267 text_publisher
= formFactory
.createTextWithLabelElement(element
,
268 "Publisher", reference
.getPublisher(), style
);
270 if (referenceType
.equals(ReferenceType
.Journal
)) {
272 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
273 reference
.getIssn(), style
);
276 if (referenceType
.equals(ReferenceType
.Report
)) {
278 selection_institution
= (InstitutionSelectionElement
) formFactory
279 .createSelectionElement(SelectionType
.INSTITUTION
,
280 getConversationHolder(), element
, "Institution",
281 reference
.getInstitution(),
282 InstitutionSelectionElement
.DEFAULT
, style
);
285 if (referenceType
.equals(ReferenceType
.Thesis
)) {
287 selection_institution
= (InstitutionSelectionElement
) formFactory
288 .createSelectionElement(SelectionType
.INSTITUTION
,
289 getConversationHolder(), element
, "School",
290 reference
.getSchool(),
291 InstitutionSelectionElement
.DEFAULT
, style
);
294 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
296 text_organisation
= formFactory
.createTextWithLabelElement(element
,
297 "Organisation", reference
.getOrganization(), style
);
302 * Creates additional controls to edit a section
308 private void createSectionControls(ICdmFormElement element
,
309 Reference reference
, int style
) {
311 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
312 reference
.getPages(), style
);
316 * Creates additional controls to edit a volume
322 private void createVolumeControls(ICdmFormElement element
,
323 Reference reference
, int style
) {
325 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
326 reference
.getVolume(), style
);
328 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
329 reference
.getSeries(), style
);
335 * @param referenceType
339 private void createPrintedUnitControls(ICdmFormElement element
,
340 ReferenceType referenceType
, Reference reference
, int style
) {
342 selection_inSeries
= (ReferenceSelectionElement
) formFactory
343 .createSelectionElement(SelectionType
.REFERENCE
,
344 getConversationHolder(), element
, "In Series",
345 reference
.getInSeries(),
346 ReferenceSelectionElement
.DEFAULT
, style
);
349 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
350 reference
.getEditor(), style
);
353 text_seriesPart
= formFactory
.createTextWithLabelElement(element
,
354 "Series Part", reference
.getSeriesPart(), style
);
356 if (referenceType
.equals(ReferenceType
.Book
)) {
358 text_edition
= formFactory
.createTextWithLabelElement(element
,
359 "Edition", reference
.getEdition(), style
);
362 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
363 reference
.getIsbn(), style
);
367 private void createUriAndAbstract(ICdmFormElement element
,
368 Reference reference
, int style
) {
370 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
371 reference
.getUri(), style
);
373 text_referenceAbstract
= formFactory
.createMultilineTextWithLabel(
374 element
, "Reference Abstract", 100, style
);
375 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
380 public void handleEvent(Object eventSource
) {
381 if (eventSource
== combo_referenceType
) {
382 getEntity().setType(combo_referenceType
.getSelection());
384 } else if (eventSource
== element_timePeriod
) {
385 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
389 else if (eventSource
== selection_authorTeam
) {
390 getEntity().setAuthorTeam(
391 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
392 } else if (eventSource
== selection_inReference
) {
393 getEntity().setInReference(selection_inReference
.getSelection());
394 } else if (eventSource
== selection_inSeries
) {
395 getEntity().setInReference(selection_inSeries
.getSelection());
396 } else if (eventSource
== selection_institution
) {
397 getEntity().setInstitution(selection_institution
.getSelection());
401 else if (eventSource
== toggleable_cache
) {
402 handleToggleableCacheField();
403 } else if (eventSource
== text_edition
) {
404 getEntity().setEdition(text_edition
.getText());
405 } else if (eventSource
== text_editor
) {
406 getEntity().setEditor(text_editor
.getText());
407 } else if (eventSource
== text_isbn
) {
408 getEntity().setIsbn(text_isbn
.getText());
409 } else if (eventSource
== text_issn
) {
410 getEntity().setIssn(text_issn
.getText());
411 } else if (eventSource
== text_organisation
) {
412 getEntity().setOrganization(text_organisation
.getText());
413 } else if (eventSource
== text_pages
) {
414 getEntity().setPages(text_pages
.getText());
415 } else if (eventSource
== text_placePublished
) {
416 getEntity().setPlacePublished(text_placePublished
.getText());
417 } else if (eventSource
== text_publisher
) {
418 getEntity().setPublisher(text_publisher
.getText());
419 } else if (eventSource
== text_referenceAbstract
) {
420 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
421 } else if (eventSource
== text_series
) {
422 getEntity().setSeries(text_series
.getText());
423 } else if (eventSource
== text_seriesPart
) {
424 getEntity().setSeriesPart(text_seriesPart
.getText());
425 } else if (eventSource
== text_title
) {
426 getEntity().setTitle(text_title
.getText());
427 } else if (eventSource
== text_uri
) {
429 getEntity().setUri(text_uri
.getUri());
430 } catch (URISyntaxException e
) {
431 StoreUtil
.warningDialog("Invlid URI", getClass(),
432 e
.getLocalizedMessage());
434 } else if (eventSource
== text_volume
) {
435 getEntity().setVolume(text_volume
.getText());
438 else if (eventSource
!= toggleable_cache
) {
439 toggleable_cache
.setText(getEntity().getTitleCache());
442 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
449 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
450 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
454 public void handleException(CdmPropertyChangeEvent event
) {
455 exceptionOccurred(event
);
461 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
465 public void clearException() {
466 exceptionOccurred(null);
469 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
475 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
476 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
480 public void addExceptionHandler(IExceptionHandler handler
) {
481 exceptionHandlers
.add(handler
);
488 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
489 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
493 public void removeExceptionHandler(IExceptionHandler handler
) {
494 exceptionHandlers
.remove(handler
);
501 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
502 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
506 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
507 for (IExceptionHandler handler
: exceptionHandlers
) {
509 handler
.clearException();
511 handler
.handleException(event
);