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.ui.section.reference;
|
12
|
|
13
|
import java.net.URISyntaxException;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Arrays;
|
16
|
import java.util.List;
|
17
|
|
18
|
import org.eclipse.swt.SWT;
|
19
|
|
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.singlesource.ui.forms.CdmFormFactoryFacade;
|
26
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.TextWithLabelElementFacade;
|
27
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.UriWithLabelElementFacade;
|
28
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade.EnumComboType;
|
29
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade.SelectionType;
|
30
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
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.TimePeriodElement;
|
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;
|
40
|
import eu.etaxonomy.taxeditor.ui.term.ReferenceTypeComboElement;
|
41
|
|
42
|
/**
|
43
|
* <p>
|
44
|
* ReferenceBaseDetailElement class.
|
45
|
* </p>
|
46
|
*
|
47
|
* @author n.hoffmann
|
48
|
* @created Mar 2, 2010
|
49
|
* @version 1.0
|
50
|
*/
|
51
|
public class ReferenceDetailElement extends AbstractIdentifiableEntityDetailElement<Reference>
|
52
|
implements IErrorIntolerableElement, IExceptionHandler {
|
53
|
|
54
|
private TextWithLabelElementFacade text_edition;
|
55
|
private TextWithLabelElementFacade text_editor;
|
56
|
private TextWithLabelElementFacade text_isbn;
|
57
|
private TextWithLabelElementFacade text_issn;
|
58
|
private TextWithLabelElementFacade text_organisation;
|
59
|
private TextWithLabelElementFacade text_pages;
|
60
|
private TextWithLabelElementFacade text_placePublished;
|
61
|
private TextWithLabelElementFacade text_publisher;
|
62
|
private TextWithLabelElementFacade text_referenceAbstract;
|
63
|
private TextWithLabelElementFacade text_series;
|
64
|
private TextWithLabelElementFacade text_seriesPart;
|
65
|
private TextWithLabelElementFacade text_title;
|
66
|
private TextWithLabelElementFacade text_volume;
|
67
|
private UriWithLabelElementFacade text_uri;
|
68
|
private AgentSelectionElement selection_authorTeam;
|
69
|
private TimePeriodElement element_timePeriod;
|
70
|
private ReferenceSelectionElement selection_inReference;
|
71
|
private InstitutionSelectionElement selection_institution;
|
72
|
private ReferenceTypeComboElement combo_referenceType;
|
73
|
|
74
|
private ReferenceSelectionElement selection_inSeries;
|
75
|
|
76
|
/**
|
77
|
* <p>
|
78
|
* Constructor for ReferenceBaseDetailElement.
|
79
|
* </p>
|
80
|
*
|
81
|
* @param cdmFormFactory
|
82
|
* a {@link eu.etaxonomy.taxeditor.singlesource.ui.forms.CdmFormFactoryFacade}
|
83
|
* object.
|
84
|
* @param formElement
|
85
|
* a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
|
86
|
* object.
|
87
|
* @param style
|
88
|
* a int.
|
89
|
*/
|
90
|
public ReferenceDetailElement(CdmFormFactoryFacade cdmFormFactory,
|
91
|
ICdmFormElement formElement, int style) {
|
92
|
super(cdmFormFactory, formElement);
|
93
|
}
|
94
|
|
95
|
/*
|
96
|
* (non-Javadoc)
|
97
|
*
|
98
|
* @see
|
99
|
* eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
|
100
|
* #createControl(org.eclipse.swt.widgets.Composite, int)
|
101
|
*/
|
102
|
/** {@inheritDoc} */
|
103
|
@Override
|
104
|
protected void createControls(ICdmFormElement formElement,
|
105
|
Reference entity, int style) {
|
106
|
toggleable_cache = formFactory.createToggleableTextField(formElement,
|
107
|
"Reference Cache", entity.getTitleCache(),
|
108
|
entity.isProtectedTitleCache(), style);
|
109
|
|
110
|
combo_referenceType = (ReferenceTypeComboElement) formFactory
|
111
|
.createEnumComboElement(EnumComboType.REFERENCETYPE,
|
112
|
formElement, style);
|
113
|
|
114
|
combo_referenceType.setSelection(entity.getType());
|
115
|
|
116
|
// title
|
117
|
text_title = formFactory.createTextWithLabelElement(formElement,
|
118
|
"Title", entity.getTitle(), style);
|
119
|
|
120
|
// author team
|
121
|
selection_authorTeam = (AgentSelectionElement) formFactory
|
122
|
.createSelectionElement(SelectionType.AGENT,
|
123
|
getConversationHolder(), formElement, "Author",
|
124
|
AuthorHelper.getAuthor(entity.getAuthorTeam()),
|
125
|
AgentSelectionElement.DEFAULT, style);
|
126
|
|
127
|
ReferenceType referenceType = entity.getType();
|
128
|
|
129
|
if (referenceType != null) {
|
130
|
|
131
|
createInReferenceByType(this, referenceType, entity, SWT.NULL);
|
132
|
|
133
|
if (referenceType.equals(ReferenceType.Generic)) {
|
134
|
createGenericControls(this, entity, SWT.NULL);
|
135
|
createPublicationControls(this, referenceType, entity, SWT.NULL);
|
136
|
} else {
|
137
|
if (referenceType.isPrintedUnit()) {
|
138
|
createPrintedUnitControls(this, referenceType, entity,
|
139
|
SWT.NULL);
|
140
|
}
|
141
|
if (referenceType.isPublication()) {
|
142
|
createPublicationControls(this, referenceType, entity,
|
143
|
SWT.NULL);
|
144
|
}
|
145
|
if (referenceType.isVolumeReference()) {
|
146
|
createVolumeControls(this, entity, SWT.NULL);
|
147
|
}
|
148
|
if (referenceType.isSection()) {
|
149
|
createSectionControls(this, entity, SWT.NULL);
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
|
154
|
// date published
|
155
|
element_timePeriod = formFactory.createTimePeriodElement(formElement,
|
156
|
"Date Published", entity.getDatePublished(), style);
|
157
|
|
158
|
createUriAndAbstract(this, entity, SWT.NULL);
|
159
|
}
|
160
|
|
161
|
/*
|
162
|
* (non-Javadoc)
|
163
|
*
|
164
|
* @see
|
165
|
* eu.etaxonomy.taxeditor.forms.section.cdmdetail.AbstractCdmDetailComposite
|
166
|
* #updateContent()
|
167
|
*/
|
168
|
/** {@inheritDoc} */
|
169
|
@Override
|
170
|
protected void updateContent() {
|
171
|
if (getEntity() == null) {
|
172
|
setEntity(ReferenceFactory.newGeneric());
|
173
|
}
|
174
|
|
175
|
super.updateContent();
|
176
|
|
177
|
// enable elements according to state of cache protection
|
178
|
// setEnabled(getEntity().isProtectedTitleCache(), Arrays.asList(new
|
179
|
// Object[]{text_cache}));
|
180
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
|
181
|
setIrrelevant(toggleable_cache.getState(),
|
182
|
Arrays.asList(new Object[] { toggleable_cache }));
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Creates an in reference for reference types that do hav this.
|
187
|
*
|
188
|
* @param element
|
189
|
* @param referenceType
|
190
|
* @param reference
|
191
|
* @param style
|
192
|
*/
|
193
|
private void createInReferenceByType(ICdmFormElement element,
|
194
|
ReferenceType referenceType, Reference reference, int style) {
|
195
|
boolean createInReferenceWidget = true;
|
196
|
String label = "In Reference";
|
197
|
|
198
|
switch (referenceType) {
|
199
|
case Generic:
|
200
|
break;
|
201
|
case BookSection:
|
202
|
label = "Book";
|
203
|
break;
|
204
|
case InProceedings:
|
205
|
label = "Print Series";
|
206
|
break;
|
207
|
case Article:
|
208
|
label = "Journal";
|
209
|
break;
|
210
|
case WebPage:
|
211
|
break;
|
212
|
default:
|
213
|
createInReferenceWidget = false;
|
214
|
}
|
215
|
|
216
|
if (createInReferenceWidget) {
|
217
|
selection_inReference = (ReferenceSelectionElement) formFactory
|
218
|
.createSelectionElement(SelectionType.REFERENCE,
|
219
|
getConversationHolder(), element, label,
|
220
|
reference.getInReference(),
|
221
|
ReferenceSelectionElement.DEFAULT, style);
|
222
|
}
|
223
|
}
|
224
|
|
225
|
/**
|
226
|
* Creates additional controls to edit a generic reference
|
227
|
*
|
228
|
* @param element
|
229
|
* @param reference
|
230
|
* @param listener
|
231
|
* @param style
|
232
|
*/
|
233
|
private void createGenericControls(ICdmFormElement element,
|
234
|
Reference reference, int style) {
|
235
|
|
236
|
// editor
|
237
|
text_editor = formFactory.createTextWithLabelElement(element, "Editor",
|
238
|
reference.getEditor(), style);
|
239
|
|
240
|
// series
|
241
|
text_series = formFactory.createTextWithLabelElement(element, "Series",
|
242
|
reference.getSeries(), style);
|
243
|
|
244
|
// volume
|
245
|
text_volume = formFactory.createTextWithLabelElement(element, "Volume",
|
246
|
reference.getVolume(), style);
|
247
|
|
248
|
// pages
|
249
|
text_pages = formFactory.createTextWithLabelElement(element, "Pages",
|
250
|
reference.getPages(), style);
|
251
|
}
|
252
|
|
253
|
/**
|
254
|
* Creates additional controls to edit a publication
|
255
|
*
|
256
|
* @param element
|
257
|
* @param reference
|
258
|
* @param listener
|
259
|
* @param style
|
260
|
*/
|
261
|
private void createPublicationControls(ICdmFormElement element,
|
262
|
ReferenceType referenceType, Reference reference, int style) {
|
263
|
|
264
|
// placePublished
|
265
|
text_placePublished = formFactory.createTextWithLabelElement(element,
|
266
|
"Place Published", reference.getPlacePublished(), style);
|
267
|
|
268
|
// publisher
|
269
|
text_publisher = formFactory.createTextWithLabelElement(element,
|
270
|
"Publisher", reference.getPublisher(), style);
|
271
|
|
272
|
if (referenceType.equals(ReferenceType.Journal)) {
|
273
|
// issn
|
274
|
text_issn = formFactory.createTextWithLabelElement(element, "ISSN",
|
275
|
reference.getIssn(), style);
|
276
|
}
|
277
|
|
278
|
if (referenceType.equals(ReferenceType.Report)) {
|
279
|
// institution
|
280
|
selection_institution = (InstitutionSelectionElement) formFactory
|
281
|
.createSelectionElement(SelectionType.INSTITUTION,
|
282
|
getConversationHolder(), element, "Institution",
|
283
|
reference.getInstitution(),
|
284
|
InstitutionSelectionElement.DEFAULT, style);
|
285
|
}
|
286
|
|
287
|
if (referenceType.equals(ReferenceType.Thesis)) {
|
288
|
// school
|
289
|
selection_institution = (InstitutionSelectionElement) formFactory
|
290
|
.createSelectionElement(SelectionType.INSTITUTION,
|
291
|
getConversationHolder(), element, "School",
|
292
|
reference.getSchool(),
|
293
|
InstitutionSelectionElement.DEFAULT, style);
|
294
|
}
|
295
|
|
296
|
if (referenceType.equals(ReferenceType.Proceedings)) {
|
297
|
// organization
|
298
|
text_organisation = formFactory.createTextWithLabelElement(element,
|
299
|
"Organisation", reference.getOrganization(), style);
|
300
|
}
|
301
|
}
|
302
|
|
303
|
/**
|
304
|
* Creates additional controls to edit a section
|
305
|
*
|
306
|
* @param element
|
307
|
* @param reference
|
308
|
* @param style
|
309
|
*/
|
310
|
private void createSectionControls(ICdmFormElement element,
|
311
|
Reference reference, int style) {
|
312
|
// pages
|
313
|
text_pages = formFactory.createTextWithLabelElement(element, "Pages",
|
314
|
reference.getPages(), style);
|
315
|
}
|
316
|
|
317
|
/**
|
318
|
* Creates additional controls to edit a volume
|
319
|
*
|
320
|
* @param element
|
321
|
* @param reference
|
322
|
* @param style
|
323
|
*/
|
324
|
private void createVolumeControls(ICdmFormElement element,
|
325
|
Reference reference, int style) {
|
326
|
|
327
|
text_volume = formFactory.createTextWithLabelElement(element, "Volume",
|
328
|
reference.getVolume(), style);
|
329
|
|
330
|
text_series = formFactory.createTextWithLabelElement(element, "Series",
|
331
|
reference.getSeries(), style);
|
332
|
}
|
333
|
|
334
|
/**
|
335
|
*
|
336
|
* @param element
|
337
|
* @param referenceType
|
338
|
* @param reference
|
339
|
* @param style
|
340
|
*/
|
341
|
private void createPrintedUnitControls(ICdmFormElement element,
|
342
|
ReferenceType referenceType, Reference reference, int style) {
|
343
|
// in series
|
344
|
selection_inSeries = (ReferenceSelectionElement) formFactory
|
345
|
.createSelectionElement(SelectionType.REFERENCE,
|
346
|
getConversationHolder(), element, "In Series",
|
347
|
reference.getInSeries(),
|
348
|
ReferenceSelectionElement.DEFAULT, style);
|
349
|
|
350
|
// editor
|
351
|
text_editor = formFactory.createTextWithLabelElement(element, "Editor",
|
352
|
reference.getEditor(), style);
|
353
|
|
354
|
// series part
|
355
|
text_seriesPart = formFactory.createTextWithLabelElement(element,
|
356
|
"Series Part", reference.getSeriesPart(), style);
|
357
|
|
358
|
if (referenceType.equals(ReferenceType.Book)) {
|
359
|
// edition
|
360
|
text_edition = formFactory.createTextWithLabelElement(element,
|
361
|
"Edition", reference.getEdition(), style);
|
362
|
|
363
|
// isbn
|
364
|
text_isbn = formFactory.createTextWithLabelElement(element, "ISBN",
|
365
|
reference.getIsbn(), style);
|
366
|
}
|
367
|
}
|
368
|
|
369
|
private void createUriAndAbstract(ICdmFormElement element,
|
370
|
Reference reference, int style) {
|
371
|
// uri
|
372
|
text_uri = formFactory.createUriWithLabelElement(element, "URI",
|
373
|
reference.getUri(), style);
|
374
|
// abstract
|
375
|
text_referenceAbstract = formFactory.createMultilineTextWithLabel(
|
376
|
element, "Reference Abstract", 100, style);
|
377
|
text_referenceAbstract.setText(reference.getReferenceAbstract());
|
378
|
}
|
379
|
|
380
|
/** {@inheritDoc} */
|
381
|
@Override
|
382
|
public void handleEvent(Object eventSource) {
|
383
|
if (eventSource == combo_referenceType) {
|
384
|
getEntity().setType(combo_referenceType.getSelection());
|
385
|
updateContent();
|
386
|
} else if (eventSource == element_timePeriod) {
|
387
|
getEntity().setDatePublished(element_timePeriod.getTimePeriod());
|
388
|
clearException();
|
389
|
}
|
390
|
// selections
|
391
|
else if (eventSource == selection_authorTeam) {
|
392
|
getEntity().setAuthorTeam(
|
393
|
(TeamOrPersonBase) selection_authorTeam.getSelection());
|
394
|
} else if (eventSource == selection_inReference) {
|
395
|
getEntity().setInReference(selection_inReference.getSelection());
|
396
|
} else if (eventSource == selection_inSeries) {
|
397
|
getEntity().setInReference(selection_inSeries.getSelection());
|
398
|
} else if (eventSource == selection_institution) {
|
399
|
getEntity().setInstitution(selection_institution.getSelection());
|
400
|
}
|
401
|
|
402
|
// textfields
|
403
|
else if (eventSource == toggleable_cache) {
|
404
|
handleToggleableCacheField();
|
405
|
} else if (eventSource == text_edition) {
|
406
|
getEntity().setEdition(text_edition.getText());
|
407
|
} else if (eventSource == text_editor) {
|
408
|
getEntity().setEditor(text_editor.getText());
|
409
|
} else if (eventSource == text_isbn) {
|
410
|
getEntity().setIsbn(text_isbn.getText());
|
411
|
} else if (eventSource == text_issn) {
|
412
|
getEntity().setIssn(text_issn.getText());
|
413
|
} else if (eventSource == text_organisation) {
|
414
|
getEntity().setOrganization(text_organisation.getText());
|
415
|
} else if (eventSource == text_pages) {
|
416
|
getEntity().setPages(text_pages.getText());
|
417
|
} else if (eventSource == text_placePublished) {
|
418
|
getEntity().setPlacePublished(text_placePublished.getText());
|
419
|
} else if (eventSource == text_publisher) {
|
420
|
getEntity().setPublisher(text_publisher.getText());
|
421
|
} else if (eventSource == text_referenceAbstract) {
|
422
|
getEntity().setReferenceAbstract(text_referenceAbstract.getText());
|
423
|
} else if (eventSource == text_series) {
|
424
|
getEntity().setSeries(text_series.getText());
|
425
|
} else if (eventSource == text_seriesPart) {
|
426
|
getEntity().setSeriesPart(text_seriesPart.getText());
|
427
|
} else if (eventSource == text_title) {
|
428
|
getEntity().setTitle(text_title.getText());
|
429
|
} else if (eventSource == text_uri) {
|
430
|
try {
|
431
|
getEntity().setUri(text_uri.getUri());
|
432
|
} catch (URISyntaxException e) {
|
433
|
StoreUtil.warningDialog("Invlid URI", getClass(),
|
434
|
e.getLocalizedMessage());
|
435
|
}
|
436
|
} else if (eventSource == text_volume) {
|
437
|
getEntity().setVolume(text_volume.getText());
|
438
|
}
|
439
|
|
440
|
else if (eventSource != toggleable_cache) {
|
441
|
toggleable_cache.setText(getEntity().getTitleCache());
|
442
|
}
|
443
|
|
444
|
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
|
445
|
}
|
446
|
|
447
|
/*
|
448
|
* (non-Javadoc)
|
449
|
*
|
450
|
* @see
|
451
|
* eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleException
|
452
|
* (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
|
453
|
*/
|
454
|
/** {@inheritDoc} */
|
455
|
@Override
|
456
|
public void handleException(CdmPropertyChangeEvent event) {
|
457
|
exceptionOccurred(event);
|
458
|
}
|
459
|
|
460
|
/*
|
461
|
* (non-Javadoc)
|
462
|
*
|
463
|
* @see eu.etaxonomy.taxeditor.forms.IExceptionHandler#clearException()
|
464
|
*/
|
465
|
/** {@inheritDoc} */
|
466
|
@Override
|
467
|
public void clearException() {
|
468
|
exceptionOccurred(null);
|
469
|
}
|
470
|
|
471
|
private final List<IExceptionHandler> exceptionHandlers = new ArrayList<IExceptionHandler>();
|
472
|
|
473
|
/*
|
474
|
* (non-Javadoc)
|
475
|
*
|
476
|
* @see
|
477
|
* eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#addExceptionHandler
|
478
|
* (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
|
479
|
*/
|
480
|
/** {@inheritDoc} */
|
481
|
@Override
|
482
|
public void addExceptionHandler(IExceptionHandler handler) {
|
483
|
exceptionHandlers.add(handler);
|
484
|
}
|
485
|
|
486
|
/*
|
487
|
* (non-Javadoc)
|
488
|
*
|
489
|
* @see
|
490
|
* eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#removeExceptionHandler
|
491
|
* (eu.etaxonomy.taxeditor.forms.IExceptionHandler)
|
492
|
*/
|
493
|
/** {@inheritDoc} */
|
494
|
@Override
|
495
|
public void removeExceptionHandler(IExceptionHandler handler) {
|
496
|
exceptionHandlers.remove(handler);
|
497
|
}
|
498
|
|
499
|
/*
|
500
|
* (non-Javadoc)
|
501
|
*
|
502
|
* @see
|
503
|
* eu.etaxonomy.taxeditor.forms.IErrorIntolerableElement#exceptionOccurred
|
504
|
* (eu.etaxonomy.taxeditor.forms.CdmPropertyChangeEvent)
|
505
|
*/
|
506
|
/** {@inheritDoc} */
|
507
|
@Override
|
508
|
public void exceptionOccurred(CdmPropertyChangeEvent event) {
|
509
|
for (IExceptionHandler handler : exceptionHandlers) {
|
510
|
if (event == null) {
|
511
|
handler.clearException();
|
512
|
} else {
|
513
|
handler.handleException(event);
|
514
|
}
|
515
|
}
|
516
|
}
|
517
|
}
|