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.dialog.selection;
|
12
|
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
19
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
22
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
23
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
24
|
import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* <p>FilteredDerivedUnitSelectionDialog class.</p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created Jun 17, 2010
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public class DerivedUnitSelectionDialog extends
|
35
|
AbstractFilteredCdmResourceSelectionDialog<DerivedUnit> {
|
36
|
|
37
|
/**
|
38
|
* <p>select</p>
|
39
|
*
|
40
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
41
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
42
|
* @param unit a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
|
43
|
* @return a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
|
44
|
*/
|
45
|
public static DerivedUnit select(Shell shell, ConversationHolder conversation, DerivedUnit unit){
|
46
|
DerivedUnitSelectionDialog dialog = new DerivedUnitSelectionDialog(shell, conversation,
|
47
|
"Choose Unit", false, DerivedUnitSelectionDialog.class.getCanonicalName(), unit);
|
48
|
return getSelectionFromDialog(dialog);
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
|
53
|
*
|
54
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
55
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
56
|
* @param title a {@link java.lang.String} object.
|
57
|
* @param multi a boolean.
|
58
|
* @param settings a {@link java.lang.String} object.
|
59
|
* @param cdmObject a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
|
60
|
*/
|
61
|
protected DerivedUnitSelectionDialog(Shell shell, ConversationHolder conversation, String title,
|
62
|
boolean multi, String settings, DerivedUnit cdmObject) {
|
63
|
super(shell, conversation, title, multi, settings, cdmObject);
|
64
|
}
|
65
|
|
66
|
/** {@inheritDoc} */
|
67
|
@Override
|
68
|
protected DerivedUnit getPersistentObject(UUID uuid) {
|
69
|
Object object = CdmStore.getService(IOccurrenceService.class).load(uuid);
|
70
|
|
71
|
SpecimenOrObservationBase specimenObservationBase = (SpecimenOrObservationBase) HibernateProxyHelper.deproxy(object);
|
72
|
|
73
|
if(specimenObservationBase instanceof DerivedUnit){
|
74
|
return (DerivedUnit) specimenObservationBase;
|
75
|
}
|
76
|
MessagingUtils.error(this.getClass(), "Selected unit is not a derived unit", null);
|
77
|
return null;
|
78
|
}
|
79
|
|
80
|
/** {@inheritDoc} */
|
81
|
@Override
|
82
|
protected void initModel() {
|
83
|
model = CdmStore.getService(IOccurrenceService.class).getDerivedUnitUuidAndTitleCache();
|
84
|
}
|
85
|
|
86
|
/** {@inheritDoc} */
|
87
|
@Override
|
88
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
89
|
return new NewDerivedUnitBaseWizard();
|
90
|
}
|
91
|
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
protected String getNewWizardLinkText() {
|
95
|
return String.format("Create a new <a>%1s</a>", "Unit ");
|
96
|
}
|
97
|
}
|