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
.AbstractCdmDetailElement
;
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 AbstractCdmDetailElement
<Reference
>
53 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 * Constructor for ReferenceBaseDetailElement.
84 * @param cdmFormFactory
85 * a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory}
88 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
93 public ReferenceDetailElement(CdmFormFactory cdmFormFactory
,
94 ICdmFormElement formElement
, int style
) {
95 super(cdmFormFactory
, formElement
);
102 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
103 * #createControl(org.eclipse.swt.widgets.Composite, int)
107 protected void createControls(ICdmFormElement formElement
,
108 Reference entity
, int style
) {
109 toggleable_cache
= formFactory
.createToggleableTextField(formElement
,
110 "Reference Cache", entity
.getTitleCache(),
111 entity
.isProtectedTitleCache(), style
);
113 combo_referenceType
= (ReferenceTypeComboElement
) formFactory
114 .createEnumComboElement(EnumComboType
.REFERENCETYPE
,
117 combo_referenceType
.setSelection(entity
.getType());
120 text_title
= formFactory
.createTextWithLabelElement(formElement
,
121 "Title", entity
.getTitle(), style
);
124 selection_authorTeam
= (AgentSelectionElement
) formFactory
125 .createSelectionElement(SelectionType
.AGENT
,
126 getConversationHolder(), formElement
, "Author",
127 AuthorHelper
.getAuthor(entity
.getAuthorTeam()),
128 AgentSelectionElement
.DEFAULT
, style
);
130 ReferenceType referenceType
= entity
.getType();
132 if (referenceType
!= null) {
134 createInReferenceByType(this, referenceType
, entity
, SWT
.NULL
);
136 if (referenceType
.equals(ReferenceType
.Generic
)) {
137 createGenericControls(this, entity
, SWT
.NULL
);
138 createPublicationControls(this, referenceType
, entity
, SWT
.NULL
);
140 if (referenceType
.isPrintedUnit()) {
141 createPrintedUnitControls(this, referenceType
, entity
,
144 if (referenceType
.isPublication()) {
145 createPublicationControls(this, referenceType
, entity
,
148 if (referenceType
.isVolumeReference()) {
149 createVolumeControls(this, entity
, SWT
.NULL
);
151 if (referenceType
.isSection()) {
152 createSectionControls(this, entity
, SWT
.NULL
);
158 element_timePeriod
= formFactory
.createTimePeriodElement(formElement
,
159 "Date Published", entity
.getDatePublished(), style
);
161 createUriAndAbstract(this, entity
, SWT
.NULL
);
168 * eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
173 protected void updateContent() {
174 if (getEntity() == null) {
175 setEntity(ReferenceFactory
.newGeneric());
178 super.updateContent();
180 // enable elements according to state of cache protection
181 // setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
182 // Object[]{text_cache}));
183 toggleable_cache
.setEnabled(getEntity().isProtectedTitleCache());
184 setIrrelevant(toggleable_cache
.getState(),
185 Arrays
.asList(new Object
[] { toggleable_cache
}));
189 * Creates an in reference for reference types that do hav this.
192 * @param referenceType
196 private void createInReferenceByType(ICdmFormElement element
,
197 ReferenceType referenceType
, Reference reference
, int style
) {
198 boolean createInReferenceWidget
= true;
199 String label
= "In Reference";
201 switch (referenceType
) {
208 label
= "Print Series";
216 createInReferenceWidget
= false;
219 if (createInReferenceWidget
) {
220 selection_inReference
= (ReferenceSelectionElement
) formFactory
221 .createSelectionElement(SelectionType
.REFERENCE
,
222 getConversationHolder(), element
, label
,
223 reference
.getInReference(),
224 ReferenceSelectionElement
.DEFAULT
, style
);
229 * Creates additional controls to edit a generic reference
236 private void createGenericControls(ICdmFormElement element
,
237 Reference reference
, int style
) {
240 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
241 reference
.getEditor(), style
);
244 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
245 reference
.getSeries(), style
);
248 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
249 reference
.getVolume(), style
);
252 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
253 reference
.getPages(), style
);
257 * Creates additional controls to edit a publication
264 private void createPublicationControls(ICdmFormElement element
,
265 ReferenceType referenceType
, Reference reference
, int style
) {
268 text_placePublished
= formFactory
.createTextWithLabelElement(element
,
269 "Place Published", reference
.getPlacePublished(), style
);
272 text_publisher
= formFactory
.createTextWithLabelElement(element
,
273 "Publisher", reference
.getPublisher(), style
);
275 if (referenceType
.equals(ReferenceType
.Journal
)) {
277 text_issn
= formFactory
.createTextWithLabelElement(element
, "ISSN",
278 reference
.getIssn(), style
);
281 if (referenceType
.equals(ReferenceType
.Report
)) {
283 selection_institution
= (InstitutionSelectionElement
) formFactory
284 .createSelectionElement(SelectionType
.INSTITUTION
,
285 getConversationHolder(), element
, "Institution",
286 reference
.getInstitution(),
287 InstitutionSelectionElement
.DEFAULT
, style
);
290 if (referenceType
.equals(ReferenceType
.Thesis
)) {
292 selection_institution
= (InstitutionSelectionElement
) formFactory
293 .createSelectionElement(SelectionType
.INSTITUTION
,
294 getConversationHolder(), element
, "School",
295 reference
.getSchool(),
296 InstitutionSelectionElement
.DEFAULT
, style
);
299 if (referenceType
.equals(ReferenceType
.Proceedings
)) {
301 text_organisation
= formFactory
.createTextWithLabelElement(element
,
302 "Organisation", reference
.getOrganization(), style
);
307 * Creates additional controls to edit a section
313 private void createSectionControls(ICdmFormElement element
,
314 Reference reference
, int style
) {
316 text_pages
= formFactory
.createTextWithLabelElement(element
, "Pages",
317 reference
.getPages(), style
);
321 * Creates additional controls to edit a volume
327 private void createVolumeControls(ICdmFormElement element
,
328 Reference reference
, int style
) {
330 text_volume
= formFactory
.createTextWithLabelElement(element
, "Volume",
331 reference
.getVolume(), style
);
333 text_series
= formFactory
.createTextWithLabelElement(element
, "Series",
334 reference
.getSeries(), style
);
340 * @param referenceType
344 private void createPrintedUnitControls(ICdmFormElement element
,
345 ReferenceType referenceType
, Reference reference
, int style
) {
347 selection_inSeries
= (ReferenceSelectionElement
) formFactory
348 .createSelectionElement(SelectionType
.REFERENCE
,
349 getConversationHolder(), element
, "In Series",
350 reference
.getInSeries(),
351 ReferenceSelectionElement
.DEFAULT
, style
);
354 text_editor
= formFactory
.createTextWithLabelElement(element
, "Editor",
355 reference
.getEditor(), style
);
358 text_seriesPart
= formFactory
.createTextWithLabelElement(element
,
359 "Series Part", reference
.getSeriesPart(), style
);
361 if (referenceType
.equals(ReferenceType
.Book
)) {
363 text_edition
= formFactory
.createTextWithLabelElement(element
,
364 "Edition", reference
.getEdition(), style
);
367 text_isbn
= formFactory
.createTextWithLabelElement(element
, "ISBN",
368 reference
.getIsbn(), style
);
372 private void createUriAndAbstract(ICdmFormElement element
,
373 Reference reference
, int style
) {
375 text_uri
= formFactory
.createUriWithLabelElement(element
, "URI",
376 reference
.getUri(), style
);
378 text_referenceAbstract
= formFactory
.createMultilineTextWithLabel(
379 element
, "Reference Abstract", 100, style
);
380 text_referenceAbstract
.setText(reference
.getReferenceAbstract());
385 public void handleEvent(Object eventSource
) {
386 if (eventSource
== combo_referenceType
) {
387 getEntity().setType(combo_referenceType
.getSelection());
388 getParentElement().refresh();
389 } else if (eventSource
== element_timePeriod
) {
390 getEntity().setDatePublished(element_timePeriod
.getTimePeriod());
394 else if (eventSource
== selection_authorTeam
) {
395 getEntity().setAuthorTeam(
396 (TeamOrPersonBase
) selection_authorTeam
.getSelection());
397 } else if (eventSource
== selection_inReference
) {
398 getEntity().setInReference(selection_inReference
.getSelection());
399 } else if (eventSource
== selection_inSeries
) {
400 getEntity().setInReference(selection_inSeries
.getSelection());
401 } else if (eventSource
== selection_institution
) {
402 getEntity().setInstitution(selection_institution
.getSelection());
406 else if (eventSource
== toggleable_cache
) {
407 getEntity().setTitleCache(toggleable_cache
.getText(),
408 toggleable_cache
.getState());
409 // setEnabled(! text_cache.getState(), Arrays.asList(new
410 // Object[]{text_cache}));
411 setIrrelevant(toggleable_cache
.getState(),
412 Arrays
.asList(new Object
[] { toggleable_cache
}));
413 } else if (eventSource
== text_edition
) {
414 getEntity().setEdition(text_edition
.getText());
415 } else if (eventSource
== text_editor
) {
416 getEntity().setEditor(text_editor
.getText());
417 } else if (eventSource
== text_isbn
) {
418 getEntity().setIsbn(text_isbn
.getText());
419 } else if (eventSource
== text_issn
) {
420 getEntity().setIssn(text_issn
.getText());
421 } else if (eventSource
== text_organisation
) {
422 getEntity().setOrganization(text_organisation
.getText());
423 } else if (eventSource
== text_pages
) {
424 getEntity().setPages(text_pages
.getText());
425 } else if (eventSource
== text_placePublished
) {
426 getEntity().setPlacePublished(text_placePublished
.getText());
427 } else if (eventSource
== text_publisher
) {
428 getEntity().setPublisher(text_publisher
.getText());
429 } else if (eventSource
== text_referenceAbstract
) {
430 getEntity().setReferenceAbstract(text_referenceAbstract
.getText());
431 } else if (eventSource
== text_series
) {
432 getEntity().setSeries(text_series
.getText());
433 } else if (eventSource
== text_seriesPart
) {
434 getEntity().setSeriesPart(text_seriesPart
.getText());
435 } else if (eventSource
== text_title
) {
436 getEntity().setTitle(text_title
.getText());
437 } else if (eventSource
== text_uri
) {
439 getEntity().setUri(text_uri
.getUri());
440 } catch (URISyntaxException e
) {
441 StoreUtil
.warningDialog("Invlid URI", getClass(),
442 e
.getLocalizedMessage());
444 } else if (eventSource
== text_volume
) {
445 getEntity().setVolume(text_volume
.getText());
448 else if (eventSource
!= toggleable_cache
) {
449 toggleable_cache
.setText(getEntity().getTitleCache());
452 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
459 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
460 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
464 public void handleException(CdmPropertyChangeEvent event
) {
465 exceptionOccurred(event
);
471 * @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
475 public void clearException() {
476 exceptionOccurred(null);
479 private final List
<IExceptionHandler
> exceptionHandlers
= new ArrayList
<IExceptionHandler
>();
485 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
486 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
490 public void addExceptionHandler(IExceptionHandler handler
) {
491 exceptionHandlers
.add(handler
);
498 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
499 * (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
503 public void removeExceptionHandler(IExceptionHandler handler
) {
504 exceptionHandlers
.remove(handler
);
511 * eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
512 * (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
516 public void exceptionOccurred(CdmPropertyChangeEvent event
) {
517 for (IExceptionHandler handler
: exceptionHandlers
) {
519 handler
.clearException();
521 handler
.handleException(event
);