AT: commiting latest changes to the Palm Use data extension
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialogs / filteredSelection / DerivedUnitSelectionDialog.java
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.dialogs.filteredSelection;
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.DerivedUnitBase;
21 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23 import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25 import eu.etaxonomy.taxeditor.store.StoreUtil;
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<DerivedUnitBase> {
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 DerivedUnitBase select(Shell shell, ConversationHolder conversation, DerivedUnitBase 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, DerivedUnitBase cdmObject) {
63 super(shell, conversation, title, multi, settings, cdmObject);
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 protected DerivedUnitBase 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 DerivedUnitBase){
74 return (DerivedUnitBase) specimenObservationBase;
75 }
76 StoreUtil.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).getDerivedUnitBaseUuidAndTitleCache();
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 "Click link to create a new <A>Unit</A>.";
96 }
97 }