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
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
28 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
29 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
30 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
31 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
32 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
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
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
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
> implements IEditorInput
, IEntityPersistenceService
<T
> {
51 private UUID entityUuid
;
53 private List
<T
> model
;
55 private IEntityCreator
<T
> entityCreator
;
57 private static Class serviceClass
;
62 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
63 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
65 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 T
loadEntity(UUID entityUuid
) {
103 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
104 return (T
) CdmStore
.getService(serviceClass
).load(entityUuid
, propertyPaths
);
107 private void setEntityUuid(UUID entityUuid
){
108 this.entityUuid
= entityUuid
;
112 * <p>Getter for the field <code>entityUuid</code>.</p>
114 * @return a {@link java.util.UUID} object.
116 public UUID
getEntityUuid() {
122 * @see org.eclipse.ui.IEditorInput#exists()
130 public boolean exists() {
131 // TODO Auto-generated method stub
136 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
139 * <p>getImageDescriptor</p>
141 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
144 public ImageDescriptor
getImageDescriptor() {
145 // TODO Auto-generated method stub
150 * @see org.eclipse.ui.IEditorInput#getPersistable()
153 * <p>getPersistable</p>
155 * @return a {@link org.eclipse.ui.IPersistableElement} object.
158 public IPersistableElement
getPersistable() {
163 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
167 @SuppressWarnings("unchecked")
168 public Object
getAdapter(Class adapter
) {
173 * <p>Setter for the field <code>query</code>.</p>
175 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
177 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
179 List
<T
> entityList
= new ArrayList
<T
>();
181 if(getEntityUuid() != null){
183 T entity
= loadEntity(getEntityUuid());
184 entityList
.add(entity
);
187 else if(bulkEditorQuery
!= null){
189 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
190 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
192 entityList
= listEntities(configurator
);
194 Collections
.sort(entityList
, queryComparator
);
203 * <p>isMergingEnabled</p>
207 public boolean isMergingEnabled() {
212 * <p>isMergingEnabled</p>
216 public boolean isConvertingEnabled() {
220 * <p>isMarkerTypeEditingEnabled</p>
222 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
225 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
232 public boolean merge(T entity
, T mergeTarget
) {
233 if (entity
instanceof IMergable
) {
235 CdmStore
.getCommonService().merge(mergeTarget
.getId(), entity
.getId(), (Class
<?
extends CdmBase
>)entity
.getClass());
236 } catch (MergeException e
) {
237 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
239 "Could not merge chosen objects of type " + entity
.getClass().getName(),
240 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
251 public boolean create(T entity
) {
255 public IEntityCreator
<T
> getEntityCreator(){
256 if(entityCreator
== null){
257 entityCreator
= createEntityCreator();
259 return entityCreator
;
265 protected abstract IEntityCreator
<T
> createEntityCreator();
268 * The default implementation returns an empty list of sort providers.
271 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
272 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
274 sortProviders
.add(new CdmBaseSortProvider
<T
>());
276 return sortProviders
;
280 * Returns a textual representation given object. The default implementation
281 * in the abstract base class returns the simple name of the class, this may
282 * be overwritten to something more specific in subclasses.
285 * @return a textual representation given object.
287 public String
getTypeText(Object entity
){
288 return entity
.getClass().getSimpleName();
295 public String
getText(T entity
) {
296 if(entity
instanceof IdentifiableEntity
){
297 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
299 return identifiableEntity
.getTitleCache();
302 return "No text. Implement in subclass";
308 public List
<?
> getModel() {