Project

General

Profile

Download (3.7 KB) Statistics
| Branch: | Tag: | Revision:
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.FieldUnit;
21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23
import eu.etaxonomy.taxeditor.newWizard.NewFieldUnitWizard;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.StoreUtil;
26

    
27
/**
28
 * <p>FilteredFieldObservationSelectionDialog class.</p>
29
 *
30
 * @author n.hoffmann
31
 * @created Jun 17, 2010
32
 * @version 1.0
33
 */
34
public class FieldObservationSelectionDialog extends
35
		AbstractFilteredCdmResourceSelectionDialog<FieldUnit> {
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 observation a {@link eu.etaxonomy.cdm.model.occurrence.FieldUnit} object.
43
	 * @return a {@link eu.etaxonomy.cdm.model.occurrence.FieldUnit} object.
44
	 */
45
	public static FieldUnit select(Shell shell, ConversationHolder conversation, FieldUnit observation){
46
		FieldObservationSelectionDialog dialog = new FieldObservationSelectionDialog(shell, conversation,
47
				"Choose Derived Unit", false, FieldObservationSelectionDialog.class.getCanonicalName(), observation);
48
		return getSelectionFromDialog(dialog);
49
	}
50

    
51
	/**
52
	 * <p>Constructor for FilteredFieldObservationSelectionDialog.</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.FieldObservation} object.
60
	 */
61
	protected FieldObservationSelectionDialog(Shell shell, ConversationHolder conversation,
62
			String title, boolean multi, String settings,
63
			FieldUnit cdmObject) {
64
		super(shell, conversation, title, multi, settings, cdmObject);
65
	}
66

    
67
	/* (non-Javadoc)
68
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	protected FieldUnit getPersistentObject(UUID uuid) {
73
		Object object = CdmStore.getService(IOccurrenceService.class).load(uuid);
74

    
75
		SpecimenOrObservationBase specimenObservationBase = (SpecimenOrObservationBase) HibernateProxyHelper.deproxy(object);
76

    
77
		if(specimenObservationBase instanceof FieldUnit){
78
			return (FieldUnit) specimenObservationBase;
79
		}
80
		StoreUtil.error(this.getClass(), "Selected object is not a field observation", null);
81
		return null;
82
	}
83

    
84
	/* (non-Javadoc)
85
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#initModel()
86
	 */
87
	/** {@inheritDoc} */
88
	@Override
89
	protected void initModel() {
90
		model = CdmStore.getService(IOccurrenceService.class).getFieldUnitUuidAndTitleCache();
91
	}
92

    
93
	/** {@inheritDoc} */
94
	@Override
95
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
96
		return new NewFieldUnitWizard();
97
	}
98

    
99
	/** {@inheritDoc} */
100
	@Override
101
	protected String getNewWizardLinkText() {
102
		return String.format("Create a new <a>%1s</a>", "Field Observation ");
103
	}
104
}
(9-9/25)