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
.command
.BulkEditorInputTypeValues
.BulkEditorInputType
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
38 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
41 * <p>Abstract AbstractBulkEditorInput class.</p>
48 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> implements IEditorInput
, IEntityPersistenceService
<T
> {
53 private static final long serialVersionUID
= 416414530232743735L;
55 private UUID entityUuid
;
57 private List
<T
> model
;
59 private IEntityCreator
<T
> entityCreator
;
64 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.command.BulkEditorInputTypeValues.BulkEditorInputType} object.
65 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
67 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
68 return BulkEditorInputType
.getInput(inputType
);
74 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
75 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
77 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
80 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
82 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
84 editorInput
.setEntityUuid(entity
.getUuid());
92 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
93 * @return a {@link java.util.List} object.
95 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
100 * @param entityUuid a {@link java.util.UUID} object.
101 * @return a T object.
103 protected abstract T
loadEntity(UUID entityUuid
);
105 private void setEntityUuid(UUID entityUuid
){
106 this.entityUuid
= entityUuid
;
110 * <p>Getter for the field <code>entityUuid</code>.</p>
112 * @return a {@link java.util.UUID} object.
114 public UUID
getEntityUuid() {
120 * @see org.eclipse.ui.IEditorInput#exists()
127 public boolean exists() {
128 // TODO Auto-generated method stub
133 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
136 * <p>getImageDescriptor</p>
138 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
140 public ImageDescriptor
getImageDescriptor() {
141 // TODO Auto-generated method stub
146 * @see org.eclipse.ui.IEditorInput#getPersistable()
149 * <p>getPersistable</p>
151 * @return a {@link org.eclipse.ui.IPersistableElement} object.
153 public IPersistableElement
getPersistable() {
158 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
161 @SuppressWarnings("unchecked")
162 public Object
getAdapter(Class adapter
) {
167 * <p>Setter for the field <code>query</code>.</p>
169 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
171 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
173 List
<T
> entityList
= new ArrayList
<T
>();
175 if(getEntityUuid() != null){
177 T entity
= loadEntity(getEntityUuid());
178 entityList
.add(entity
);
181 else if(bulkEditorQuery
!= null){
183 String queryString
= bulkEditorQuery
.getSearchString();
184 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
185 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
187 entityList
= listEntities(configurator
);
189 Collections
.sort(entityList
, queryComparator
);
197 * <p>isMergingEnabled</p>
201 public boolean isMergingEnabled() {
206 * <p>isMarkerTypeEditingEnabled</p>
208 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
211 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
217 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
220 public boolean merge(T entity
, T mergeTarget
) {
221 if (entity
instanceof IMergable
) {
223 CdmStore
.getService(ICommonService
.class).merge((IMergable
)mergeTarget
, (IMergable
)entity
, null);
224 } catch (MergeException e
) {
225 BulkEditorUtil
.error(getClass(), e
);
233 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
236 public boolean create(T entity
) {
240 public IEntityCreator
<T
> getEntityCreator(){
241 if(entityCreator
== null){
242 entityCreator
= createEntityCreator();
244 return entityCreator
;
250 protected abstract IEntityCreator
<T
> createEntityCreator();
253 * The default implementation returns an empty list of sort providers.
256 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
257 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
259 sortProviders
.add(new CdmBaseSortProvider
<T
>());
261 return sortProviders
;
268 public String
getTypeText(Object entity
){
269 return entity
.getClass().getSimpleName();
276 public String
getText(T entity
) {
277 if(entity
instanceof IdentifiableEntity
){
278 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
280 return identifiableEntity
.getTitleCache();
283 return "No text. Implement in subclass";
289 public List
<?
> getModel() {