*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
+import java.util.HashSet;
+import java.util.Set;
import java.util.UUID;
import org.eclipse.jface.resource.ImageDescriptor;
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
public class DerivateViewEditorInput implements IEditorInput{
/**
- * The selected derivate {@link UUID}
+ * The selected derivate {@link UUID}s
*/
- private UUID derivateUUID;
+ private Set<UUID> derivateUUIDs;
/**
- * The {@link UUID} of the root of the hierarchy (may be the same object as the derivate)
+ * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
*/
- private UUID rootUUID;
+ private Set<UUID> rootUUIDs;
private final ConversationHolder conversationHolder;
/**
- * Creates an editor input for the {@link DerivateView} with the currently selected derivate and the
- * corresponding {@link FieldUnit} (both may be the same object).
- * @param derivateUuid the {@link UUID} of the derivate for which the derivate hierarchy should be shown
- * @param rootUUID the root of the hierarchy
+ * 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
*/
- public DerivateViewEditorInput(UUID derivateUuid) {
+ public DerivateViewEditorInput(Set<UUID> derivateUuids) {
super();
this.conversationHolder = CdmStore.createConversation();
- this.derivateUUID = derivateUuid;
- SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(derivateUuid);
- if(derivate instanceof FieldUnit){
- this.rootUUID = derivateUUID;
- }
- else if(derivate instanceof DerivedUnit){
- SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
- rootUUID = topMostDerivate==null?null:topMostDerivate.getUuid();
- if(rootUUID==null){
- rootUUID = derivateUUID;
+ 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(rootUUID==null){
+ if(rootUUIDs.isEmpty()){
+ rootUUIDs = derivateUUIDs;
+ }
+ if(rootUUIDs.isEmpty()){
MessagingUtils.messageDialog("Failed initializing editor", DerivateViewEditorInput.class, "No root element found!");
}
}
*/
@Override
public String getName() {
- return derivateUUID.toString();
+ return getEditorName();
}
/* (non-Javadoc)
*/
@Override
public String getToolTipText() {
- return derivateUUID.toString();
+ return getEditorName();
+ }
+
+ 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 UUID getDerivateUUID() {
- return derivateUUID;
+ public Set<UUID> getRootUUIDs() {
+ return rootUUIDs;
}
- public UUID getRootElementUUID() {
- return rootUUID;
+ public Set<UUID> getDerivateUUIDs() {
+ return derivateUUIDs;
}
public void setRootAsDerivate(){
- this.derivateUUID = this.rootUUID;
+ this.derivateUUIDs = this.rootUUIDs;
}
public ConversationHolder getConversationHolder() {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((rootUUID == null) ? 0 : rootUUID.hashCode());
+ result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
return result;
}
return false;
}
DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
- if (rootUUID == null) {
- if (other.rootUUID != null) {
+ if (rootUUIDs == null) {
+ if (other.rootUUIDs != null) {
return false;
}
- } else if (!rootUUID.equals(other.rootUUID)) {
+ } else if (!rootUUIDs.equals(other.rootUUIDs)) {
return false;
}
return true;
}
+
}