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
.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
.model
.AuthorHelper
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
27 import eu
.etaxonomy
.taxeditor
.ui
.dialogs
.filteredSelection
.ReferenceSelectionDialog
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.EnumComboType
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.SelectionType
;
31 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
32 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IErrorIntolerableElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IExceptionHandler
;
35 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TimePeriodElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ToggleableTextElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.forms
.UriWithLabelElement
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
40 import eu
.etaxonomy
.taxeditor
.ui
.selection
.AbstractSelectionElement
;
41 import eu
.etaxonomy
.taxeditor
.ui
.selection
.AgentSelectionElement
;
42 import eu
.etaxonomy
.taxeditor
.ui
.selection
.InstitutionSelectionElement
;
43 import eu
.etaxonomy
.taxeditor
.ui
.selection
.ReferenceSelectionElement
;
44 import eu
.etaxonomy
.taxeditor
.ui
.term
.ReferenceTypeComboElement
;
47 * <p>ReferenceBaseDetailElement class.</p>
50 * @created Mar 2, 2010
53 public class ReferenceDetailElement
extends AbstractCdmDetailElement
<Reference
> implements IErrorIntolerableElement
, IExceptionHandler
{
56 private ToggleableTextElement toggleable_cache
;
57 private TextWithLabelElement text_edition
;
58 private TextWithLabelElement text_editor
;
59 private TextWithLabelElement text_isbn
;
60 private TextWithLabelElement text_issn
;
61 private TextWithLabelElement text_organisation
;
62 private TextWithLabelElement text_pages
;
63 private TextWithLabelElement text_placePublished
;
64 private TextWithLabelElement text_publisher
;
65 private TextWithLabelElement text_referenceAbstract
;
66 private TextWithLabelElement text_series
;
67 private TextWithLabelElement text_seriesPart
;
68 private TextWithLabelElement text_title
;
69 private TextWithLabelElement text_volume
;
70 private UriWithLabelElement text_uri
;
71 private AgentSelectionElement selection_authorTeam
;
72 private TimePeriodElement element_timePeriod
;
73 private ReferenceSelectionElement selection_inReference
;
74 private InstitutionSelectionElement selection_institution
;
75 private ReferenceTypeComboElement combo_referenceType
;
77 private ReferenceSelectionElement selection_inSeries
;
81 * <p>Constructor for ReferenceBaseDetailElement.</p>
83 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
84 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
87 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
88 ICdmFormElement formElement
, int style
) {
89 super(cdmFormFactory
, formElement
);
94 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite#createControl(org.eclipse.swt.widgets.Composite, int)
98 protected void createControls(ICdmFormElement formElement
, Reference entity
, int style
) {
99 toggleable_cache
= formFactory
.createToggleableTextField(formElement
, "Reference Cache", entity
.getTitleCache(), entity
.isProtectedTitleCache(), style
);
101 combo_referenceType
= (ReferenceTypeComboElement
) formFactory
.createEnumComboElement(EnumComboType
.REFERENCETYPE
, formElement
, style
);
103 combo_referenceType
.setSelection(entity
.getType());
106 text_title
= formFactory
.createTextWithLabelElement(formElement
, "Title", entity
.getTitle(), style
);
109 selection_authorTeam
= (AgentSelectionElement
) formFactory
.createSelectionElement(SelectionType
.AGENT
, getConversationHolder(), formElement
, "Author", AuthorHelper
.getAuthor(entity
.getAuthorTeam()), style
);
111 ReferenceType referenceType
= entity
.getType();
113 if(referenceType
!= null){
115 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
117 if(referenceType
.equals(ReferenceType
.Generic
)){
118 createGenericControls(this, entity
, SWT
.NULL
);
119 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
121 if(referenceType
.isPrintedUnit()){
122 createPrintedUnitControls(this, referenceType
, entity
, SWT
.NULL
);
124 if(referenceType
.isPublication()){
125 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
127 if(referenceType
.isVolumeReference()){
128 createVolumeControls(this, entity
, SWT
.NULL
);
130 if(referenceType
.isSection()){
131 createSectionControls(this, entity
, SWT
.NULL
);
137 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
, "Date Published", entity
.getDatePublished(), style
);
139 createUriAndAbstract(this, entity
, SWT
.NULL
);
144 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite#updateContent()
148 protected void updateContent() {
149 if(getEntity() == null){
150 setEntity(ReferenceFactory
.newGeneric());
153 super.updateContent();
155 // enable elements according to state of cache protection
156 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new Object[]{text_cache}));
157 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
158 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
162 * Creates an in reference for reference types that do hav this.
165 * @param referenceType
169 private void createInReferenceByType(
170 ICdmFormElement element
,
171 ReferenceType referenceType
, Reference reference
, int style
) {
172 boolean createInReferenceWidget
= true;
173 String label
= "In Reference";
175 switch(referenceType
){
182 label
= "Print Series";
190 createInReferenceWidget
= false;
193 if(createInReferenceWidget
){
194 selection_inReference
= (ReferenceSelectionElement
) formFactory
.createSelectionElement(SelectionType
.REFERENCE
, getConversationHolder(),
195 element
, label
, reference
.getInReference(), style
);
200 * Creates additional controls to edit a generic reference
207 private void createGenericControls(ICdmFormElement element
, Reference reference
, int style
){
210 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor", reference
.getEditor(), style
);
213 text_series
= formFactory
.createTextWithLabelElement(element
, "Series", reference
.getSeries(), style
);
216 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume", reference
.getVolume(), style
);
219 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages", reference
.getPages(), style
);
224 * Creates additional controls to edit a publication
231 private void createPublicationControls(ICdmFormElement element
, ReferenceType referenceType
, Reference reference
, int style
){
234 text_placePublished
= formFactory
.createTextWithLabelElement(element
, "Place Published", reference
.getPlacePublished(), style
);
237 text_publisher
= formFactory
.createTextWithLabelElement(element
, "Publisher", reference
.getPublisher(), style
);
239 if(referenceType
.equals(ReferenceType
.Journal
)){
241 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN", reference
.getIssn(), style
);
244 if(referenceType
.equals(ReferenceType
.Report
)){
246 selection_institution
= (InstitutionSelectionElement
) formFactory
.createSelectionElement(SelectionType
.INSTITUTION
, getConversationHolder(), element
, "Institution", reference
.getInstitution(), style
);
249 if(referenceType
.equals(ReferenceType
.Thesis
)){
251 selection_institution
= (InstitutionSelectionElement
) formFactory
.createSelectionElement(SelectionType
.INSTITUTION
, getConversationHolder(), element
, "School", reference
.getSchool(), style
);
254 if(referenceType
.equals(ReferenceType
.Proceedings
)){
256 text_organisation
= formFactory
.createTextWithLabelElement(element
, "Organisation", reference
.getOrganization(), style
);
262 * Creates additional controls to edit a section
268 private void createSectionControls(ICdmFormElement element
, Reference reference
, int style
){
270 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages", reference
.getPages(), style
);
274 * Creates additional controls to edit a volume
280 private void createVolumeControls(ICdmFormElement element
, Reference reference
, int style
){
282 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume", reference
.getVolume(), style
);
284 text_series
= formFactory
.createTextWithLabelElement(element
, "Series", reference
.getSeries(), style
);
291 * @param referenceType
295 private void createPrintedUnitControls(ICdmFormElement element
, ReferenceType referenceType
, Reference reference
, int style
){
297 selection_inSeries
= (ReferenceSelectionElement
) formFactory
.createSelectionElement(SelectionType
.REFERENCE
, getConversationHolder(), element
, "In Series", (Reference
) reference
.getInSeries(), style
);
300 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor", reference
.getEditor(), style
);
303 text_seriesPart
= formFactory
.createTextWithLabelElement(element
, "Series Part", reference
.getSeriesPart(), style
);
305 if(referenceType
.equals(ReferenceType
.Book
)){
307 text_edition
= formFactory
.createTextWithLabelElement(element
, "Edition", reference
.getEdition(), style
);
310 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN", reference
.getIsbn(), style
);
314 private void createUriAndAbstract(ICdmFormElement element
,
315 Reference reference
, int style
) {
317 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI", reference
.getUri(), style
);
319 text_referenceAbstract
= formFactory
.createMultilineTextWithLabel(element
, "Reference Abstract", 100, style
);
320 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
326 public void handleEvent(Object eventSource
) {
327 if(eventSource
== combo_referenceType
){
328 getEntity().setType(combo_referenceType
.getSelection());
329 getParentElement().refresh();
331 else if(eventSource
== element_timePeriod
){
332 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
336 else if(eventSource
== selection_authorTeam
){
337 getEntity().setAuthorTeam((TeamOrPersonBase
)selection_authorTeam
.getSelection());
339 else if(eventSource
== selection_inReference
){
340 getEntity().setInReference(selection_inReference
.getSelection());
342 else if(eventSource
== selection_inSeries
){
343 getEntity().setInReference(selection_inSeries
.getSelection());
345 else if(eventSource
== selection_institution
){
346 getEntity().setInstitution(selection_institution
.getSelection());
350 else if(eventSource
== toggleable_cache
){
351 getEntity().setTitleCache(toggleable_cache
.getText(), toggleable_cache
.getState());
352 // setEnabled(! text_cache.getState(), Arrays.asList(new Object[]{text_cache}));
353 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
355 else if(eventSource
== text_edition
){
356 getEntity().setEdition(text_edition
.getText());
358 else if(eventSource
== text_editor
){
359 getEntity().setEditor(text_editor
.getText());
361 else if(eventSource
== text_isbn
){
362 getEntity().setIsbn(text_isbn
.getText());
364 else if(eventSource
== text_issn
){
365 getEntity().setIssn(text_issn
.getText());
367 else if(eventSource
== text_organisation
){
368 getEntity().setOrganization(text_organisation
.getText());
370 else if(eventSource
== text_pages
){
371 getEntity().setPages(text_pages
.getText());
373 else if(eventSource
== text_placePublished
){
374 getEntity().setPlacePublished(text_placePublished
.getText());
376 else if(eventSource
== text_publisher
){
377 getEntity().setPublisher(text_publisher
.getText());
379 else if(eventSource
== text_referenceAbstract
){
380 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
382 else if(eventSource
== text_series
){
383 getEntity().setSeries(text_series
.getText());
385 else if(eventSource
== text_seriesPart
){
386 getEntity().setSeriesPart(text_seriesPart
.getText());
388 else if(eventSource
== text_title
){
389 getEntity().setTitle(text_title
.getText());
391 else if(eventSource
== text_uri
){
393 getEntity().setUri(text_uri
.getUri());
394 } catch (URISyntaxException e
) {
395 StoreUtil
.warningDialog("Invlid URI", getClass(), e
.getLocalizedMessage());
398 else if(eventSource
== text_volume
){
399 getEntity().setVolume(text_volume
.getText());
402 else if(eventSource
!= toggleable_cache
){
403 toggleable_cache
.setText(getEntity().getTitleCache());
409 * @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException(eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
413 public void handleException(CdmPropertyChangeEvent event
) {
414 exceptionOccurred(event
);
418 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
422 public void clearException() {
423 exceptionOccurred(null);
426 private List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
429 * @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler(eu.etaxonomy.taxeditor.forms.IExceptionHandler)
433 public void addExceptionHandler(IExceptionHandler handler
) {
434 exceptionHandlers
.add(handler
);
438 * @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler(eu.etaxonomy.taxeditor.forms.IExceptionHandler)
442 public void removeExceptionHandler(IExceptionHandler handler
) {
443 exceptionHandlers
.remove(handler
);
447 * @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred(eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
451 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
452 for(IExceptionHandler handler
: exceptionHandlers
){
456 handler
.handleException(event
);