Project

General

Profile

Download (3.63 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.service.IOccurrenceService;
17
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
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.NewFieldUnitWizard;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

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

    
50
	/**
51
	 * <p>Constructor for FilteredFieldUnitSelectionDialog.</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.FieldUnit} object.
59
	 */
60
	protected FieldUnitSelectionDialog(Shell shell, //ConversationHolder conversation,
61
			String title, boolean multi, String settings,
62
			FieldUnit cdmObject) {
63
		super(shell, //conversation,
64
		        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
		MessagingUtils.error(this.getClass(), "Selected object is not a field unit", null);
81
		return null;
82
	}
83

    
84
	/* (non-Javadoc)
85
	 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#search
86
	 */
87
	/** {@inheritDoc} */
88
	@Override
89
	protected void callService(String pattern) {
90
	    model = CdmStore.getService(IOccurrenceService.class).getUuidAndTitleCache(FieldUnit.class, limitOfInitialElements, pattern);
91

    
92
	}
93

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

    
100
	/** {@inheritDoc} */
101
	@Override
102
	protected String[] getNewWizardText() {
103
		return new String[]{"New Field Unit"};
104
	}
105
}
(16-16/44)