*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-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.store.CdmStore;
-import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
/**
* Editor input for the {@link DerivateView} which holds the currently selected derivate for which
* @date 25.11.2013
*
*/
-public class DerivateViewEditorInput extends CdmEntitySessionInput implements IEditorInput {
+public class DerivateViewEditorInput implements IEditorInput {
/**
- * The selected derivate {@link UUID}s
+ * The {@link UUID}s of the derivative entities
*/
- private 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"
- });
+ private Set<UUID> derivativeUUIDs;
/**
* 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 derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
- * @param rootUUIDs the root of the hierarchy
+ * @param derivativeUUIDs the root of the hierarchy
*/
public DerivateViewEditorInput(Set<UUID> derivateUuids) {
- 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();
- updateRootEntities(derivateUuids);
-
+ this.derivativeUUIDs = derivateUuids;
}
/* (non-Javadoc)
}
private String getEditorName() {
- String name = null;
- for( SpecimenOrObservationBase<?> specimen : rootEntities){
- if(specimen!=null){
- if(name==null){
- name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
- }
- else{
- name += " + "+DerivateLabelProvider.getDerivateText(specimen, conversationHolder); //$NON-NLS-1$
- }
- }
- }
- if(name==null){
- name = "Derivative Editor";
- }
- return name;
+ return "Derivative Editor";
}
- @Override
- public Set<SpecimenOrObservationBase<?>> getRootEntities() {
- return rootEntities;
- }
-
- public Set<SpecimenOrObservationBase<?>> getDerivateEntities() {
- return derivateEntities;
- }
-
- public void addRootEntity(SpecimenOrObservationBase<?> root){
- rootEntities.add(root);
- }
-
-
- public ConversationHolder getConversationHolder() {
- return conversationHolder;
+ /**
+ * @return the derivativeUUIDs
+ */
+ public Set<UUID> getDerivativeUUIDs() {
+ return derivativeUUIDs;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
+ result = prime * result + ((derivativeUUIDs == null) ? 0 : derivativeUUIDs.hashCode());
return result;
}
return false;
}
DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
- if (rootUUIDs == null) {
- if (other.rootUUIDs != null) {
+ if (derivativeUUIDs == null) {
+ if (other.derivativeUUIDs != null) {
return false;
}
- } else if (!rootUUIDs.equals(other.rootUUIDs)) {
+ } else if (!derivativeUUIDs.equals(other.derivativeUUIDs)) {
return false;
}
return true;
}
- @Override
- public void merge() {
- if(CdmStore.getCurrentSessionManager().isRemoting()) {
- CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
- }
-
- }
-
- @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;
- }
-
- public void updateRootEntities(Collection<UUID> derivateUuids) {
- this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
- this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
- for (UUID uuid : derivateUuids) {
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
- derivateEntities.add(derivate);
- if(derivate instanceof FieldUnit){
- rootEntities.add(derivate);
- }
- else if(derivate instanceof DerivedUnit){
- SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
- if(topMostDerivate!=null){
- rootEntities.add(topMostDerivate);
- }
- }
- }
- if(rootEntities.isEmpty()){
- rootEntities = derivateEntities;
- }
- }
-
}