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
.Arrays
;
14 import java
.util
.Collections
;
15 import java
.util
.Comparator
;
16 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
.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
.IBulkEditorSortProvider
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
37 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
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
> extends CdmEntitySessionInput
implements IEditorInput
,
50 IEntityPersistenceService
<T
> {
52 private UUID entityUuid
;
54 private List
<T
> model
;
56 private IEntityCreator
<T
> entityCreator
;
58 private static Class serviceClass
;
60 public AbstractBulkEditorInput() {
67 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
68 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
70 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
72 return BulkEditorInputType
.getInput(inputType
);
78 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
79 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
81 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
84 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
86 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
88 editorInput
.setEntityUuid(entity
.getUuid());
96 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
97 * @return a {@link java.util.List} object.
99 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
104 * @param entityUuid a {@link java.util.UUID} object.
105 * @return a T object.
107 protected T
loadEntity(UUID entityUuid
) {
108 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
109 return (T
) CdmStore
.getService(serviceClass
).load(entityUuid
, propertyPaths
);
112 private void setEntityUuid(UUID entityUuid
){
113 this.entityUuid
= entityUuid
;
117 * <p>Getter for the field <code>entityUuid</code>.</p>
119 * @return a {@link java.util.UUID} object.
121 public UUID
getEntityUuid() {
127 * @see org.eclipse.ui.IEditorInput#exists()
135 public boolean exists() {
136 // TODO Auto-generated method stub
141 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
144 * <p>getImageDescriptor</p>
146 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
149 public ImageDescriptor
getImageDescriptor() {
150 // TODO Auto-generated method stub
155 * @see org.eclipse.ui.IEditorInput#getPersistable()
158 * <p>getPersistable</p>
160 * @return a {@link org.eclipse.ui.IPersistableElement} object.
163 public IPersistableElement
getPersistable() {
168 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
172 @SuppressWarnings("unchecked")
173 public Object
getAdapter(Class adapter
) {
178 * <p>Setter for the field <code>query</code>.</p>
180 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
182 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
184 List
<T
> entityList
= new ArrayList
<T
>();
186 if(getEntityUuid() != null){
188 T entity
= loadEntity(getEntityUuid());
189 entityList
.add(entity
);
192 else if(bulkEditorQuery
!= null){
194 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
195 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
197 entityList
= listEntities(configurator
);
199 Collections
.sort(entityList
, queryComparator
);
208 * <p>isMergingEnabled</p>
212 public boolean isMergingEnabled() {
217 * <p>isMergingEnabled</p>
221 public boolean isConvertingEnabled() {
225 * <p>isMarkerTypeEditingEnabled</p>
227 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
230 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
237 public boolean merge(T entity
, T mergeTarget
) {
238 if (entity
instanceof IMergable
) {
240 CdmStore
.getCommonService().merge((IMergable
)mergeTarget
, (IMergable
)entity
);
241 } catch (MergeException e
) {
242 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
244 "Could not merge chosen objects of type " + entity
.getClass().getName(),
245 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
256 public boolean create(T entity
) {
260 public IEntityCreator
<T
> getEntityCreator(){
261 if(entityCreator
== null){
262 entityCreator
= createEntityCreator();
264 return entityCreator
;
270 protected abstract IEntityCreator
<T
> createEntityCreator();
273 * The default implementation returns an empty list of sort providers.
276 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
277 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
279 sortProviders
.add(new CdmBaseSortProvider
<T
>());
281 return sortProviders
;
285 * Returns a textual representation given object. The default implementation
286 * in the abstract base class returns the simple name of the class, this may
287 * be overwritten to something more specific in subclasses.
290 * @return a textual representation given object.
292 public String
getTypeText(Object entity
){
293 return entity
.getClass().getSimpleName();
300 public String
getText(T entity
) {
301 if(entity
instanceof IdentifiableEntity
){
302 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
304 return identifiableEntity
.getTitleCache();
307 return "No text. Implement in subclass";
313 public List
<T
> getModel() {
320 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
323 public List
<T
> getRootEntities() {