Allow creating new taxa in taxon selection dialog #2402
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 19 Jan 2016 07:02:49 +0000 (08:02 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 19 Jan 2016 12:35:47 +0000 (13:35 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/TaxonBaseSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractCdmEntityWizardPage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonWizardPage.java [new file with mode: 0644]

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonWizard.java
new file mode 100644 (file)
index 0000000..1947c45
--- /dev/null
@@ -0,0 +1,60 @@
+// $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.newWizard;
+
+import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonWizardPage;
+
+/**
+ *
+ * @author pplitzner
+ * @date Jan 18, 2016
+ *
+ */
+public class NewTaxonWizard extends AbstractNewEntityWizard<Taxon> {
+
+       private TaxonWizardPage taxonWizardPage;
+
+       /** {@inheritDoc} */
+       @Override
+       public void addPages() {
+           addPage(new NonViralNameWizardPage(formFactory, getConversationHolder(), (NonViralName) getEntity().getName()));
+               taxonWizardPage = new TaxonWizardPage(formFactory, getConversationHolder(), getEntity());
+               addPage(taxonWizardPage);
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected Taxon createNewEntity() {
+               return Taxon.NewInstance(NonViralName.NewInstance(null), null);
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected void saveEntity() {
+           CdmStore.getService(ITaxonService.class).save(getEntity());
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public void setEntity(Taxon entity) {
+               super.setEntity(entity);
+       }
+
+       @Override
+       protected String getEntityName() {
+               return "Taxon";
+       }
+}
index fba0ce6c3ee5ad90283aaea259c60e6070a82ad0..a22f14454b57b8fe06cad6624edb8ee1e1ce9153 100644 (file)
@@ -477,26 +477,27 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
                        @Override
                        public void widgetSelected(SelectionEvent e) {
 
-                               AbstractNewEntityWizard wizard = getNewEntityWizard(e.text);
-
-                               wizard.init(null, null);
-                               if(wizard.getEntity() != null) {
-                                       WizardDialog dialog = new WizardDialog(getShell(), wizard);
-                                       int status = dialog.open();
-
-                                       if (status == IStatus.OK) {
-
-                                               T entity = (T) wizard.getEntity();
-                                               model.add(new UuidAndTitleCache<T>(entity.getUuid(),
-                                                       entity.getId(),
-                                                       getTitle(entity)));
-                                               refresh();
-                                               setPattern(entity);
-                                               getConversationHolder().bind();
-                                       }
-                                       //FIXME : Need to make sure this is a stable fix (ticket 3822)
-                                       getConversationHolder().commit();
-                               }
+                           AbstractNewEntityWizard wizard = getNewEntityWizard(e.text);
+                           if(wizard!=null){
+                               wizard.init(null, null);
+                               if(wizard.getEntity() != null) {
+                                   WizardDialog dialog = new WizardDialog(getShell(), wizard);
+                                   int status = dialog.open();
+
+                                   if (status == IStatus.OK) {
+
+                                       T entity = (T) wizard.getEntity();
+                                       model.add(new UuidAndTitleCache<T>(entity.getUuid(),
+                                               entity.getId(),
+                                               getTitle(entity)));
+                                       refresh();
+                                       setPattern(entity);
+                                       getConversationHolder().bind();
+                                   }
+                                   //FIXME : Need to make sure this is a stable fix (ticket 3822)
+                                   getConversationHolder().commit();
+                               }
+                           }
                        }
                };
        }
index 93860909685b64708e50f515cf973e8c700b7062..a02f2c0e1d963681d507511e387ea2fe97dfd1d8 100644 (file)
@@ -12,8 +12,6 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
 import java.util.UUID;
 
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -22,6 +20,7 @@ import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
+import eu.etaxonomy.taxeditor.newWizard.NewTaxonWizard;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -34,7 +33,7 @@ public class TaxonBaseSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
     public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
         AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
-                "Choose a taxon", false, null, null);
+                "Choose a taxon/synonym", false, null, null);
         return getSelectionFromDialog(dialog);
     }
 
@@ -48,25 +47,19 @@ public class TaxonBaseSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
     public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
         AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
-                "Choose a taxon", false, null, null);
+                "Choose a synonym", false, null, null);
         return (Synonym) getSelectionFromDialog(dialog);
     }
 
     private final Class<? extends TaxonBase> clazz;
 
     protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
-        super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), taxon);
+        super(shell, conversation, title, multi, TaxonBaseSelectionDialog.class.getCanonicalName(), taxon);
         this.cdmBaseToBeFiltered = taxonToBeFiltered;
         this.clazz = clazz;
         initModel();
     }
 
-    /** {@inheritDoc} */
-    @Override
-    protected Control createExtendedContentArea(Composite parent) {
-        return null;
-    }
-
     /** {@inheritDoc} */
     @Override
     protected TaxonBase getPersistentObject(UUID uuid) {
@@ -90,12 +83,12 @@ public class TaxonBaseSelectionDialog extends AbstractFilteredCdmResourceSelecti
     /** {@inheritDoc} */
     @Override
     protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
-        return null;
+        return new NewTaxonWizard();
     }
 
     /** {@inheritDoc} */
     @Override
     protected String getNewWizardLinkText() {
-        return null;
+        return String.format("Create a new <a>%1s</a>", "Taxon ");
     }
 }
index e04928fa8f31ed0575a4354fd6857df368c54c65..505a653a2f701fb19b4a378dbb5413ea58e52082 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.
  */
@@ -28,7 +28,7 @@ import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
  * <p>
  * Abstract AbstractCdmEntityWizardPage class.
  * </p>
- * 
+ *
  * @author n.hoffmann
  * @created Jun 1, 2010
  * @version 1.0
@@ -46,7 +46,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
         * <p>
         * Constructor for AbstractCdmEntityWizardPage.
         * </p>
-        * 
+        *
         * @param formFactory
         *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
         *            object.
@@ -82,7 +82,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
         * .Composite)
@@ -115,7 +115,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
         * <p>
         * Getter for the field <code>entity</code>.
         * </p>
-        * 
+        *
         * @return a T object.
         */
        public T getEntity() {
@@ -124,7 +124,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
 
        /**
         * Creates the detail element for this wizard page
-        * 
+        *
         * @param rootElement
         *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
         *            object.
@@ -169,6 +169,17 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
                if (event.getSource() == getDetailElement()) {
                        checkComplete();
                }
+               else if(event.getSource() instanceof AbstractCdmDetailElement){
+                   //check if parent element is set as detail element
+                   ICdmFormElement formElement = (ICdmFormElement) event.getSource();
+            while(formElement.getParentElement()!=null){
+                if(formElement.getParentElement() == getDetailElement()){
+                    checkComplete();
+                    return;
+                }
+                formElement = formElement.getParentElement();
+            }
+               }
        }
 
        /**
@@ -191,7 +202,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
         * <p>
         * getConversationHolder
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *         object.
         */
@@ -214,7 +225,7 @@ public abstract class AbstractCdmEntityWizardPage<T> extends WizardPage
         * <p>
         * Getter for the field <code>detailElement</code>.
         * </p>
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
         *         object.
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonWizardPage.java
new file mode 100644 (file)
index 0000000..fa6d9ec
--- /dev/null
@@ -0,0 +1,49 @@
+// $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.section.taxon;
+
+import org.eclipse.swt.SWT;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+
+/**
+ *
+ * @author pplitzner
+ * @date Jan 18, 2016
+ *
+ */
+public class TaxonWizardPage extends AbstractCdmEntityWizardPage<TaxonBase> {
+
+       public TaxonWizardPage(CdmFormFactory formFactory, ConversationHolder conversation,
+               TaxonBase entity) {
+               super(formFactory, conversation, entity);
+               setTitle("Taxon");
+       }
+
+
+       /** {@inheritDoc} */
+       @Override
+       public AbstractCdmDetailElement<TaxonBase> createElement(ICdmFormElement rootElement) {
+               TaxonBaseDetailElement taxonBaseDetailElement = formFactory.createTaxonBaseDetailElement(rootElement, SWT.NULL);
+               taxonBaseDetailElement.setEntity(entity);
+               return taxonBaseDetailElement;
+       }
+
+       @Override
+       public boolean isPageComplete() {
+           return true;
+       }
+}