Add support for generic SpecimenOrObservationBase class to
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Oct 2015 13:13:32 +0000 (14:13 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Oct 2015 13:13:32 +0000 (14:13 +0100)
EntitySelectionElement and selection wizard

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SpecimenOrObservationBaseSelectionDialog.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/detail/IndividualsAssociationDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EditFromSelectionWizard.java

index f6752d97249a171a4889be32dccbf539e6062731..a90ce1c9bca1c861a41b1d44c3dcd2411259cd3b 100644 (file)
@@ -34,6 +34,7 @@ import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.occurrence.Collection;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
@@ -103,10 +104,13 @@ public class SelectionDialogFactory {
                        return null;
                }
                if(clazz.equals(DerivedUnit.class)){
-                       return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
+                   return (T) DerivedUnitSelectionDialog.select(shell, conversation, (DerivedUnit) currentSelection);
                }
                if(clazz.equals(FieldUnit.class)){
-                       return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
+                   return (T) FieldUnitSelectionDialog.select(shell, conversation, (FieldUnit) currentSelection);
+               }
+               if(clazz.equals(SpecimenOrObservationBase.class)){
+                   return (T) SpecimenOrObservationBaseSelectionDialog.select(shell, conversation, (SpecimenOrObservationBase) currentSelection);
                }
                if(clazz.equals(NamedArea.class)){
                    if(parentElement instanceof IEntityElement && ((IEntityElement) parentElement).getEntity() instanceof DerivedUnitFacade){
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SpecimenOrObservationBaseSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SpecimenOrObservationBaseSelectionDialog.java
new file mode 100644 (file)
index 0000000..589b084
--- /dev/null
@@ -0,0 +1,67 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.ui.dialog.selection;
+
+import java.util.UUID;
+
+import org.eclipse.swt.widgets.Shell;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
+import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author pplitzner
+ */
+public class SpecimenOrObservationBaseSelectionDialog extends
+               AbstractFilteredCdmResourceSelectionDialog<SpecimenOrObservationBase> {
+
+       public static SpecimenOrObservationBase select(Shell shell, ConversationHolder conversation, SpecimenOrObservationBase observation){
+               SpecimenOrObservationBaseSelectionDialog dialog = new SpecimenOrObservationBaseSelectionDialog(shell, conversation,
+                               "Choose field unit or derived unit", false, SpecimenOrObservationBaseSelectionDialog.class.getCanonicalName(), observation);
+               return getSelectionFromDialog(dialog);
+       }
+
+       protected SpecimenOrObservationBaseSelectionDialog(Shell shell, ConversationHolder conversation,
+                       String title, boolean multi, String settings,
+                       SpecimenOrObservationBase cdmObject) {
+               super(shell, conversation, title, multi, settings, cdmObject);
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected SpecimenOrObservationBase getPersistentObject(UUID uuid) {
+               Object object = CdmStore.getService(IOccurrenceService.class).load(uuid);
+               return HibernateProxyHelper.deproxy(object, SpecimenOrObservationBase.class);
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected void initModel() {
+               model = CdmStore.getService(IOccurrenceService.class).getUuidAndTitleCache();
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
+               return new NewDerivedUnitBaseWizard();
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected String getNewWizardLinkText() {
+               return String.format("Create a new <a>%1s</a>", "field unit/derived unit");
+       }
+}
index acfbf7c6dda406f8ac26826c8b90e1e1699e6064..b91fc58b7bc037b84d94919a443388e633e10669 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -16,7 +16,7 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -24,10 +24,6 @@ import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
- * <p>
- * IndividualsAssociationDetailElement class.
- * </p>
- * 
  * @author n.hoffmann
  * @created Jun 10, 2010
  * @version 1.0
@@ -36,26 +32,8 @@ public class IndividualsAssociationDetailElement extends
                AbstractDetailedDescriptionDetailElement<IndividualsAssociation> {
 
        private TextWithLabelElement text_description;
-       private EntitySelectionElement<DerivedUnit> selection_derivedUnit;
+       private EntitySelectionElement<SpecimenOrObservationBase> selection_derivedUnit;
 
-       /**
-        * <p>
-        * Constructor for IndividualsAssociationDetailElement.
-        * </p>
-        * 
-        * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-        *            object.
-        * @param formElement
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
-        *            object.
-        * @param entity
-        *            a
-        *            {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation}
-        *            object.
-        * @param style
-        *            a int.
-        */
        public IndividualsAssociationDetailElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement, IndividualsAssociation entity,
                        int style) {
@@ -67,9 +45,9 @@ public class IndividualsAssociationDetailElement extends
        protected void createControls(ICdmFormElement formElement,
                        IndividualsAssociation entity, int style) {
                selection_derivedUnit = formFactory
-                               .createSelectionElement(DerivedUnit.class,
-                                               getConversationHolder(), formElement, "Unit",
-                                               CdmBase.deproxy(entity.getAssociatedSpecimenOrObservation(),DerivedUnit.class),
+                               .createSelectionElement(SpecimenOrObservationBase.class,
+                                               getConversationHolder(), formElement, "Occurrence/Unit",
+                                               CdmBase.deproxy(entity.getAssociatedSpecimenOrObservation(),SpecimenOrObservationBase.class),
                                                EntitySelectionElement.ALL, style);
 
                text_description = formFactory.createMultiLineTextWithLabel(
index a9175681804242fd4de0d0f0ebc5b5ffc80ca804..22d5dd7a3972bc36b728f15cf3111bc1a50218bb 100644 (file)
@@ -30,6 +30,9 @@ import eu.etaxonomy.cdm.model.molecular.Primer;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.occurrence.Collection;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
@@ -102,13 +105,21 @@ public class EditFromSelectionWizard extends Wizard implements
                        addPage(new NonViralNameWizardPage(formFactory,
                                        selectionElement.getConversationHolder(),
                                        (NonViralName) entity));
-               } else if (entity instanceof DerivedUnit) {
+               } else if (entity instanceof SpecimenOrObservationBase) {
 
                        DerivedUnitFacade facade;
                        try {
-                               facade = DerivedUnitFacade.NewInstance(
-                                               (DerivedUnit) entity,
-                                               PreferencesUtil.getDerivedUnitConfigurator());
+                           if(((SpecimenOrObservationBase) entity).isInstanceOf(DerivedUnit.class)){
+                               facade = DerivedUnitFacade.NewInstance(
+                                       HibernateProxyHelper.deproxy(entity, DerivedUnit.class),
+                                       PreferencesUtil.getDerivedUnitConfigurator());
+                           }
+                           else {
+                    facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit,
+                            HibernateProxyHelper.deproxy(entity, FieldUnit.class),
+                            PreferencesUtil.getDerivedUnitConfigurator());
+                           }
+
                        } catch (DerivedUnitFacadeNotSupportedException e) {
                                // we should never get here
                                throw new IllegalStateException();
@@ -120,8 +131,10 @@ public class EditFromSelectionWizard extends Wizard implements
                                        selectionElement.getConversationHolder(), facade));
                        addPage(new FieldUnitWizardPage(formFactory,
                                        selectionElement.getConversationHolder(), facade));
-                       addPage(new DerivedUnitBaseWizardPage(formFactory,
-                                       selectionElement.getConversationHolder(), facade));
+                       if(facade.innerDerivedUnit()!=null){
+                           addPage(new DerivedUnitBaseWizardPage(formFactory,
+                                   selectionElement.getConversationHolder(), facade));
+                       }
                } else if (entity instanceof Collection) {
                        addPage(new CollectionWizardPage(formFactory,
                                        selectionElement.getConversationHolder(),