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
.forms
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.EnumComboType
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.SelectionType
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IErrorIntolerableElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IExceptionHandler
;
33 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TimePeriodElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ToggleableTextElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.forms
.UriWithLabelElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.selection
.AgentSelectionElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.selection
.InstitutionSelectionElement
;
40 import eu
.etaxonomy
.taxeditor
.ui
.selection
.ReferenceSelectionElement
;
41 import eu
.etaxonomy
.taxeditor
.ui
.term
.ReferenceTypeComboElement
;
45 * ReferenceBaseDetailElement class.
49 * @created Mar 2, 2010
52 public class ReferenceDetailElement
extends AbstractIdentifiableEntityDetailElement
<Reference
>
53 implements IErrorIntolerableElement
, IExceptionHandler
{
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_title
;
67 private TextWithLabelElement text_volume
;
68 private UriWithLabelElement text_uri
;
69 private AgentSelectionElement selection_authorTeam
;
70 private TimePeriodElement element_timePeriod
;
71 private ReferenceSelectionElement selection_inReference
;
72 private InstitutionSelectionElement selection_institution
;
73 private ReferenceTypeComboElement combo_referenceType
;
75 private ReferenceSelectionElement selection_inSeries
;
79 * Constructor for ReferenceBaseDetailElement.
82 * @param cdmFormFactory
83 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
86 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
91 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
92 ICdmFormElement formElement
, int style
) {
93 super(cdmFormFactory
, formElement
);
100 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
101 * #createControl(org.eclipse.swt.widgets.Composite, int)
105 protected void createControls(ICdmFormElement formElement
,
106 Reference entity
, int style
) {
107 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
108 "Reference Cache", entity
.getTitleCache(),
109 entity
.isProtectedTitleCache(), style
);
111 combo_referenceType
= (ReferenceTypeComboElement
) formFactory
112 .createEnumComboElement(EnumComboType
.REFERENCETYPE
,
115 combo_referenceType
.setSelection(entity
.getType());
118 text_title
= formFactory
.createTextWithLabelElement(formElement
,
119 "Title", entity
.getTitle(), style
);
122 selection_authorTeam
= (AgentSelectionElement
) formFactory
123 .createSelectionElement(SelectionType
.AGENT
,
124 getConversationHolder(), formElement
, "Author",
125 AuthorHelper
.getAuthor(entity
.getAuthorTeam()),
126 AgentSelectionElement
.DEFAULT
, style
);
128 ReferenceType referenceType
= entity
.getType();
130 if (referenceType
!= null) {
132 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
134 if (referenceType
.equals(ReferenceType
.Generic
)) {
135 createGenericControls(this, entity
, SWT
.NULL
);
136 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
138 if (referenceType
.isPrintedUnit()) {
139 createPrintedUnitControls(this, referenceType
, entity
,
142 if (referenceType
.isPublication()) {
143 createPublicationControls(this, referenceType
, entity
,
146 if (referenceType
.isVolumeReference()) {
147 createVolumeControls(this, entity
, SWT
.NULL
);
149 if (referenceType
.isSection()) {
150 createSectionControls(this, entity
, SWT
.NULL
);
156 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
,
157 "Date Published", entity
.getDatePublished(), style
);
159 createUriAndAbstract(this, entity
, SWT
.NULL
);
166 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
171 protected void updateContent() {
172 if (getEntity() == null) {
173 setEntity(ReferenceFactory
.newGeneric());
176 super.updateContent();
178 // enable elements according to state of cache protection
179 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
180 // Object[]{text_cache}));
181 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
182 setIrrelevant(toggleable_cache
.getState(),
183 Arrays
.asList(new Object
[] { toggleable_cache
}));
187 * Creates an in reference for reference types that do hav this.
190 * @param referenceType
194 private void createInReferenceByType(ICdmFormElement element
,
195 ReferenceType referenceType
, Reference reference
, int style
) {
196 boolean createInReferenceWidget
= true;
197 String label
= "In Reference";
199 switch (referenceType
) {
206 label
= "Print Series";
214 createInReferenceWidget
= false;
217 if (createInReferenceWidget
) {
218 selection_inReference
= (ReferenceSelectionElement
) formFactory
219 .createSelectionElement(SelectionType
.REFERENCE
,
220 getConversationHolder(), element
, label
,
221 reference
.getInReference(),
222 ReferenceSelectionElement
.DEFAULT
, style
);
227 * Creates additional controls to edit a generic reference
234 private void createGenericControls(ICdmFormElement element
,
235 Reference reference
, int style
) {
238 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
239 reference
.getEditor(), style
);
242 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
243 reference
.getSeries(), style
);
246 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
247 reference
.getVolume(), style
);
250 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
251 reference
.getPages(), style
);
255 * Creates additional controls to edit a publication
262 private void createPublicationControls(ICdmFormElement element
,
263 ReferenceType referenceType
, Reference reference
, int style
) {
266 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
267 "Place Published", reference
.getPlacePublished(), style
);
270 text_publisher
= formFactory
.createTextWithLabelElement(element
,
271 "Publisher", reference
.getPublisher(), style
);
273 if (referenceType
.equals(ReferenceType
.Journal
)) {
275 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
276 reference
.getIssn(), style
);
279 if (referenceType
.equals(ReferenceType
.Report
)) {
281 selection_institution
= (InstitutionSelectionElement
) formFactory
282 .createSelectionElement(SelectionType
.INSTITUTION
,
283 getConversationHolder(), element
, "Institution",
284 reference
.getInstitution(),
285 InstitutionSelectionElement
.DEFAULT
, style
);
288 if (referenceType
.equals(ReferenceType
.Thesis
)) {
290 selection_institution
= (InstitutionSelectionElement
) formFactory
291 .createSelectionElement(SelectionType
.INSTITUTION
,
292 getConversationHolder(), element
, "School",
293 reference
.getSchool(),
294 InstitutionSelectionElement
.DEFAULT
, style
);
297 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
299 text_organisation
= formFactory
.createTextWithLabelElement(element
,
300 "Organisation", reference
.getOrganization(), style
);
305 * Creates additional controls to edit a section
311 private void createSectionControls(ICdmFormElement element
,
312 Reference reference
, int style
) {
314 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
315 reference
.getPages(), style
);
319 * Creates additional controls to edit a volume
325 private void createVolumeControls(ICdmFormElement element
,
326 Reference reference
, int style
) {
328 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
329 reference
.getVolume(), style
);
331 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
332 reference
.getSeries(), style
);
338 * @param referenceType
342 private void createPrintedUnitControls(ICdmFormElement element
,
343 ReferenceType referenceType
, Reference reference
, int style
) {
345 selection_inSeries
= (ReferenceSelectionElement
) formFactory
346 .createSelectionElement(SelectionType
.REFERENCE
,
347 getConversationHolder(), element
, "In Series",
348 reference
.getInSeries(),
349 ReferenceSelectionElement
.DEFAULT
, style
);
352 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
353 reference
.getEditor(), style
);
356 text_seriesPart
= formFactory
.createTextWithLabelElement(element
,
357 "Series Part", reference
.getSeriesPart(), style
);
359 if (referenceType
.equals(ReferenceType
.Book
)) {
361 text_edition
= formFactory
.createTextWithLabelElement(element
,
362 "Edition", reference
.getEdition(), style
);
365 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
366 reference
.getIsbn(), style
);
370 private void createUriAndAbstract(ICdmFormElement element
,
371 Reference reference
, int style
) {
373 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
374 reference
.getUri(), style
);
376 text_referenceAbstract
= formFactory
.createMultilineTextWithLabel(
377 element
, "Reference Abstract", 100, style
);
378 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
383 public void handleEvent(Object eventSource
) {
384 if (eventSource
== combo_referenceType
) {
385 getEntity().setType(combo_referenceType
.getSelection());
386 getParentElement().refresh();
387 } else if (eventSource
== element_timePeriod
) {
388 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
392 else if (eventSource
== selection_authorTeam
) {
393 getEntity().setAuthorTeam(
394 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
395 } else if (eventSource
== selection_inReference
) {
396 getEntity().setInReference(selection_inReference
.getSelection());
397 } else if (eventSource
== selection_inSeries
) {
398 getEntity().setInReference(selection_inSeries
.getSelection());
399 } else if (eventSource
== selection_institution
) {
400 getEntity().setInstitution(selection_institution
.getSelection());
404 else if (eventSource
== toggleable_cache
) {
405 handleToggleableCacheField();
406 } else if (eventSource
== text_edition
) {
407 getEntity().setEdition(text_edition
.getText());
408 } else if (eventSource
== text_editor
) {
409 getEntity().setEditor(text_editor
.getText());
410 } else if (eventSource
== text_isbn
) {
411 getEntity().setIsbn(text_isbn
.getText());
412 } else if (eventSource
== text_issn
) {
413 getEntity().setIssn(text_issn
.getText());
414 } else if (eventSource
== text_organisation
) {
415 getEntity().setOrganization(text_organisation
.getText());
416 } else if (eventSource
== text_pages
) {
417 getEntity().setPages(text_pages
.getText());
418 } else if (eventSource
== text_placePublished
) {
419 getEntity().setPlacePublished(text_placePublished
.getText());
420 } else if (eventSource
== text_publisher
) {
421 getEntity().setPublisher(text_publisher
.getText());
422 } else if (eventSource
== text_referenceAbstract
) {
423 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
424 } else if (eventSource
== text_series
) {
425 getEntity().setSeries(text_series
.getText());
426 } else if (eventSource
== text_seriesPart
) {
427 getEntity().setSeriesPart(text_seriesPart
.getText());
428 } else if (eventSource
== text_title
) {
429 getEntity().setTitle(text_title
.getText());
430 } else if (eventSource
== text_uri
) {
432 getEntity().setUri(text_uri
.getUri());
433 } catch (URISyntaxException e
) {
434 StoreUtil
.warningDialog("Invlid URI", getClass(),
435 e
.getLocalizedMessage());
437 } else if (eventSource
== text_volume
) {
438 getEntity().setVolume(text_volume
.getText());
441 else if (eventSource
!= toggleable_cache
) {
442 toggleable_cache
.setText(getEntity().getTitleCache());
445 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
452 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
453 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
457 public void handleException(CdmPropertyChangeEvent event
) {
458 exceptionOccurred(event
);
464 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
468 public void clearException() {
469 exceptionOccurred(null);
472 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
478 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
479 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
483 public void addExceptionHandler(IExceptionHandler handler
) {
484 exceptionHandlers
.add(handler
);
491 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
492 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
496 public void removeExceptionHandler(IExceptionHandler handler
) {
497 exceptionHandlers
.remove(handler
);
504 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
505 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
509 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
510 for (IExceptionHandler handler
: exceptionHandlers
) {
512 handler
.clearException();
514 handler
.handleException(event
);