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
;
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
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
25 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
30 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
31 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
32 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
33 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
34 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorSortProvider
;
36 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.CdmBaseSortProvider
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.sortprovider
.TitleCacheComparator
;
38 import eu
.etaxonomy
.taxeditor
.bulkeditor
.internal
.TaxeditorBulkeditorPlugin
;
39 import eu
.etaxonomy
.taxeditor
.editor
.CdmEntitySessionInput
;
40 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
41 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
44 * <p>Abstract AbstractBulkEditorInput class.</p>
51 public abstract class AbstractBulkEditorInput
<T
extends ICdmBase
> extends CdmEntitySessionInput
implements IEditorInput
,
52 IEntityPersistenceService
<T
> {
54 private UUID entityUuid
;
56 private List
<T
> model
;
58 private IEntityCreator
<T
> entityCreator
;
59 private final ConversationHolder conversation
;
61 public AbstractBulkEditorInput() {
63 this.conversation
= CdmStore
.createConversation();
69 * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
70 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
72 static public AbstractBulkEditorInput
NewInstance(BulkEditorInputType inputType
) {
74 return BulkEditorInputType
.getInput(inputType
);
80 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
81 * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
83 public static AbstractBulkEditorInput
NewInstance(IdentifiableEntity entity
) {
86 BulkEditorInputType inputType
= BulkEditorInputType
.getByType(entity
.getClass());
88 AbstractBulkEditorInput editorInput
= NewInstance(inputType
);
90 editorInput
.setEntityUuid(entity
.getUuid());
98 * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
99 * @return a {@link java.util.List} object.
101 protected abstract List
<T
> listEntities(IIdentifiableEntityServiceConfigurator configurator
);
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()
128 public boolean exists() {
129 // TODO Auto-generated method stub
134 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
137 * <p>getImageDescriptor</p>
139 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
142 public ImageDescriptor
getImageDescriptor() {
143 // TODO Auto-generated method stub
148 * @see org.eclipse.ui.IEditorInput#getPersistable()
151 * <p>getPersistable</p>
153 * @return a {@link org.eclipse.ui.IPersistableElement} object.
156 public IPersistableElement
getPersistable() {
161 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
165 @SuppressWarnings("unchecked")
166 public Object
getAdapter(Class adapter
) {
171 * <p>Setter for the field <code>query</code>.</p>
173 * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
175 public void performSearch(final BulkEditorQuery bulkEditorQuery
) {
177 List
<T
> entityList
= new ArrayList
<T
>();
179 if(getEntityUuid() != null){
181 T entity
= loadEntity(getEntityUuid());
182 entityList
.add(entity
);
185 else if(bulkEditorQuery
!= null){
187 IIdentifiableEntityServiceConfigurator configurator
= bulkEditorQuery
.getSearchConfigurator();
188 Comparator queryComparator
= (bulkEditorQuery
.getComparator() != null) ? bulkEditorQuery
.getComparator() : new TitleCacheComparator();
190 entityList
= listEntities(configurator
);
192 Collections
.sort(entityList
, queryComparator
);
201 * <p>isMergingEnabled</p>
205 public boolean isMergingEnabled() {
210 * <p>isMergingEnabled</p>
214 public boolean isConvertingEnabled() {
218 * <p>isMarkerTypeEditingEnabled</p>
220 * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
223 public boolean isMarkerTypeEditingEnabled(MarkerType markerType
) {
230 public boolean merge(T entity
, T mergeTarget
) {
231 if (entity
instanceof IMergable
) {
233 CdmStore
.getCommonService().merge(mergeTarget
.getUuid(), entity
.getUuid(), (Class
<?
extends CdmBase
>)entity
.getClass());
234 } catch (MergeException e
) {
235 MessagingUtils
.errorDialog("Bulk Editor Merge Error",
237 "Could not merge chosen objects of type " + entity
.getClass().getName(),
238 TaxeditorBulkeditorPlugin
.PLUGIN_ID
,
249 public T
create(T entity
) {
253 public IEntityCreator
<T
> getEntityCreator(){
254 if(entityCreator
== null){
255 entityCreator
= createEntityCreator();
257 return entityCreator
;
263 protected abstract IEntityCreator
<T
> createEntityCreator();
266 * The default implementation returns an empty list of sort providers.
269 public List
<IBulkEditorSortProvider
<T
>> getSortProviders(){
270 List
<IBulkEditorSortProvider
<T
>> sortProviders
= new ArrayList
<IBulkEditorSortProvider
<T
>>();
272 sortProviders
.add(new CdmBaseSortProvider
<T
>());
274 return sortProviders
;
278 * Returns a textual representation given object. The default implementation
279 * in the abstract base class returns the simple name of the class, this may
280 * be overwritten to something more specific in subclasses.
283 * @return a textual representation given object.
285 public String
getTypeText(Object entity
){
286 return entity
.getClass().getSimpleName();
293 public String
getText(T entity
) {
294 if(entity
instanceof IdentifiableEntity
){
295 IdentifiableEntity identifiableEntity
= (IdentifiableEntity
) HibernateProxyHelper
.deproxy(entity
);
297 return identifiableEntity
.getTitleCache();
300 return "No text. Implement in subclass";
306 public List
<T
> getModel() {
310 protected boolean replaceInModel(T entity
) {
311 int index
= model
.indexOf(entity
);
313 model
.set(index
, entity
);
321 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
324 public List
<T
> getRootEntities() {
330 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
333 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
334 // TODO Auto-generated method stub
338 public ConversationHolder
getConversation() {