Use wizard to create new specimen
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Sep 2015 12:50:49 +0000 (14:50 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 14 Sep 2015 12:50:49 +0000 (14:50 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/create/NewSpecimenHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DerivedUnitGeneralDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DerivedUnitGeneralWizardPage.java

index 7760df8..f434a3b 100644 (file)
 
 package eu.etaxonomy.taxeditor.editor.handler.create;
 
-import java.util.Collections;
-
 import org.apache.log4j.Logger;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.PartInitException;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.handlers.HandlerUtil;
 
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeFieldUnitCacheStrategy;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
-import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard;
 
 /**
  * @author n.hoffmann
@@ -43,27 +31,28 @@ public class NewSpecimenHandler extends AbstractHandler {
        /** {@inheritDoc} */
        @Override
     public Object execute(ExecutionEvent event) throws ExecutionException {
-           ConversationHolder conversation = CdmStore.createConversation();
-           conversation.bind();
-           FieldUnit fieldUnit = FieldUnit.NewInstance();
-           DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
-           DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.GATHERING_IN_SITU());
-           fieldUnit.setCacheStrategy(new DerivedUnitFacadeFieldUnitCacheStrategy());
-           derivedUnit.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
-        CdmStore.getService(IOccurrenceService.class).save(fieldUnit);
-        CdmStore.getService(IOccurrenceService.class).save(derivedUnit);
-        conversation.commit();
-        DerivateViewEditorInput input = new DerivateViewEditorInput(Collections.singleton(fieldUnit.getUuid()));
-        try {
-            EditorUtil.open(input);
-        } catch (PartInitException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-//             NewDerivedUnitBaseWizard wizard = new NewDerivedUnitBaseWizard();
-//             wizard.init(null, null);
-//             WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
-//             dialog.open();
+           //TODO: we need to discuss how specimens should be created and handled #5244
+//         ConversationHolder conversation = CdmStore.createConversation();
+//         conversation.bind();
+//         FieldUnit fieldUnit = FieldUnit.NewInstance();
+//         DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
+//         DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.GATHERING_IN_SITU());
+//         fieldUnit.setCacheStrategy(new DerivedUnitFacadeFieldUnitCacheStrategy());
+//         derivedUnit.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
+//        CdmStore.getService(IOccurrenceService.class).save(fieldUnit);
+//        CdmStore.getService(IOccurrenceService.class).save(derivedUnit);
+//        conversation.commit();
+//        DerivateViewEditorInput input = new DerivateViewEditorInput(Collections.singleton(fieldUnit.getUuid()));
+//        try {
+//            EditorUtil.open(input);
+//        } catch (PartInitException e) {
+//            // TODO Auto-generated catch block
+//            e.printStackTrace();
+//        }
+               NewDerivedUnitBaseWizard wizard = new NewDerivedUnitBaseWizard();
+               wizard.init(null, null);
+               WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
+               dialog.open();
                return null;
        }
 }
index 1ac5b58..e8d7739 100644 (file)
@@ -45,6 +45,8 @@ public class DerivedUnitGeneralDetailElement extends
                AbstractCdmDetailElement<DerivedUnitFacade> {
 
     boolean showOnlyDerivedUnitData = false;
+    //TODO: flag to disable specimen type dropdown (#5244)
+    boolean showSpecimenType = true;
 
        private ToggleableTextElement toggleableText_titleCache;
        private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
@@ -71,13 +73,6 @@ public class DerivedUnitGeneralDetailElement extends
            super(formFactory, formElement);
        }
 
-       /*
-        * (non-Javadoc)
-        *
-        * @see
-        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
-        * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
-        */
        @Override
        protected void createControls(ICdmFormElement formElement,
                        DerivedUnitFacade entity, int style) {
@@ -91,6 +86,7 @@ public class DerivedUnitGeneralDetailElement extends
                else{
                    combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
                    combo_specorobstype.setSelection(entity.getType());
+                   combo_specorobstype.setEnabled(showSpecimenType);
                    selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(),
                            formElement, "Country",
                            entity.getCountry(), EntitySelectionElement.NOTHING, style);
@@ -130,13 +126,6 @@ public class DerivedUnitGeneralDetailElement extends
 
        }
 
-       /*
-        * (non-Javadoc)
-        *
-        * @see
-        * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
-        * .lang.Object)
-        */
        @Override
        public void handleEvent(Object eventSource) {
                if (eventSource == toggleableText_titleCache) {
@@ -177,4 +166,8 @@ public class DerivedUnitGeneralDetailElement extends
         this.showOnlyDerivedUnitData = showOnlyDerivedUnitData;
     }
 
+    public void setShowSpecimenType(boolean showSpecimenType) {
+        this.showSpecimenType = showSpecimenType;
+    }
+
 }
index 4d0bfc6..8db53ce 100644 (file)
@@ -38,6 +38,7 @@ public class DerivedUnitGeneralWizardPage extends AbstractCdmEntityWizardPage<De
        @Override
        public AbstractCdmDetailElement<DerivedUnitFacade> createElement(ICdmFormElement rootElement) {
                DerivedUnitGeneralDetailElement detailElement = formFactory.createDerivedUnitGeneralDetailElement(rootElement);
+               detailElement.setShowSpecimenType(false);
                detailElement.setEntity(getEntity());
                checkComplete();
                return detailElement;