Trim code
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / input / AbstractBulkEditorInput.java
index 9da689de70e7e73a5c931168b1bf59ca10d080f8..d57ea686635b84c2219f18ff87d83e6e1c1873d6 100644 (file)
@@ -13,19 +13,20 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
 
-import eu.etaxonomy.cdm.api.service.ICommonService;
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.ICdmBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.MarkerType;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.strategy.merge.IMergable;
 import eu.etaxonomy.cdm.strategy.merge.MergeException;
 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
@@ -34,49 +35,39 @@ import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.CdmBaseSortProvider;
 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.TitleCacheComparator;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
+import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
- * <p>Abstract AbstractBulkEditorInput class.</p>
- *
  * @author p.ciardelli
  * @created 25.06.2009
  * @version 1.0
  * @param <T>
  */
-public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEditorInput, IEntityPersistenceService<T> {
-
-       /**
-        *
-        */
-       private static final long serialVersionUID = 416414530232743735L;
+public abstract class AbstractBulkEditorInput<T extends ICdmBase> extends CdmEntitySessionInput implements IEditorInput ,
+    IEntityPersistenceService<T> {
 
        private UUID entityUuid;
 
        private List<T> model;
 
        private IEntityCreator<T> entityCreator;
+       private final ConversationHolder conversation;
+
+       public AbstractBulkEditorInput() {
+           super(true);
+           this.conversation = CdmStore.createConversation();
+       }
 
-       /**
-        * <p>NewInstance</p>
-        *
-        * @param inputType a {@link eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInputTypeValues.BulkEditorInputType} object.
-        * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
-        */
        static public AbstractBulkEditorInput NewInstance(BulkEditorInputType inputType) {
+
                return BulkEditorInputType.getInput(inputType);
        }
 
-       /**
-        * <p>NewInstance</p>
-        *
-        * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
-        * @return a {@link eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput} object.
-        */
        public static AbstractBulkEditorInput NewInstance(IdentifiableEntity entity) {
 
-
                BulkEditorInputType inputType = BulkEditorInputType.getByType(entity.getClass());
 
                AbstractBulkEditorInput editorInput = NewInstance(inputType);
@@ -86,80 +77,35 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return editorInput;
        }
 
-       /**
-        * <p>listEntities</p>
-        *
-        * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
-        * @return a {@link java.util.List} object.
-        */
        protected abstract List<T> listEntities(IIdentifiableEntityServiceConfigurator configurator);
 
-       /**
-        * <p>loadEntity</p>
-        *
-        * @param entityUuid a {@link java.util.UUID} object.
-        * @return a T object.
-        */
        protected abstract T loadEntity(UUID entityUuid);
 
        private void setEntityUuid(UUID entityUuid){
                this.entityUuid = entityUuid;
        }
 
-       /**
-        * <p>Getter for the field <code>entityUuid</code>.</p>
-        *
-        * @return a {@link java.util.UUID} object.
-        */
        public UUID getEntityUuid() {
                return entityUuid;
        }
 
-
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#exists()
-        */
-       /**
-        * <p>exists</p>
-        *
-        * @return a boolean.
-        */
        @Override
     public boolean exists() {
                // TODO Auto-generated method stub
                return false;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
-        */
-       /**
-        * <p>getImageDescriptor</p>
-        *
-        * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
-        */
        @Override
     public ImageDescriptor getImageDescriptor() {
                // TODO Auto-generated method stub
                return null;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.IEditorInput#getPersistable()
-        */
-       /**
-        * <p>getPersistable</p>
-        *
-        * @return a {@link org.eclipse.ui.IPersistableElement} object.
-        */
        @Override
     public IPersistableElement getPersistable() {
                return null;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
-        */
        /** {@inheritDoc} */
        @Override
     @SuppressWarnings("unchecked")
@@ -167,11 +113,6 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return null;
        }
 
-       /**
-        * <p>Setter for the field <code>query</code>.</p>
-        *
-        * @param bulkEditorQuery a {@link eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorQuery} object.
-        */
        public void performSearch(final BulkEditorQuery bulkEditorQuery) {
 
                List<T> entityList = new ArrayList<T>();
@@ -191,54 +132,47 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
 
                        Collections.sort(entityList, queryComparator);
 
+
                }
 
                model = entityList;
        }
 
-       /**
-        * <p>isMergingEnabled</p>
-        *
-        * @return a boolean.
-        */
        public boolean isMergingEnabled() {
                return false;
        }
 
-       /**
-        * <p>isMarkerTypeEditingEnabled</p>
-        *
-        * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object.
-        * @return a boolean.
-        */
+       public boolean isConvertingEnabled() {
+               return false;
+       }
+
        public boolean isMarkerTypeEditingEnabled(MarkerType markerType) {
                return false;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#merge(eu.etaxonomy.cdm.model.common.IdentifiableEntity, eu.etaxonomy.cdm.model.common.IdentifiableEntity)
-        */
+
        /** {@inheritDoc} */
        @Override
     public boolean merge(T entity, T mergeTarget) {
                if (entity instanceof IMergable) {
                        try {
-                               CdmStore.getService(ICommonService.class).merge((IMergable)mergeTarget, (IMergable)entity, null);
+                               CdmStore.getCommonService().merge(mergeTarget.getUuid(), entity.getUuid(), (Class<? extends CdmBase>)entity.getClass());
                        } catch (MergeException e) {
-                               AbstractUtility.error(getClass(), e);
+                               MessagingUtils.errorDialog("Bulk Editor Merge Error",
+                                               this,
+                                               "Could not merge chosen objects of type " + entity.getClass().getName(),
+                                               TaxeditorBulkeditorPlugin.PLUGIN_ID,
+                                               e,
+                                               true);
                        }
                }
                return true;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService#create(eu.etaxonomy.cdm.model.common.IdentifiableEntity)
-        */
+
        /** {@inheritDoc} */
        @Override
-    public boolean create(T entity) {
+    public T create(T entity) {
                return save(entity);
        }
 
@@ -249,9 +183,6 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return entityCreator;
        }
 
-       /**
-        * @return
-        */
        protected abstract IEntityCreator<T> createEntityCreator();
 
        /**
@@ -267,17 +198,17 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
        }
 
        /**
+        * Returns a textual representation given object. The default implementation
+        * in the abstract base class returns the simple name of the class, this may
+        * be overwritten to something more specific in subclasses.
+        *
         * @param entity
-        * @return
+        * @return a textual representation given object.
         */
        public String getTypeText(Object entity){
-               return ((SpecimenOrObservationBase) entity).getRecordBasis().toString();
+               return entity.getClass().getSimpleName();
        }
 
-       /**
-        * @param entity
-        * @return
-        */
        public String getText(T entity) {
                if(entity instanceof IdentifiableEntity){
                        IdentifiableEntity identifiableEntity = (IdentifiableEntity) HibernateProxyHelper.deproxy(entity);
@@ -288,12 +219,33 @@ public abstract class AbstractBulkEditorInput<T extends ICdmBase> implements IEd
                return "No text. Implement in subclass";
        }
 
-       /**
-        * @return
-        */
-       public List<?> getModel() {
+       public List<T> getModel() {
                return model;
        }
 
+       protected boolean replaceInModel(T entity) {
+           int index = model.indexOf(entity);
+           if(index >= 0) {
+               model.set(index, entity);
+               return true;
+           } else {
+               return false;
+           }
+       }
+
+    @Override
+    public   List<T> getRootEntities() {
+        return getModel();
+    }
+
 
+    @Override
+    public Map<Object, List<String>> getPropertyPathsMap() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+       public ConversationHolder getConversation() {
+               return conversation;
+       }
 }