import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
-import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
open(input);
}
+ public static SpecimenOrObservationBase getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
+ if(specimen==null) {
+ return null;
+ }
+ if(specimen.isInstanceOf(FieldUnit.class)){
+ return specimen;
+ }
+ else if(specimen instanceof DerivedUnit){
+ if(((DerivedUnit) specimen).getOriginals()==null || ((DerivedUnit) specimen).getOriginals().isEmpty()){
+ return specimen;
+ }
+ else{
+ for(SpecimenOrObservationBase original:((DerivedUnit) specimen).getOriginals()){
+ return getTopMostDerivate(original);
+ }
+ }
+ }
+ return null;
+ }
+
public static FieldUnit getFieldUnit(SpecimenOrObservationBase<?> specimen){
- if(specimen==null) {
- return null;
- }
- if(specimen.isInstanceOf(FieldUnit.class)){
- return (FieldUnit) specimen;
- }
- else if(specimen instanceof DerivedUnit && ((DerivedUnit) specimen).getOriginals()!=null){
- for(SpecimenOrObservationBase original:((DerivedUnit) specimen).getOriginals()){
- if(original.isInstanceOf(FieldUnit.class)){
- return (FieldUnit) original;
- }
- else if(original.isInstanceOf(DerivedUnit.class)){
- return getFieldUnit(original);
- }
- }
+ SpecimenOrObservationBase topMostDerivate = getTopMostDerivate(specimen);
+ if(topMostDerivate instanceof FieldUnit) {
+ return (FieldUnit) topMostDerivate;
}
return null;
}
createMenuItem(menu, "DNA Sample", derivedUnit, DnaSample.class, SpecimenOrObservationType.DnaSample);
createMenuItem(menu, "Specimen Scan", derivedUnit, MediaSpecimen.class, SpecimenOrObservationType.StillImage);
createMenuItem(menu, "Artwork", derivedUnit, MediaSpecimen.class, SpecimenOrObservationType.StillImage);
- createMenuItem(menu, "Living Plant Photo", derivedUnit, DerivedUnit.class, SpecimenOrObservationType.StillImage);
+ createMenuItem(menu, "Living Plant Photo", derivedUnit, MediaSpecimen.class, SpecimenOrObservationType.StillImage);
}
//context menu for DnaSample
else if(selectedElement instanceof DnaSample){
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.AbstractUtility;
public class DerivateContentProvider implements ITreeContentProvider {
@Override
public Object[] getElements(Object inputElement) {
- SpecimenOrObservationBase<?> specimen = null;
+ SpecimenOrObservationBase specimen = null;
if(inputElement instanceof DerivateViewEditorInput){
- inputElement = ((DerivateViewEditorInput) inputElement).getDerivate();
+ specimen = ((DerivateViewEditorInput) inputElement).getDerivate();
}
- // return the parent FieldUnit if element is a DerivedUnit
- if(inputElement instanceof DerivedUnit){
- specimen = EditorUtil.getFieldUnit((DerivedUnit)inputElement);
- }
- else if(inputElement instanceof FieldUnit){
- specimen = (FieldUnit) inputElement;
- }
- else{
- AbstractUtility.error(DerivateContentProvider.class, "Invalid input of type " + inputElement.getClass(), new UnsupportedOperationException());
- }
+ specimen = EditorUtil.getTopMostDerivate(specimen);
+
if(specimen!=null){
return Collections.singleton(specimen).toArray();
}
else {
- return Collections.EMPTY_LIST.toArray();
+ //show topmost element in the derivate hierarchy if no field unit was found
+ return Collections.singleton(specimen).toArray();
}
}
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-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.model.IDirtyMarkableSelectionProvider;
viewer.setInput(editorInput);
if(editorInput instanceof DerivateViewEditorInput){
SpecimenOrObservationBase<?> specimen = ((DerivateViewEditorInput) editorInput).getDerivate();
- FieldUnit fieldUnit = ((DerivateViewEditorInput) editorInput).getFieldUnit();
- setPartName(fieldUnit.toString());
+ SpecimenOrObservationBase rootElement = ((DerivateViewEditorInput) editorInput).getRootElement();
+ setPartName(rootElement.toString());
viewer.setSelection(new StructuredSelection(specimen));
}
}
*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
-import java.util.Collection;
import java.util.UUID;
import org.eclipse.jface.resource.ImageDescriptor;
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.AbstractUtility;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* Editor input for the {@link DerivateView} which holds the currently selected derivate for which
* the derivate hierarchy should be shown in the DerivateView.<br>
- * It also holds a {@link FieldUnit} which is the root of the hierarchy. (both may be the same object)
+ * It also holds a {@link SpecimenOrObservationBase} which is the root of the hierarchy. (both may be the same object)
* @author pplitzner
* @date 25.11.2013
*
/**
* The root of the hierarchy (may be the same object as the derivate)
*/
- private FieldUnit fieldUnit;
+ private SpecimenOrObservationBase<?> root;
- private ConversationHolder conversationHolder;
+ 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 fieldUnit the root of the hierarchy
+ * @param root the root of the hierarchy
*/
public DerivateViewEditorInput(UUID derivateUuid) {
super();
this.conversationHolder = CdmStore.createConversation();
this.derivate = CdmStore.getCurrentApplicationConfiguration().getOccurrenceService().load(derivateUuid);
if(derivate instanceof FieldUnit){
- this.fieldUnit = (FieldUnit) derivate;
+ this.root = derivate;
}
else if(derivate instanceof DerivedUnit){
- Collection<FieldUnit> fieldUnits = CdmStore.getCurrentApplicationConfiguration().getOccurrenceService().getFieldUnits(derivateUuid);
- if(!fieldUnits.isEmpty()){
- // TODO think about handling multiple parent FieldUnits
- this.fieldUnit = fieldUnits.iterator().next();
+ root = EditorUtil.getTopMostDerivate(derivate);
+ if(root==null){
+ root = derivate;
}
}
- if(fieldUnit==null){
- AbstractUtility.errorDialog("Failed initializing editor", DerivateViewEditorInput.class, "No FieldUnit found!");
+ if(root==null){
+ AbstractUtility.errorDialog("Failed initializing editor", DerivateViewEditorInput.class, "No root element found!");
}
}
/**
* @return the fieldUnit
*/
- public FieldUnit getFieldUnit() {
- return fieldUnit;
+ public SpecimenOrObservationBase<?> getRootElement() {
+ return root;
}
/**
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((fieldUnit == null) ? 0 : fieldUnit.hashCode());
+ result = prime * result + ((root == null) ? 0 : root.hashCode());
return result;
}
return false;
}
DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
- if (fieldUnit == null) {
- if (other.fieldUnit != null) {
+ if (root == null) {
+ if (other.root != null) {
return false;
}
- } else if (!fieldUnit.equals(other.fieldUnit)) {
+ } else if (!root.equals(other.root)) {
return false;
}
return true;
try {
if(getEntity() instanceof DerivedUnit) {
facade = DerivedUnitFacade.NewInstance((DerivedUnit)getEntity(), PreferencesUtil.getDerivedUnitConfigurator());
- facade.getFieldUnit(true); //TODO: this is a temporary solution for the Campanula project as
- //this ALWAYS needs a FieldUnit as root of the hierarchy
-
addPage(new DerivedUnitGeneralWizardPage(formFactory, getConversationHolder(), facade));
addPage(new GatheringEventWizardPage(formFactory, getConversationHolder(), facade));
addPage(new FieldUnitWizardPage(formFactory, getConversationHolder(), facade));
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
-import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
*/
@Override
public void setInput(Object input) {
- if (input instanceof DerivedUnit) {
+ if (input.getClass().equals(DerivedUnit.class)) {
DerivedUnit derivedUnit = (DerivedUnit)input;
- if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.BULK_EDITOR_AVOID_FACADE)){
- try {
- input = DerivedUnitFacade.NewInstance(derivedUnit,
- PreferencesUtil.getDerivedUnitConfigurator());
- } catch (DerivedUnitFacadeNotSupportedException e) {
- AbstractUtility.error(getClass(), e);
- }
+ try {
+ input = DerivedUnitFacade.NewInstance(derivedUnit,
+ PreferencesUtil.getDerivedUnitConfigurator());
+ } catch (DerivedUnitFacadeNotSupportedException e) {
+ AbstractUtility.error(getClass(), e);
}
}
else if(input instanceof FieldUnit){