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
;
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
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
25 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
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
.strategy
.merge
.IMergable
;
31 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
32 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
33 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
38 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
39 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
40 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
41 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
49 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> extends CdmEntitySessionInput
implements IEditorInput
,
50 IEntityPersistenceService
<T
> {
52 private UUID entityUuid
;
54 private List
<T
> model
;
56 private IEntityCreator
<T
> entityCreator
;
57 private final ConversationHolder conversation
;
59 public AbstractBulkEditorInput() {
61 this.conversation
= CdmStore
.createConversation();
64 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
66 return BulkEditorInputType
.getInput(inputType
);
69 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
71 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
73 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
75 editorInput
.setEntityUuid(entity
.getUuid());
80 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
82 protected abstract T
loadEntity(UUID entityUuid
);
84 private void setEntityUuid(UUID entityUuid
){
85 this.entityUuid
= entityUuid
;
88 public UUID
getEntityUuid() {
93 public boolean exists() {
94 // TODO Auto-generated method stub
99 public ImageDescriptor
getImageDescriptor() {
100 // TODO Auto-generated method stub
105 public IPersistableElement
getPersistable() {
111 @SuppressWarnings("unchecked")
112 public Object
getAdapter(Class adapter
) {
116 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
118 List
<T
> entityList
= new ArrayList
<T
>();
120 if(getEntityUuid() != null){
122 T entity
= loadEntity(getEntityUuid());
123 entityList
.add(entity
);
126 else if(bulkEditorQuery
!= null){
128 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
129 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
131 entityList
= listEntities(configurator
);
133 Collections
.sort(entityList
, queryComparator
);
141 public boolean isMergingEnabled() {
145 public boolean isConvertingEnabled() {
149 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
156 public boolean merge(T entity
, T mergeTarget
) {
157 if (entity
instanceof IMergable
) {
159 CdmStore
.getCommonService().merge(mergeTarget
.getUuid(), entity
.getUuid(), (Class
<?
extends CdmBase
>)entity
.getClass());
160 } catch (MergeException e
) {
161 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
163 "Could not merge chosen objects of type " + entity
.getClass().getName(),
164 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
175 public T
create(T entity
) {
179 public IEntityCreator
<T
> getEntityCreator(){
180 if(entityCreator
== null){
181 entityCreator
= createEntityCreator();
183 return entityCreator
;
186 protected abstract IEntityCreator
<T
> createEntityCreator();
189 * The default implementation returns an empty list of sort providers.
192 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
193 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
195 sortProviders
.add(new CdmBaseSortProvider
<T
>());
197 return sortProviders
;
201 * Returns a textual representation given object. The default implementation
202 * in the abstract base class returns the simple name of the class, this may
203 * be overwritten to something more specific in subclasses.
206 * @return a textual representation given object.
208 public String
getTypeText(Object entity
){
209 return entity
.getClass().getSimpleName();
212 public String
getText(T entity
) {
213 if(entity
instanceof IdentifiableEntity
){
214 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
216 return identifiableEntity
.getTitleCache();
219 return "No text. Implement in subclass";
222 public List
<T
> getModel() {
226 protected boolean replaceInModel(T entity
) {
227 int index
= model
.indexOf(entity
);
229 model
.set(index
, entity
);
237 public List
<T
> getRootEntities() {
243 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
244 // TODO Auto-generated method stub
248 public ConversationHolder
getConversation() {