*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.Messages;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
* @date 25.11.2013
*
*/
-public class DerivateViewEditorInput implements IEditorInput{
+public class DerivateViewEditorInput extends CdmEntitySessionInput implements IEditorInput {
/**
* The selected derivate {@link UUID}s
*/
- private final Set<UUID> derivateUUIDs;
+ private final Set<SpecimenOrObservationBase<?>> derivateEntities;
/**
* List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
*/
+ private Set<SpecimenOrObservationBase<?>> rootEntities;
private Set<UUID> rootUUIDs;
private final ConversationHolder conversationHolder;
+ private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
+ "descriptions",
+ "annotations",
+ "markers",
+ "credits",
+ "extensions",
+ "rights",
+ "sources",
+ "derivationEvents.derivatives.annotations",
+ "derivationEvents.derivatives.markers",
+ "derivationEvents.derivatives.credits",
+ "derivationEvents.derivatives.extensions",
+ "derivationEvents.derivatives.rights",
+ "derivationEvents.derivatives.sources"
+ });
+
/**
* Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
* corresponding {@link FieldUnit}s (both may be the same object).
* @param rootUUIDs the root of the hierarchy
*/
public DerivateViewEditorInput(Set<UUID> derivateUuids) {
- super();
+ super(false);
+ rootUUIDs = derivateUuids;
+ //FIXME:Remoting temporary hack for making the sessions work
+ //This should ideally be changed to initializing the
+ //super class with a collection of (id) objects which can
+ //then be used for the hashCode, equals methods
+ initSession();
this.conversationHolder = CdmStore.createConversation();
- this.derivateUUIDs = derivateUuids;
- this.rootUUIDs = new HashSet<UUID>();
+ this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
+ this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
for (UUID uuid : derivateUuids) {
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid);
+ SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+ derivateEntities.add(derivate);
if(derivate instanceof FieldUnit){
- rootUUIDs.add(uuid);
+ rootEntities.add(derivate);
}
else if(derivate instanceof DerivedUnit){
SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
if(topMostDerivate!=null){
- rootUUIDs.add(topMostDerivate.getUuid());
+ rootEntities.add(topMostDerivate);
}
}
}
- if(rootUUIDs.isEmpty()){
- rootUUIDs = derivateUUIDs;
+ if(rootEntities.isEmpty()){
+ rootEntities = derivateEntities;
}
- if(rootUUIDs.isEmpty()){
+ if(rootEntities.isEmpty()){
MessagingUtils.messageDialog(Messages.DerivateViewEditorInput_FAIL_INIT, DerivateViewEditorInput.class, Messages.DerivateViewEditorInput_NO_ROOT);
}
+
+
}
/* (non-Javadoc)
private String getEditorName() {
String name = null;
- for(UUID uuid:rootUUIDs){
- SpecimenOrObservationBase<?> specimen = CdmStore.getService(IOccurrenceService.class).load(uuid);
+ for( SpecimenOrObservationBase<?> specimen : rootEntities){
if(specimen!=null){
if(name==null){
name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
return name;
}
- public Set<UUID> getRootUUIDs() {
- return rootUUIDs;
+ @Override
+ public Set<SpecimenOrObservationBase<?>> getRootEntities() {
+ return rootEntities;
}
- public Set<UUID> getDerivateUUIDs() {
- return derivateUUIDs;
+ public Set<SpecimenOrObservationBase<?>> getDerivateEntities() {
+ return derivateEntities;
}
- public void addRootUuid(UUID root){
- rootUUIDs.add(root);
+ public void addRootEntity(SpecimenOrObservationBase<?> root){
+ rootEntities.add(root);
}
return true;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
+ */
+ @Override
+ public void merge() {
+ List<SpecimenOrObservationBase> mergedEntities = CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()));
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+ */
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ List<String> specimenPropertyPaths = Arrays.asList(new String[] {
+ "descriptions",
+ "derivationEvents.derivates",
+ "annotations",
+ "markers",
+ "credits",
+ "extensions",
+ "rights",
+ "sources"
+ });
+ Map<Object, List<String>> specimenPropertyPathMap =
+ new HashMap<Object, List<String>>();
+ specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
+ return specimenPropertyPathMap;
+ }
+
}