2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.bulkeditor
.input
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collections
;
13 import java
.util
.Comparator
;
14 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
.conversation
.ConversationHolder
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
24 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
27 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
28 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
29 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
30 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
31 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.e4
.AnnotatedTableItem
;
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
.editor
.CdmEntitySessionInput
;
39 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
40 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
48 public abstract class AbstractBulkEditorInput
<T
extends CdmBase
> extends CdmEntitySessionInput
implements IEditorInput
,
49 IEntityPersistenceService
<T
> {
51 private UUID entityUuid
;
53 private List
<T
> model
= new ArrayList
<>();
55 private IEntityCreator
<T
> entityCreator
;
56 private final ConversationHolder conversation
;
58 public AbstractBulkEditorInput() {
60 this.conversation
= CdmStore
.createConversation();
63 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
65 return BulkEditorInputType
.getInput(inputType
);
68 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
70 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
72 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
74 editorInput
.setEntityUuid(entity
.getUuid());
79 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
81 protected abstract T
loadEntity(UUID entityUuid
);
83 private void setEntityUuid(UUID entityUuid
){
84 this.entityUuid
= entityUuid
;
87 public UUID
getEntityUuid() {
92 public boolean exists() {
93 // TODO Auto-generated method stub
98 public ImageDescriptor
getImageDescriptor() {
99 // TODO Auto-generated method stub
104 public IPersistableElement
getPersistable() {
110 @SuppressWarnings("unchecked")
111 public Object
getAdapter(Class adapter
) {
115 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
117 List
<T
> entityList
= new ArrayList
<T
>();
119 if(getEntityUuid() != null){
121 T entity
= loadEntity(getEntityUuid());
122 entityList
.add(entity
);
125 else if(bulkEditorQuery
!= null){
127 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
128 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
130 entityList
= listEntities(configurator
);
132 Collections
.sort(entityList
, queryComparator
);
140 public boolean isMergingEnabled() {
144 public boolean isConvertingEnabled() {
148 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
155 public boolean merge(T entity
, T mergeTarget
) {
156 if (entity
instanceof IMergable
) {
158 CdmStore
.getCommonService().merge(mergeTarget
.getUuid(), entity
.getUuid(), (Class
<?
extends CdmBase
>)entity
.getClass());
159 } catch (MergeException e
) {
160 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
162 "Could not merge chosen objects of type " + entity
.getClass().getName(),
163 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
174 public T
create(T entity
) {
178 public IEntityCreator
<T
> getEntityCreator(){
179 if(entityCreator
== null){
180 entityCreator
= createEntityCreator();
182 return entityCreator
;
185 protected abstract IEntityCreator
<T
> createEntityCreator();
188 * The default implementation returns an empty list of sort providers.
191 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
192 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
194 sortProviders
.add(new CdmBaseSortProvider
<T
>());
196 return sortProviders
;
200 * Returns a textual representation given object. The default implementation
201 * in the abstract base class returns the simple name of the class, this may
202 * be overwritten to something more specific in subclasses.
205 * @return a textual representation given object.
207 public String
getTypeText(Object entity
){
208 return entity
.getClass().getSimpleName();
211 public String
getText(T entity
) {
212 if(entity
instanceof IdentifiableEntity
){
213 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
215 return identifiableEntity
.getTitleCache();
218 return "No text. Implement in subclass";
221 public List
<T
> getModel() {
225 public List
<AnnotatedTableItem
<T
>> getWrappedModel() {
226 List
<AnnotatedTableItem
<T
>> wrappetItems
= new ArrayList
<>();
228 wrappetItems
.add(new AnnotatedTableItem
<T
>(t
));
233 protected boolean replaceInModel(T entity
) {
234 int index
= model
.indexOf(entity
);
236 model
.set(index
, entity
);
244 public List
<T
> getRootEntities() {
250 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
251 // TODO Auto-generated method stub
255 public ConversationHolder
getConversation() {