1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.section.reference;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
|
17
|
import org.eclipse.swt.SWT;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
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.forms.CdmFormFactory;
|
26
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.EnumComboType;
|
27
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType;
|
28
|
import eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent;
|
29
|
import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement;
|
31
|
import eu.etaxonomy.taxeditor.forms.IExceptionHandler;
|
32
|
import eu.etaxonomy.taxeditor.forms.TextWithLabelElement;
|
33
|
import eu.etaxonomy.taxeditor.forms.TimePeriodElement;
|
34
|
import eu.etaxonomy.taxeditor.forms.ToggleableTextElement;
|
35
|
import eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement;
|
36
|
import eu.etaxonomy.taxeditor.forms.selection.ReferenceSelectionElement;
|
37
|
import eu.etaxonomy.taxeditor.forms.term.ReferenceTypeComboElement;
|
38
|
import eu.etaxonomy.taxeditor.model.AuthorHelper;
|
39
|
import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
|
40
|
|
41
|
/**
|
42
|
* <p>ReferenceBaseDetailElement class.</p>
|
43
|
*
|
44
|
* @author n.hoffmann
|
45
|
* @created Mar 2, 2010
|
46
|
* @version 1.0
|
47
|
*/
|
48
|
public class ReferenceBaseDetailElement extends AbstractCdmDetailElement<Reference> implements IErrorIntolerableElement, IExceptionHandler {
|
49
|
|
50
|
// property holder
|
51
|
private ToggleableTextElement toggleable_cache;
|
52
|
private TextWithLabelElement text_edition;
|
53
|
private TextWithLabelElement text_editor;
|
54
|
private TextWithLabelElement text_isbn;
|
55
|
private TextWithLabelElement text_issn;
|
56
|
private TextWithLabelElement text_organisation;
|
57
|
private TextWithLabelElement text_pages;
|
58
|
private TextWithLabelElement text_placePublished;
|
59
|
private TextWithLabelElement text_publisher;
|
60
|
private TextWithLabelElement text_referenceAbstract;
|
61
|
private TextWithLabelElement text_series;
|
62
|
private TextWithLabelElement text_seriesPart;
|
63
|
private TextWithLabelElement text_title;
|
64
|
private TextWithLabelElement text_volume;
|
65
|
private TextWithLabelElement text_uri;
|
66
|
private AbstractSelectionElement<AgentBase> selection_authorTeam;
|
67
|
private TimePeriodElement element_timePeriod;
|
68
|
private AbstractSelectionElement<Reference> selection_inReference;
|
69
|
private AbstractSelectionElement<Institution> selection_institution;
|
70
|
private ReferenceTypeComboElement combo_referenceType;
|
71
|
|
72
|
private ReferenceSelectionElement selection_inSeries;
|
73
|
|
74
|
|
75
|
/**
|
76
|
* <p>Constructor for ReferenceBaseDetailElement.</p>
|
77
|
*
|
78
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
|
79
|
* @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
|
80
|
* @param style a int.
|
81
|
*/
|
82
|
public ReferenceBaseDetailElement(CdmFormFactory cdmFormFactory,
|
83
|
ICdmFormElement formElement, int style) {
|
84
|
super(cdmFormFactory, formElement);
|
85
|
}
|
86
|
|
87
|
/*
|
88
|
* (non-Javadoc)
|
89
|
* @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite#createControl(org.eclipse.swt.widgets.Composite, int)
|
90
|
*/
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
protected void createControls(ICdmFormElement formElement, Reference entity, int style) {
|
94
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Reference Cache", entity.getTitleCache(), entity.isProtectedTitleCache(), style);
|
95
|
|
96
|
combo_referenceType = (ReferenceTypeComboElement) formFactory.createEnumComboElement(EnumComboType.REFERENCETYPE, formElement, style);
|
97
|
|
98
|
combo_referenceType.setSelection(entity.getType());
|
99
|
|
100
|
// title
|
101
|
text_title = formFactory.createTextWithLabelElement(formElement, "Title", entity.getTitle(), style);
|
102
|
|
103
|
// author team
|
104
|
selection_authorTeam = formFactory.createSelectionElement(SelectionType.TEAM, getConversationHolder(), formElement, "Author", AuthorHelper.getAuthor(entity.getAuthorTeam()), style);
|
105
|
|
106
|
ReferenceType referenceType = entity.getType();
|
107
|
|
108
|
if(referenceType != null && referenceType.equals(ReferenceType.Generic)){
|
109
|
createGenericControls(this, entity, SWT.NULL);
|
110
|
}else if(referenceType != null){
|
111
|
if(referenceType.isPrintedUnit()){
|
112
|
createPrintedUnitControls(this, referenceType, entity, SWT.NULL);
|
113
|
}
|
114
|
if(referenceType.isPublication()){
|
115
|
createPublicationControls(this, referenceType, entity, SWT.NULL);
|
116
|
}
|
117
|
if(referenceType.isVolumeReference()){
|
118
|
createVolumeControls(this, entity, SWT.NULL);
|
119
|
}
|
120
|
if(referenceType.isSection()){
|
121
|
createSectionControls(this, entity, SWT.NULL);
|
122
|
}
|
123
|
}
|
124
|
|
125
|
// date published
|
126
|
element_timePeriod = formFactory.createTimePeriodElement(formElement, "Date Published", entity.getDatePublished(), style);
|
127
|
element_timePeriod.addExceptionHandler(this);
|
128
|
|
129
|
createUriAndAbstract(this, entity, SWT.NULL);
|
130
|
}
|
131
|
|
132
|
/*
|
133
|
* (non-Javadoc)
|
134
|
* @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite#updateContent()
|
135
|
*/
|
136
|
/** {@inheritDoc} */
|
137
|
@Override
|
138
|
protected void updateContent() {
|
139
|
if(getEntity() == null){
|
140
|
setEntity(ReferenceFactory.newGeneric());
|
141
|
}
|
142
|
|
143
|
super.updateContent();
|
144
|
|
145
|
// enable elements according to state of cache protection
|
146
|
// setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new Object[]{text_cache}));
|
147
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
|
148
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
|
149
|
}
|
150
|
|
151
|
/**
|
152
|
* Creates additional controls to edit a generic reference
|
153
|
*
|
154
|
* @param element
|
155
|
* @param reference
|
156
|
* @param listener
|
157
|
* @param style
|
158
|
*/
|
159
|
private void createGenericControls(ICdmFormElement element, Reference reference, int style){
|
160
|
//editor
|
161
|
text_editor = formFactory.createTextWithLabelElement(element, "Editor", reference.getEditor(), style);
|
162
|
|
163
|
// series
|
164
|
text_series = formFactory.createTextWithLabelElement(element, "Series", reference.getSeries(), style);
|
165
|
|
166
|
// volume
|
167
|
text_volume = formFactory.createTextWithLabelElement(element, "Volume", reference.getVolume(), style);
|
168
|
|
169
|
// pages
|
170
|
text_pages = formFactory.createTextWithLabelElement(element, "Pages", reference.getPages(), style);
|
171
|
}
|
172
|
|
173
|
|
174
|
/**
|
175
|
* Creates addition controls to edit a publication
|
176
|
*
|
177
|
* @param element
|
178
|
* @param reference
|
179
|
* @param listener
|
180
|
* @param style
|
181
|
*/
|
182
|
private void createPublicationControls(ICdmFormElement element, ReferenceType referenceType, Reference reference, int style){
|
183
|
|
184
|
// placePublished
|
185
|
text_placePublished = formFactory.createTextWithLabelElement(element, "Place Published", reference.getPlacePublished(), style);
|
186
|
|
187
|
// publisher
|
188
|
text_publisher = formFactory.createTextWithLabelElement(element, "Publisher", reference.getPublisher(), style);
|
189
|
|
190
|
if(referenceType.equals(ReferenceType.Journal)){
|
191
|
//issn
|
192
|
text_issn = formFactory.createTextWithLabelElement(element, "ISSN", reference.getIssn(), style);
|
193
|
}
|
194
|
|
195
|
if(referenceType.equals(ReferenceType.Report)){
|
196
|
// institution
|
197
|
selection_institution = formFactory.createSelectionElement(SelectionType.INSTITUTION, getConversationHolder(), element, "Institution", reference.getInstitution(), style);
|
198
|
}
|
199
|
|
200
|
if(referenceType.equals(ReferenceType.Thesis)){
|
201
|
// school
|
202
|
selection_institution = formFactory.createSelectionElement(SelectionType.INSTITUTION, getConversationHolder(), element, "School", reference.getSchool(), style);
|
203
|
}
|
204
|
|
205
|
if(referenceType.equals(ReferenceType.Proceedings)){
|
206
|
//organization
|
207
|
text_organisation = formFactory.createTextWithLabelElement(element, "Organisation", reference.getOrganization(), style);
|
208
|
}
|
209
|
}
|
210
|
|
211
|
|
212
|
/**
|
213
|
*
|
214
|
* @param element
|
215
|
* @param reference
|
216
|
* @param style
|
217
|
*/
|
218
|
private void createSectionControls(ICdmFormElement element, Reference reference, int style){
|
219
|
|
220
|
// in reference
|
221
|
if(reference.getType() == ReferenceType.BookSection || reference.getType() == ReferenceType.InProceedings){
|
222
|
String label = "";
|
223
|
if(reference.getType() == ReferenceType.BookSection){
|
224
|
label = "Book";
|
225
|
}else if(reference.getType() == ReferenceType.InProceedings){
|
226
|
label = "Print Series";
|
227
|
}
|
228
|
|
229
|
selection_inReference = formFactory.createSelectionElement(SelectionType.REFERENCE, getConversationHolder(), element, label, reference.getInReference(), style);
|
230
|
}
|
231
|
|
232
|
// pages
|
233
|
text_pages = formFactory.createTextWithLabelElement(element, "Pages", reference.getPages(), style);
|
234
|
}
|
235
|
|
236
|
/**
|
237
|
*
|
238
|
* @param element
|
239
|
* @param reference
|
240
|
* @param style
|
241
|
*/
|
242
|
private void createVolumeControls(ICdmFormElement element, Reference reference, int style){
|
243
|
if(reference.getType() == ReferenceType.Article){
|
244
|
selection_inReference = formFactory.createSelectionElement(SelectionType.REFERENCE, getConversationHolder(), element, "Journal", reference.getInReference(), style);
|
245
|
}
|
246
|
|
247
|
text_volume = formFactory.createTextWithLabelElement(element, "Volume", reference.getVolume(), style);
|
248
|
|
249
|
text_series = formFactory.createTextWithLabelElement(element, "Series", reference.getSeries(), style);
|
250
|
}
|
251
|
|
252
|
|
253
|
/**
|
254
|
*
|
255
|
* @param element
|
256
|
* @param referenceType
|
257
|
* @param reference
|
258
|
* @param style
|
259
|
*/
|
260
|
private void createPrintedUnitControls(ICdmFormElement element, ReferenceType referenceType, Reference reference, int style){
|
261
|
// in series
|
262
|
selection_inSeries = (ReferenceSelectionElement) formFactory.createSelectionElement(SelectionType.REFERENCE, getConversationHolder(), element, "In Series", (Reference) reference.getInSeries(), style);
|
263
|
|
264
|
//editor
|
265
|
text_editor = formFactory.createTextWithLabelElement(element, "Editor", reference.getEditor(), style);
|
266
|
|
267
|
// series part
|
268
|
text_seriesPart = formFactory.createTextWithLabelElement(element, "Series Part", reference.getSeriesPart(), style);
|
269
|
|
270
|
if(referenceType.equals(ReferenceType.Book)){
|
271
|
// edition
|
272
|
text_edition = formFactory.createTextWithLabelElement(element, "Edition", reference.getEdition(), style);
|
273
|
|
274
|
//isbn
|
275
|
text_isbn = formFactory.createTextWithLabelElement(element, "ISBN", reference.getIsbn(), style);
|
276
|
}
|
277
|
}
|
278
|
|
279
|
private void createUriAndAbstract(ICdmFormElement element,
|
280
|
Reference reference, int style) {
|
281
|
// uri
|
282
|
text_uri = formFactory.createTextWithLabelElement(element, "URI", reference.getUri(), style);
|
283
|
// abstract
|
284
|
text_referenceAbstract = formFactory.createMultilineTextWithLabel(element, "Reference Abstract", 100, style);
|
285
|
text_referenceAbstract.setText(reference.getReferenceAbstract());
|
286
|
}
|
287
|
|
288
|
|
289
|
/** {@inheritDoc} */
|
290
|
@Override
|
291
|
public void handleEvent(Object eventSource) {
|
292
|
if(eventSource == combo_referenceType){
|
293
|
getEntity().setType(combo_referenceType.getSelection());
|
294
|
getParentElement().refresh();
|
295
|
}
|
296
|
else if(eventSource == element_timePeriod){
|
297
|
getEntity().setDatePublished(element_timePeriod.getTimePeriod());
|
298
|
clearException();
|
299
|
}
|
300
|
// selections
|
301
|
else if(eventSource == selection_authorTeam){
|
302
|
getEntity().setAuthorTeam((TeamOrPersonBase)selection_authorTeam.getSelection());
|
303
|
}
|
304
|
else if(eventSource == selection_inReference){
|
305
|
getEntity().setInReference(selection_inReference.getSelection());
|
306
|
}
|
307
|
else if(eventSource == selection_inSeries){
|
308
|
getEntity().setInReference(selection_inSeries.getSelection());
|
309
|
}
|
310
|
else if(eventSource == selection_institution){
|
311
|
getEntity().setInstitution(selection_institution.getSelection());
|
312
|
}
|
313
|
|
314
|
// textfields
|
315
|
else if(eventSource == toggleable_cache){
|
316
|
getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
|
317
|
// setEnabled(! text_cache.getState(), Arrays.asList(new Object[]{text_cache}));
|
318
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
|
319
|
}
|
320
|
else if(eventSource == text_edition){
|
321
|
getEntity().setEdition(text_edition.getText());
|
322
|
}
|
323
|
else if(eventSource == text_editor){
|
324
|
getEntity().setEditor(text_editor.getText());
|
325
|
}
|
326
|
else if(eventSource == text_isbn){
|
327
|
getEntity().setIsbn(text_isbn.getText());
|
328
|
}
|
329
|
else if(eventSource == text_issn){
|
330
|
getEntity().setIssn(text_issn.getText());
|
331
|
}
|
332
|
else if(eventSource == text_organisation){
|
333
|
getEntity().setOrganization(text_organisation.getText());
|
334
|
}
|
335
|
else if(eventSource == text_pages){
|
336
|
getEntity().setPages(text_pages.getText());
|
337
|
}
|
338
|
else if(eventSource == text_placePublished){
|
339
|
getEntity().setPlacePublished(text_placePublished.getText());
|
340
|
}
|
341
|
else if(eventSource == text_publisher){
|
342
|
getEntity().setPublisher(text_publisher.getText());
|
343
|
}
|
344
|
else if(eventSource == text_referenceAbstract){
|
345
|
getEntity().setReferenceAbstract(text_referenceAbstract.getText());
|
346
|
}
|
347
|
else if(eventSource == text_series){
|
348
|
getEntity().setSeries(text_series.getText());
|
349
|
}
|
350
|
else if(eventSource == text_seriesPart){
|
351
|
getEntity().setSeriesPart(text_seriesPart.getText());
|
352
|
}
|
353
|
else if(eventSource == text_title){
|
354
|
getEntity().setTitle(text_title.getText());
|
355
|
}
|
356
|
else if(eventSource == text_uri){
|
357
|
getEntity().setUri(text_uri.getText());
|
358
|
}
|
359
|
else if(eventSource == text_volume){
|
360
|
getEntity().setVolume(text_volume.getText());
|
361
|
}
|
362
|
|
363
|
else if(eventSource != toggleable_cache){
|
364
|
toggleable_cache.setText(getEntity().getTitleCache());
|
365
|
}
|
366
|
}
|
367
|
|
368
|
/*
|
369
|
* (non-Javadoc)
|
370
|
* @see eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException(eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
|
371
|
*/
|
372
|
/** {@inheritDoc} */
|
373
|
@Override
|
374
|
public void handleException(CdmPropertyChangeEvent event) {
|
375
|
exceptionOccurred(event);
|
376
|
}
|
377
|
|
378
|
/* (non-Javadoc)
|
379
|
* @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
|
380
|
*/
|
381
|
/** {@inheritDoc} */
|
382
|
@Override
|
383
|
public void clearException() {
|
384
|
exceptionOccurred(null);
|
385
|
}
|
386
|
|
387
|
private List<IExceptionHandler> exceptionHandlers = new ArrayList<IExceptionHandler>();
|
388
|
|
389
|
/* (non-Javadoc)
|
390
|
* @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler(eu.etaxonomy.taxeditor.forms.IExceptionHandler)
|
391
|
*/
|
392
|
/** {@inheritDoc} */
|
393
|
@Override
|
394
|
public void addExceptionHandler(IExceptionHandler handler) {
|
395
|
exceptionHandlers.add(handler);
|
396
|
}
|
397
|
|
398
|
/* (non-Javadoc)
|
399
|
* @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler(eu.etaxonomy.taxeditor.forms.IExceptionHandler)
|
400
|
*/
|
401
|
/** {@inheritDoc} */
|
402
|
@Override
|
403
|
public void removeExceptionHandler(IExceptionHandler handler) {
|
404
|
exceptionHandlers.remove(handler);
|
405
|
}
|
406
|
|
407
|
/* (non-Javadoc)
|
408
|
* @see eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred(eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
|
409
|
*/
|
410
|
/** {@inheritDoc} */
|
411
|
@Override
|
412
|
public void exceptionOccurred(CdmPropertyChangeEvent event) {
|
413
|
for(IExceptionHandler handler : exceptionHandlers){
|
414
|
if(event == null) {
|
415
|
clearException();
|
416
|
}else{
|
417
|
handler.handleException(event);
|
418
|
}
|
419
|
}
|
420
|
}
|
421
|
}
|