Fix initialization problems for preferences and editor input
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / OccurrenceEditorInput.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;
12
13 import java.util.Arrays;
14 import java.util.List;
15 import java.util.UUID;
16
17 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
18 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
19 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
20 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
22 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
23 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
24 import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.OccurrenceCreator;
25 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.IdentifiableEntitySortProvider;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27
28 /**
29 * <p>OccurrenceEditorInput class.</p>
30 *
31 * @author n.hoffmann
32 * @created Jun 16, 2010
33 * @version 1.0
34 */
35 public class OccurrenceEditorInput extends AbstractBulkEditorInput<SpecimenOrObservationBase> {
36
37 /**
38 *
39 */
40 private static final long serialVersionUID = 1014860873939989973L;
41
42 /** Constant <code>ID="bulkeditor.input.occurrence"</code> */
43 public static final String ID = "bulkeditor.input.occurrence";
44
45 private static OccurrenceEditorInput instance;
46
47 /**
48 * <p>Getter for the field <code>instance</code>.</p>
49 *
50 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
51 */
52 public static AbstractBulkEditorInput<SpecimenOrObservationBase> getInstance() {
53 if (instance == null) {
54 instance = new OccurrenceEditorInput();
55 }
56 return instance;
57 }
58
59 /* (non-Javadoc)
60 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
61 */
62 /** {@inheritDoc} */
63 @Override
64 protected List<SpecimenOrObservationBase> listEntities(
65 IIdentifiableEntityServiceConfigurator configurator) {
66 return CdmStore.getSearchManager().findOccurrences(configurator);
67 }
68
69 /* (non-Javadoc)
70 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#loadEntity(java.util.UUID)
71 */
72 /** {@inheritDoc}
73 @Override
74 protected SpecimenOrObservationBase loadEntity(UUID entityUuid) {
75 List<String> propertyPaths = Arrays.asList(new String[]{});
76 return CdmStore.getService(IOccurrenceService.class).load(entityUuid, propertyPaths);
77 }*/
78
79 /* (non-Javadoc)
80 * @see org.eclipse.ui.IEditorInput#getName()
81 */
82 /**
83 * <p>getName</p>
84 *
85 * @return a {@link java.lang.String} object.
86 */
87 @Override
88 public String getName() {
89 return BulkEditorInputType.OCCURRENCE.label;
90 }
91
92 /* (non-Javadoc)
93 * @see org.eclipse.ui.IEditorInput#getToolTipText()
94 */
95 /**
96 * <p>getToolTipText</p>
97 *
98 * @return a {@link java.lang.String} object.
99 */
100 @Override
101 public String getToolTipText() {
102 return getName();
103 }
104
105 /* (non-Javadoc)
106 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getTypeText(java.lang.Object)
107 */
108 @Override
109 public String getTypeText(Object entity) {
110 if(HibernateProxyHelper.isInstanceOf(entity, SpecimenOrObservationBase.class)){
111 return ((SpecimenOrObservationBase) entity).getRecordBasis().getMessage();
112 }
113 return super.getTypeText(entity);
114 }
115
116 /**
117 * <p>getId</p>
118 *
119 * @return a {@link java.lang.Object} object.
120 */
121 public static Object getId(){
122 return ID;
123 }
124
125 /* (non-Javadoc)
126 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#delete(java.lang.Object)
127 */
128 /** {@inheritDoc}
129 * @throws ReferencedObjectUndeletableException */
130 @Override
131 public boolean delete(SpecimenOrObservationBase entity) throws ReferencedObjectUndeletableException {
132 return CdmStore.getService(IOccurrenceService.class).delete(entity) != null;
133 }
134
135 /* (non-Javadoc)
136 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#save(java.lang.Object)
137 */
138 /** {@inheritDoc} */
139 @Override
140 public boolean save(SpecimenOrObservationBase entity) {
141 return CdmStore.getService(IOccurrenceService.class).save(entity) != null;
142 }
143
144
145 /* (non-Javadoc)
146 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#createEntityCreator()
147 */
148 @Override
149 protected IEntityCreator<SpecimenOrObservationBase> createEntityCreator() {
150 return new OccurrenceCreator();
151 }
152
153 /* (non-Javadoc)
154 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#getSortProviders()
155 */
156 @Override
157 public List<IBulkEditorSortProvider<SpecimenOrObservationBase>> getSortProviders() {
158 List<IBulkEditorSortProvider<SpecimenOrObservationBase>> sortProviders = super.getSortProviders();
159
160 sortProviders.add(0, new IdentifiableEntitySortProvider<SpecimenOrObservationBase>());
161
162 return sortProviders;
163 }
164 }