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
.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
.BulkEditorUtil
;
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
.store
.CdmStore
;
40 * <p>Abstract AbstractBulkEditorInput class.</p>
47 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> implements IEditorInput
, IEntityPersistenceService
<T
> {
52 private static final long serialVersionUID
= 416414530232743735L;
54 private UUID entityUuid
;
56 private List
<T
> model
;
58 private IEntityCreator
<T
> entityCreator
;
63 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
64 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
66 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
67 return BulkEditorInputType
.getInput(inputType
);
73 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
74 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
76 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
79 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
81 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
83 editorInput
.setEntityUuid(entity
.getUuid());
91 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
92 * @return a {@link java.util.List} object.
94 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
99 * @param entityUuid a {@link java.util.UUID} object.
100 * @return a T object.
102 protected abstract T
loadEntity(UUID entityUuid
);
104 private void setEntityUuid(UUID entityUuid
){
105 this.entityUuid
= entityUuid
;
109 * <p>Getter for the field <code>entityUuid</code>.</p>
111 * @return a {@link java.util.UUID} object.
113 public UUID
getEntityUuid() {
119 * @see org.eclipse.ui.IEditorInput#exists()
126 public boolean exists() {
127 // TODO Auto-generated method stub
132 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
135 * <p>getImageDescriptor</p>
137 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
139 public ImageDescriptor
getImageDescriptor() {
140 // TODO Auto-generated method stub
145 * @see org.eclipse.ui.IEditorInput#getPersistable()
148 * <p>getPersistable</p>
150 * @return a {@link org.eclipse.ui.IPersistableElement} object.
152 public IPersistableElement
getPersistable() {
157 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
160 @SuppressWarnings("unchecked")
161 public Object
getAdapter(Class adapter
) {
166 * <p>Setter for the field <code>query</code>.</p>
168 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
170 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
172 List
<T
> entityList
= new ArrayList
<T
>();
174 if(getEntityUuid() != null){
176 T entity
= loadEntity(getEntityUuid());
177 entityList
.add(entity
);
180 else if(bulkEditorQuery
!= null){
182 String queryString
= bulkEditorQuery
.getSearchString();
183 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
184 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
186 entityList
= listEntities(configurator
);
188 Collections
.sort(entityList
, queryComparator
);
196 * <p>isMergingEnabled</p>
200 public boolean isMergingEnabled() {
205 * <p>isMarkerTypeEditingEnabled</p>
207 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
210 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
216 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
219 public boolean merge(T entity
, T mergeTarget
) {
220 if (entity
instanceof IMergable
) {
222 CdmStore
.getService(ICommonService
.class).merge((IMergable
)mergeTarget
, (IMergable
)entity
, null);
223 } catch (MergeException e
) {
224 BulkEditorUtil
.error(getClass(), e
);
232 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
235 public boolean create(T entity
) {
239 public IEntityCreator
<T
> getEntityCreator(){
240 if(entityCreator
== null){
241 entityCreator
= createEntityCreator();
243 return entityCreator
;
249 protected abstract IEntityCreator
<T
> createEntityCreator();
252 * The default implementation returns an empty list of sort providers.
255 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
256 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
258 sortProviders
.add(new CdmBaseSortProvider
<T
>());
260 return sortProviders
;
267 public String
getTypeText(Object entity
){
268 return entity
.getClass().getSimpleName();
275 public String
getText(T entity
) {
276 if(entity
instanceof IdentifiableEntity
){
277 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
279 return identifiableEntity
.getTitleCache();
282 return "No text. Implement in subclass";
288 public List
<?
> getModel() {