reintegrated model changes from branch 3.3-MC-SNAPSHOT
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / entitycreator / OccurrenceCreator.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.bulkeditor.input.entitycreator;
12
13 import java.util.Comparator;
14 import java.util.HashMap;
15 import java.util.Map;
16 import java.util.TreeMap;
17
18 import org.apache.log4j.Logger;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.jface.wizard.WizardDialog;
21
22 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
23 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
24 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
25 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
26 import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
27 import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
28
29 /**
30 * <p>
31 * OccurrenceCreator class.
32 * </p>
33 *
34 * @author n.hoffmann
35 * @created Jun 16, 2010
36 * @version 1.0
37 */
38 public class OccurrenceCreator implements
39 IEntityCreator<SpecimenOrObservationBase> {
40 private static final Logger logger = Logger
41 .getLogger(OccurrenceCreator.class);
42
43 /** {@inheritDoc} */
44 @Override
45 public SpecimenOrObservationBase createEntity(String text) {
46
47 return createEntity(DerivedUnit.class, text);
48 }
49
50 /** {@inheritDoc} */
51 @Override
52 public SpecimenOrObservationBase createEntity(Object key, String text) {
53
54 SpecimenOrObservationBase specimenOrObservation = null;
55 NewDerivedUnitBaseWizard wizard = new NewDerivedUnitBaseWizard((SpecimenOrObservationType)key);
56 wizard.init(null, null);
57 if(wizard.getEntity() != null) {
58 WizardDialog dialog = new WizardDialog(BulkEditorUtil.getShell(), wizard);
59 int status = dialog.open();
60
61 if (status == IStatus.OK) {
62 specimenOrObservation = wizard.getEntity();
63 }
64 }
65 return specimenOrObservation;
66 }
67
68 /**
69 * <p>
70 * getKeyLabelPairs
71 * </p>
72 *
73 * @return a {@link java.util.Map} object.
74 */
75 @Override
76 public Map<Object, String> getKeyLabelPairs() {
77 Comparator<Object> comparator = new Comparator<Object>() {
78 public int compare(Object o1, Object o2) {
79 String key1 = ((SpecimenOrObservationType)o1).getKey();
80 String key2 = ((SpecimenOrObservationType)o2).getKey();
81 return key1.compareTo(key2);
82 }
83 };
84 Map<Object, String> result = new TreeMap<Object, String>(comparator);
85
86 for(SpecimenOrObservationType sooType : SpecimenOrObservationType.values()) {
87 result.put(sooType, sooType.getMessage());
88 }
89
90 return result;
91 }
92
93 @Override
94 public boolean savesEntity() {
95 // TODO Auto-generated method stub
96 return true;
97 }
98
99
100 }