package eu.etaxonomy.taxeditor.editor.view.derivate;
+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.Map.Entry;
import java.util.Set;
import java.util.UUID;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.molecular.Sequence;
import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.Messages;
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
*/
public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
- ISelectionChangedListener, IPostOperationEnabled{
+ ISelectionChangedListener, IPostOperationEnabled/*, ICdmEntitySessionEnabled*/{
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
+ 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 ConversationHolder conversation;
private TreeViewer viewer;
private DerivateSearchCompositeController derivateSearchCompositeController;
+ /**
+ * A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
+ * and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
+ */
+ private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
+
+ /**
+ * The set of root elements
+ */
+ private Set<SpecimenOrObservationBase<?>> rootElements;
+
/**
* Default constructor
*/
public DerivateView() {
+ conversation = CdmStore.createConversation();
}
@Override
Menu menu = menuManager.createContextMenu(control);
control.setMenu(menu);
+ //single read multi links
generateMultiLinkSingleReads();
labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
- IEditorInput editorInput = getEditorInput();
- viewer.setInput(((DerivateViewEditorInput) editorInput).getRootEntities());
- //set selection to selected derivate if only one was selected
- if(editorInput instanceof DerivateViewEditorInput){
- Set<SpecimenOrObservationBase<?>> derivateEntities = ((DerivateViewEditorInput) editorInput).getDerivateEntities();
- if(derivateEntities.size()==1){
- SpecimenOrObservationBase<?> specimen = derivateEntities.iterator().next();
- if(specimen != null){
- viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
- }
- }
+
+ //init tree
+ DerivateViewEditorInput editorInput = (DerivateViewEditorInput) getEditorInput();
+ if(editorInput.getDerivativeUUIDs()!=null){
+ updateRootEntities(editorInput.getDerivativeUUIDs());
+ }
+ else{
+ updateRootEntities();
}
//add drag'n'drop support
viewer.addDropSupport(dndOperations, transfers, new DerivateDropListener(this));
}
+ public void updateRootEntities() {
+ updateRootEntities(null);
+ }
+
+ public void updateRootEntities(Collection<UUID> derivativeUuids) {
+ if(derivativeUuids!=null){
+ this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+ this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+ for (UUID uuid : derivativeUuids) {
+ SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+ if(derivate instanceof FieldUnit){
+ derivateToRootEntityMap.put(derivate, derivate);
+ }
+ else {
+ SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+ if(topMostDerivate!=null){
+ derivateToRootEntityMap.put(derivate, topMostDerivate);
+ }
+ else{
+ derivateToRootEntityMap.put(derivate, derivate);
+ }
+ }
+ }
+ for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
+ rootElements.add(specimen);
+ }
+ }
+ viewer.setInput(rootElements);
+ refreshTree();
+ }
+
@Override
public void doSave(IProgressMonitor monitor) {
String taskName = Messages.DerivateView_SAVING_HIERARCHY;
// commit the conversation and start a new transaction immediately
conversation.commit(true);
- ((DerivateViewEditorInput) getEditorInput()).merge();
+// TODO: what does this do? merge();
monitor.worked(1);
this.setDirty(false);
public void doSaveAs() {
}
+ public Set<SpecimenOrObservationBase<?>> getRootElements() {
+ return rootElements;
+ }
+
@Override
public String getTitleToolTip() {
if(getEditorInput() instanceof DerivateViewEditorInput){
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
- if(input instanceof DerivateViewEditorInput){
- DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) input;
- conversation = derivateViewEditorInput.getConversationHolder();
- setPartName(derivateViewEditorInput.getName());
- }
+ this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+ this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
}
@Override
if(!conversation.isBound()){
conversation.bind();
}
- ((DerivateViewEditorInput) getEditorInput()).bind();
}
@Override
changed(null);
}
- protected void setRootEntities(Collection<UUID> rootEntityUuids){
- ((DerivateViewEditorInput)getEditorInput()).updateRootEntities(rootEntityUuids);
- }
+// @Override
+// public Set<SpecimenOrObservationBase<?>> getRootEntities() {
+// return rootElements;
+// }
+//
+// @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;
+// }
/**
* Refreshes the derivate hierarchy tree and expands the tree
//FIXME:Remoting hack to make this work for remoting
//This should actually be resolved using remoting post operations
public void remove(Object obj) {
- Set<SpecimenOrObservationBase<?>> rootEntities = ((DerivateViewEditorInput) getEditorInput()).getRootEntities();
- rootEntities.remove(obj);
- viewer.setInput(rootEntities);
+ rootElements.remove(obj);
+ viewer.setInput(rootElements);
}
private void generateMultiLinkSingleReads() {
return true;
}
- @Override
- public void dispose() {
- ((DerivateViewEditorInput) getEditorInput()).dispose();
- super.dispose();
- }
-
@Override
public boolean canAttachMedia() {
return true;
}
+
+ public void removeHierarchy(SpecimenOrObservationBase<?> specimenOrObservationBase) {
+ SpecimenOrObservationBase<?> rootElement = derivateToRootEntityMap.remove(specimenOrObservationBase);
+ rootElements.remove(rootElement);
+ }
+
+ public void addHierarchy(FieldUnit fieldUnit) {
+ rootElements.add(fieldUnit);
+ derivateToRootEntityMap.put(fieldUnit, fieldUnit);
+ }
+
+// @Override
+// public ICdmEntitySession getCdmEntitySession() {
+// return conversation;
+// }
}
*/
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;
- }
- }
-
}
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
FieldUnit fieldUnit = FieldUnit.NewInstance();
fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
derivateView.getConversationHolder().commit();
- DerivateViewEditorInput input = (DerivateViewEditorInput) derivateView.getEditorInput();
- input.addRootEntity(fieldUnit);
+ derivateView.addHierarchy(fieldUnit);
derivateView.refreshTree();
}
return null;
lblNewLabel.setText("Taxon assignment");
comboTaxonAssignment = new Combo(this, SWT.NONE);
- comboTaxonAssignment.setItems(new String[] { "Yes", "No", "All" });
+ comboTaxonAssignment.setItems(new String[] { "All", "Yes", "No" });
comboTaxonAssignment.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
formToolkit.adapt(comboTaxonAssignment);
formToolkit.paintBordersFor(comboTaxonAssignment);
}
//filter out (un-)assigned specimens
+ DerivateViewEditorInput editorInput = (DerivateViewEditorInput)derivativeEditor.getEditorInput();
int selectionIndex = derivateSearchComposite.getComboTaxonAssignment().getSelectionIndex();
- List<SpecimenOrObservationBase> specimensWithAssociations = new ArrayList<SpecimenOrObservationBase>();
+ List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<SpecimenOrObservationBase<?>>();
if(selectionIndex!=DerivateSearchComposite.ALL_SPECIMENS){
for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(specimenOrObservationBase, null, null, null, null);
if(!associatedTaxa.isEmpty()){
- specimensWithAssociations.add(specimenOrObservationBase);
+ specimenWithAssociations.add(specimenOrObservationBase);
}
}
}
- if(selectionIndex==DerivateSearchComposite.ASSIGNED_SPECIMENS){
- occurrences = specimensWithAssociations;
- }
- else if(selectionIndex==DerivateSearchComposite.UNASSIGNED_SPECIMENS){
- occurrences.retainAll(specimensWithAssociations);
+ if(selectionIndex==DerivateSearchComposite.UNASSIGNED_SPECIMENS){
+ for (SpecimenOrObservationBase<?> specimenOrObservationBase : specimenWithAssociations) {
+ derivativeEditor.removeHierarchy(specimenOrObservationBase);
+ }
+ derivativeEditor.updateRootEntities();
}
-
- List<UUID> derivateUuids = new ArrayList<UUID>();
- for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
- derivateUuids.add(specimenOrObservationBase.getUuid());
+ else{
+ if(selectionIndex==DerivateSearchComposite.ASSIGNED_SPECIMENS){
+ occurrences = new ArrayList<SpecimenOrObservationBase>(specimenWithAssociations);
+ }
+ List<UUID> derivateUuids = new ArrayList<UUID>();
+ for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
+ derivateUuids.add(specimenOrObservationBase.getUuid());
+ }
+ derivativeEditor.updateRootEntities(derivateUuids);
}
- //update tree
- DerivateViewEditorInput editorInput = (DerivateViewEditorInput)derivativeEditor.getEditorInput();
- editorInput.updateRootEntities(derivateUuids);
- derivativeEditor.getViewer().setInput(editorInput.getRootEntities());
- derivativeEditor.refreshTree();
}
@Override