*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
-import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
-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.EditorUtil;
-import eu.etaxonomy.taxeditor.model.MessagingUtils;
-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 implements IEditorInput{
+public class DerivateViewEditorInput implements IEditorInput {
/**
- * The selected derivate {@link UUID}s
+ * The {@link UUID}s of the derivative entities
*/
- private final Set<UUID> derivateUUIDs;
- /**
- * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
- */
- private Set<UUID> rootUUIDs;
-
- private final ConversationHolder conversationHolder;
+ 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();
- this.conversationHolder = CdmStore.createConversation();
- this.derivateUUIDs = derivateUuids;
- this.rootUUIDs = new HashSet<UUID>();
- for (UUID uuid : derivateUuids) {
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid);
- if(derivate instanceof FieldUnit){
- rootUUIDs.add(uuid);
- }
- else if(derivate instanceof DerivedUnit){
- SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
- if(topMostDerivate!=null){
- rootUUIDs.add(topMostDerivate.getUuid());
- }
- }
- }
- if(rootUUIDs.isEmpty()){
- rootUUIDs = derivateUUIDs;
- }
- if(rootUUIDs.isEmpty()){
- MessagingUtils.messageDialog("Failed initializing editor", DerivateViewEditorInput.class, "No root element found!");
- }
+ this.derivativeUUIDs = derivateUuids;
}
/* (non-Javadoc)
}
private String getEditorName() {
- String name = null;
- for(UUID uuid:rootUUIDs){
- SpecimenOrObservationBase<?> specimen = CdmStore.getService(IOccurrenceService.class).load(uuid);
- if(specimen!=null){
- if(name==null){
- name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
- }
- else{
- name += " + "+DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
- }
- }
- }
- return name;
- }
-
- public Set<UUID> getRootUUIDs() {
- return rootUUIDs;
+ return "Derivative Editor";
}
- public Set<UUID> getDerivateUUIDs() {
- return derivateUUIDs;
- }
-
- public void addRootUuid(UUID root){
- rootUUIDs.add(root);
- }
-
-
- public ConversationHolder getConversationHolder() {
- return conversationHolder;
+ /**
+ * @return the derivativeUUIDs
+ */
+ public Set<UUID> getDerivativeUUIDs() {
+ return derivativeUUIDs;
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
@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;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {
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;
}
-
}