Project

General

Profile

Download (3.34 KB) Statistics
| Branch: | Tag: | Revision:
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.conversation.ConversationHolder;
17
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
18
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
19
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23
import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * <p>FilteredDerivedUnitSelectionDialog class.</p>
28
 *
29
 * @author n.hoffmann
30
 * @created Jun 17, 2010
31
 * @version 1.0
32
 */
33
public class DerivedUnitSelectionDialog extends
34
		AbstractFilteredCdmResourceSelectionDialog<DerivedUnit> {
35

    
36
	/**
37
	 * <p>select</p>
38
	 *
39
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
40
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
41
	 * @param unit a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
42
	 * @return a {@link eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase} object.
43
	 */
44
	public static DerivedUnit select(Shell shell, ConversationHolder conversation, 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, String title,
61
			boolean multi, String settings, DerivedUnit cdmObject) {
62
		super(shell, conversation, title, multi, settings, cdmObject);
63
	}
64

    
65
	/** {@inheritDoc} */
66
	@Override
67
	protected DerivedUnit getPersistentObject(UUID uuid) {
68
		Object object = CdmStore.getService(IOccurrenceService.class).load(uuid);
69

    
70
		SpecimenOrObservationBase specimenObservationBase = (SpecimenOrObservationBase) HibernateProxyHelper.deproxy(object);
71

    
72
		if(specimenObservationBase instanceof DerivedUnit){
73
			return (DerivedUnit) specimenObservationBase;
74
		}
75
		MessagingUtils.error(this.getClass(), "Selected unit is not a derived unit", null);
76
		return null;
77
	}
78

    
79
	/** {@inheritDoc} */
80
	@Override
81
	protected void search() {
82
		model = CdmStore.getService(IOccurrenceService.class).getDerivedUnitUuidAndTitleCache();
83
	}
84

    
85
	/** {@inheritDoc} */
86
	@Override
87
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
88
		return new NewDerivedUnitBaseWizard();
89
	}
90

    
91
	/** {@inheritDoc} */
92
	@Override
93
	protected String[] getNewWizardText() {
94
		return new String[]{ "Unit "};
95
	}
96
}
(9-9/39)