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
.Collections
;
14 import java
.util
.Comparator
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
19 import org
.eclipse
.ui
.IEditorInput
;
20 import org
.eclipse
.ui
.IPersistableElement
;
22 import eu
.etaxonomy
.cdm
.api
.service
.ICommonService
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
24 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
25 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
27 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
29 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
30 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
31 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
32 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
38 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 * <p>Abstract AbstractBulkEditorInput class.</p>
49 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> implements IEditorInput
, IEntityPersistenceService
<T
> {
54 private static final long serialVersionUID
= 416414530232743735L;
56 private UUID entityUuid
;
58 private List
<T
> model
;
60 private IEntityCreator
<T
> entityCreator
;
65 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
66 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
68 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
69 return BulkEditorInputType
.getInput(inputType
);
75 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
76 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
78 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
81 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
83 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
85 editorInput
.setEntityUuid(entity
.getUuid());
93 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
94 * @return a {@link java.util.List} object.
96 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
101 * @param entityUuid a {@link java.util.UUID} object.
102 * @return a T object.
104 protected abstract T
loadEntity(UUID entityUuid
);
106 private void setEntityUuid(UUID entityUuid
){
107 this.entityUuid
= entityUuid
;
111 * <p>Getter for the field <code>entityUuid</code>.</p>
113 * @return a {@link java.util.UUID} object.
115 public UUID
getEntityUuid() {
121 * @see org.eclipse.ui.IEditorInput#exists()
129 public boolean exists() {
130 // TODO Auto-generated method stub
135 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
138 * <p>getImageDescriptor</p>
140 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
143 public ImageDescriptor
getImageDescriptor() {
144 // TODO Auto-generated method stub
149 * @see org.eclipse.ui.IEditorInput#getPersistable()
152 * <p>getPersistable</p>
154 * @return a {@link org.eclipse.ui.IPersistableElement} object.
157 public IPersistableElement
getPersistable() {
162 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
166 @SuppressWarnings("unchecked")
167 public Object
getAdapter(Class adapter
) {
172 * <p>Setter for the field <code>query</code>.</p>
174 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
176 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
178 List
<T
> entityList
= new ArrayList
<T
>();
180 if(getEntityUuid() != null){
182 T entity
= loadEntity(getEntityUuid());
183 entityList
.add(entity
);
186 else if(bulkEditorQuery
!= null){
188 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
189 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
191 entityList
= listEntities(configurator
);
193 Collections
.sort(entityList
, queryComparator
);
201 * <p>isMergingEnabled</p>
205 public boolean isMergingEnabled() {
210 * <p>isMarkerTypeEditingEnabled</p>
212 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
215 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
221 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
225 public boolean merge(T entity
, T mergeTarget
) {
226 if (entity
instanceof IMergable
) {
228 CdmStore
.getService(ICommonService
.class).merge((IMergable
)mergeTarget
, (IMergable
)entity
, null);
229 } catch (MergeException e
) {
230 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
232 "Could not merge chosen objects of type " + entity
.getClass().getName(),
233 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
243 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
247 public boolean create(T entity
) {
251 public IEntityCreator
<T
> getEntityCreator(){
252 if(entityCreator
== null){
253 entityCreator
= createEntityCreator();
255 return entityCreator
;
261 protected abstract IEntityCreator
<T
> createEntityCreator();
264 * The default implementation returns an empty list of sort providers.
267 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
268 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
270 sortProviders
.add(new CdmBaseSortProvider
<T
>());
272 return sortProviders
;
276 * Returns a textual representation given object. The default implementation
277 * in the abstract base class returns the simple name of the class, this may
278 * be overwritten to something more specific in subclasses.
281 * @return a textual representation given object.
283 public String
getTypeText(Object entity
){
284 return entity
.getClass().getSimpleName();
291 public String
getText(T entity
) {
292 if(entity
instanceof IdentifiableEntity
){
293 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
295 return identifiableEntity
.getTitleCache();
298 return "No text. Implement in subclass";
304 public List
<?
> getModel() {