3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.Collections
;
15 import java
.util
.Comparator
;
16 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.ui
.IEditorInput
;
21 import org
.eclipse
.ui
.IPersistableElement
;
23 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
24 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
26 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
27 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
32 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
33 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
34 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
35 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
38 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
39 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
40 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
41 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
42 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
45 * <p>Abstract AbstractBulkEditorInput class.</p>
52 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> implements IEditorInput
, IEntityPersistenceService
<T
> {
57 private static final long serialVersionUID
= 416414530232743735L;
59 private UUID entityUuid
;
61 private List
<T
> model
;
63 private IEntityCreator
<T
> entityCreator
;
65 private static Class serviceClass
;
70 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
71 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
73 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
75 return BulkEditorInputType
.getInput(inputType
);
81 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
82 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
84 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
87 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
89 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
91 editorInput
.setEntityUuid(entity
.getUuid());
99 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
100 * @return a {@link java.util.List} object.
102 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
107 * @param entityUuid a {@link java.util.UUID} object.
108 * @return a T object.
110 protected T
loadEntity(UUID entityUuid
) {
111 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
112 return (T
) CdmStore
.getService(serviceClass
).load(entityUuid
, propertyPaths
);
115 private void setEntityUuid(UUID entityUuid
){
116 this.entityUuid
= entityUuid
;
120 * <p>Getter for the field <code>entityUuid</code>.</p>
122 * @return a {@link java.util.UUID} object.
124 public UUID
getEntityUuid() {
130 * @see org.eclipse.ui.IEditorInput#exists()
138 public boolean exists() {
139 // TODO Auto-generated method stub
144 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
147 * <p>getImageDescriptor</p>
149 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
152 public ImageDescriptor
getImageDescriptor() {
153 // TODO Auto-generated method stub
158 * @see org.eclipse.ui.IEditorInput#getPersistable()
161 * <p>getPersistable</p>
163 * @return a {@link org.eclipse.ui.IPersistableElement} object.
166 public IPersistableElement
getPersistable() {
171 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
175 @SuppressWarnings("unchecked")
176 public Object
getAdapter(Class adapter
) {
181 * <p>Setter for the field <code>query</code>.</p>
183 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
185 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
187 List
<T
> entityList
= new ArrayList
<T
>();
189 if(getEntityUuid() != null){
191 T entity
= (T
) loadEntity(getEntityUuid());
192 entityList
.add(entity
);
195 else if(bulkEditorQuery
!= null){
197 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
198 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
200 entityList
= listEntities(configurator
);
202 Collections
.sort(entityList
, queryComparator
);
211 * <p>isMergingEnabled</p>
215 public boolean isMergingEnabled() {
220 * <p>isMarkerTypeEditingEnabled</p>
222 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
225 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
231 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
235 public boolean merge(T entity
, T mergeTarget
) {
236 if (entity
instanceof IMergable
) {
238 CdmStore
.getService(ICommonService
.class).merge((IMergable
)mergeTarget
, (IMergable
)entity
, null);
239 } catch (MergeException e
) {
240 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
242 "Could not merge chosen objects of type " + entity
.getClass().getName(),
243 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
253 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
257 public boolean create(T entity
) {
261 public IEntityCreator
<T
> getEntityCreator(){
262 if(entityCreator
== null){
263 entityCreator
= createEntityCreator();
265 return entityCreator
;
271 protected abstract IEntityCreator
<T
> createEntityCreator();
274 * The default implementation returns an empty list of sort providers.
277 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
278 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
280 sortProviders
.add(new CdmBaseSortProvider
<T
>());
282 return sortProviders
;
286 * Returns a textual representation given object. The default implementation
287 * in the abstract base class returns the simple name of the class, this may
288 * be overwritten to something more specific in subclasses.
291 * @return a textual representation given object.
293 public String
getTypeText(Object entity
){
294 return entity
.getClass().getSimpleName();
301 public String
getText(T entity
) {
302 if(entity
instanceof IdentifiableEntity
){
303 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
305 return identifiableEntity
.getTitleCache();
308 return "No text. Implement in subclass";
314 public List
<?
> getModel() {