-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.taxeditor.newWizard;
+import java.util.HashSet;
+import java.util.Set;
+
+import eu.etaxonomy.cdm.api.service.INameService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
-import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.HybridRelationship;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameWizardPage;
*/
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);
+ addPage(new TaxonWizardPage(formFactory, getConversationHolder(), getEntity()));
+ addPage(new NonViralNameWizardPage(formFactory, getConversationHolder(), getEntity().getName()));
}
/** {@inheritDoc} */
@Override
protected Taxon createNewEntity() {
- return Taxon.NewInstance(NonViralName.NewInstance(null), null);
+ return Taxon.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(ITaxonService.class).save(getEntity());
+// TODO: if new entity is an hybrid, the hybrid names should be saved first.. see newTaxonnodeWizard
+ Taxon taxon = getEntity();
+ if (!taxon.getName().getHybridChildRelations().isEmpty() || !taxon.getName().getHybridParentRelations().isEmpty()){
+ Set<TaxonName> namesToSave = new HashSet<>();
+ for (HybridRelationship hybridRelationship: taxon.getName().getHybridChildRelations()){
+ if (hybridRelationship.getParentName() != taxon.getName()){
+ if (!hybridRelationship.getParentName().isPersited()){
+ namesToSave.add(hybridRelationship.getParentName());
+ }
+ }else if (hybridRelationship.getHybridName() != taxon.getName()){
+ if (!hybridRelationship.getHybridName().isPersited()){
+ namesToSave.add(hybridRelationship.getHybridName());
+ }
+ }
+
+ }
+
+ for (HybridRelationship hybridRelationship: taxon.getName().getHybridParentRelations()){
+ if (hybridRelationship.getParentName() != taxon.getName()){
+ if (!hybridRelationship.getParentName().isPersited()){
+ namesToSave.add(hybridRelationship.getParentName());
+ }
+ }else if (hybridRelationship.getHybridName() != taxon.getName()){
+ if (!hybridRelationship.getHybridName().isPersited()){
+ namesToSave.add(hybridRelationship.getHybridName());
+ }
+ }
+
+ }
+ CdmStore.getService(INameService.class).save(namesToSave);
+ }
+ CdmStore.getService(ITaxonService.class).save(taxon);
}
/** {@inheritDoc} */