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
.model
.MessagingUtils
;
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
> {
50 private UUID entityUuid
;
52 private List
<T
> model
;
54 private IEntityCreator
<T
> entityCreator
;
56 private static Class serviceClass
;
61 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
62 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
64 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
66 return BulkEditorInputType
.getInput(inputType
);
72 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
73 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
75 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
78 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
80 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
82 editorInput
.setEntityUuid(entity
.getUuid());
90 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
91 * @return a {@link java.util.List} object.
93 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
98 * @param entityUuid a {@link java.util.UUID} object.
101 protected T
loadEntity(UUID entityUuid
) {
102 List
<String
> propertyPaths
= Arrays
.asList(new String
[]{});
103 return (T
) CdmStore
.getService(serviceClass
).load(entityUuid
, propertyPaths
);
106 private void setEntityUuid(UUID entityUuid
){
107 this.entityUuid
= entityUuid
;
111 * <p>Getter for the field <code>entityUuid</code>.</p>
113 * @return a {@link java.util.UUID} object.
115 public UUID
getEntityUuid() {
121 * @see org.eclipse.ui.IEditorInput#exists()
129 public boolean exists() {
130 // TODO Auto-generated method stub
135 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
138 * <p>getImageDescriptor</p>
140 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
143 public ImageDescriptor
getImageDescriptor() {
144 // TODO Auto-generated method stub
149 * @see org.eclipse.ui.IEditorInput#getPersistable()
152 * <p>getPersistable</p>
154 * @return a {@link org.eclipse.ui.IPersistableElement} object.
157 public IPersistableElement
getPersistable() {
162 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
166 @SuppressWarnings("unchecked")
167 public Object
getAdapter(Class adapter
) {
172 * <p>Setter for the field <code>query</code>.</p>
174 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
176 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
178 List
<T
> entityList
= new ArrayList
<T
>();
180 if(getEntityUuid() != null){
182 T entity
= loadEntity(getEntityUuid());
183 entityList
.add(entity
);
186 else if(bulkEditorQuery
!= null){
188 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
189 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
191 entityList
= listEntities(configurator
);
193 Collections
.sort(entityList
, queryComparator
);
202 * <p>isMergingEnabled</p>
206 public boolean isMergingEnabled() {
211 * <p>isMergingEnabled</p>
215 public boolean isConvertingEnabled() {
219 * <p>isMarkerTypeEditingEnabled</p>
221 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
224 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
231 public boolean merge(T entity
, T mergeTarget
) {
232 if (entity
instanceof IMergable
) {
234 CdmStore
.getCommonService().merge((IMergable
)mergeTarget
, (IMergable
)entity
);
235 } catch (MergeException e
) {
236 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
238 "Could not merge chosen objects of type " + entity
.getClass().getName(),
239 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
250 public boolean create(T entity
) {
254 public IEntityCreator
<T
> getEntityCreator(){
255 if(entityCreator
== null){
256 entityCreator
= createEntityCreator();
258 return entityCreator
;
264 protected abstract IEntityCreator
<T
> createEntityCreator();
267 * The default implementation returns an empty list of sort providers.
270 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
271 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
273 sortProviders
.add(new CdmBaseSortProvider
<T
>());
275 return sortProviders
;
279 * Returns a textual representation given object. The default implementation
280 * in the abstract base class returns the simple name of the class, this may
281 * be overwritten to something more specific in subclasses.
284 * @return a textual representation given object.
286 public String
getTypeText(Object entity
){
287 return entity
.getClass().getSimpleName();
294 public String
getText(T entity
) {
295 if(entity
instanceof IdentifiableEntity
){
296 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
298 return identifiableEntity
.getTitleCache();
301 return "No text. Implement in subclass";
307 public List
<?
> getModel() {