Merge branch 'release/5.7.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / DerivedUnitSelectionDialog.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.UUID;
13
14 import org.eclipse.swt.widgets.Shell;
15
16 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
17 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
19 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22 import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * <p>FilteredDerivedUnitSelectionDialog class.</p>
27 *
28 * @author n.hoffmann
29 * @created Jun 17, 2010
30 * @version 1.0
31 */
32 public class DerivedUnitSelectionDialog extends
33 AbstractFilteredCdmResourceSelectionDialog<DerivedUnit> {
34
35 /**
36 * <p>select</p>
37 *
38 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
39 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
40 * @param unit a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
41 * @return a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
42 */
43 public static DerivedUnit select(Shell shell, //ConversationHolder conversation,
44 DerivedUnit unit){
45 DerivedUnitSelectionDialog dialog = new DerivedUnitSelectionDialog(shell, //conversation,
46 "Choose Unit", false, DerivedUnitSelectionDialog.class.getCanonicalName(), unit);
47 return getSelectionFromDialog(dialog);
48 }
49
50 /**
51 * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
52 *
53 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
54 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
55 * @param title a {@link java.lang.String} object.
56 * @param multi a boolean.
57 * @param settings a {@link java.lang.String} object.
58 * @param cdmObject a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
59 */
60 protected DerivedUnitSelectionDialog(Shell shell, //ConversationHolder conversation,
61 String title,
62 boolean multi, String settings, DerivedUnit cdmObject) {
63 super(shell, //conversation,
64 title, multi, settings, cdmObject);
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 protected DerivedUnit getPersistentObject(UUID uuid) {
70 Object object = CdmStore.getService(IOccurrenceService.class).load(uuid);
71
72 SpecimenOrObservationBase specimenObservationBase = (SpecimenOrObservationBase) HibernateProxyHelper.deproxy(object);
73
74 if(specimenObservationBase instanceof DerivedUnit){
75 return (DerivedUnit) specimenObservationBase;
76 }
77 MessagingUtils.error(this.getClass(), "Selected unit is not a derived unit", null);
78 return null;
79 }
80
81 /** {@inheritDoc} */
82 @Override
83 protected void callService(String pattern) {
84 model = CdmStore.getService(IOccurrenceService.class).getDerivedUnitUuidAndTitleCache(limitOfInitialElements,pattern);
85 }
86
87 /** {@inheritDoc} */
88 @Override
89 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
90 return new NewDerivedUnitBaseWizard();
91 }
92
93 /** {@inheritDoc} */
94 @Override
95 protected String[] getNewWizardText() {
96 return new String[]{ "New Unit"};
97 }
98 }