-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.taxeditor.ui.selection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
+import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.agent.Institution;
import eu.etaxonomy.cdm.model.agent.Person;
import eu.etaxonomy.cdm.model.agent.Team;
-import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.User;
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
import eu.etaxonomy.cdm.model.molecular.Amplification;
import eu.etaxonomy.cdm.model.molecular.Primer;
-import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.TaxonName;
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.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.model.TextHelper;
-import eu.etaxonomy.taxeditor.newWizard.AmplificationCloningWizardPage;
-import eu.etaxonomy.taxeditor.newWizard.AmplificationGelPhotoWizardPage;
import eu.etaxonomy.taxeditor.newWizard.AmplificationGeneralWizardPage;
-import eu.etaxonomy.taxeditor.newWizard.AmplificationPrimerWizardPage;
+import eu.etaxonomy.taxeditor.newWizard.PolytomousKeyWizardPage;
import eu.etaxonomy.taxeditor.newWizard.PrimerWizardPage;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionWizardPage;
import eu.etaxonomy.taxeditor.ui.section.agent.PersonWizardPage;
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitWizardPage;
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonWizardPage;
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailWizardPage;
/**
- * <p>
- * EditFromSelectionWizard class.
- * </p>
- *
* @author n.hoffmann
* @created Jun 1, 2010
* @version 1.0
*/
public class EditFromSelectionWizard extends Wizard implements
- SelectionListener {
+ SelectionListener, ICdmEntitySessionEnabled {
+ private ICdmEntitySession cdmEntitySession;
+ private ICdmEntitySession previousCdmEntitySession;
private final EntitySelectionElement selectionElement;
+ private CdmBase rootElement;
- /**
- * <p>
- * Constructor for EditFromSelectionWizard.
- * </p>
- *
- * @param selectionElement
- * a
- * {@link eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement}
- * object.
- */
public EditFromSelectionWizard(EntitySelectionElement selectionElement) {
+ if (CdmStore.isActive()) {
+ previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ cdmEntitySession.bind();
+ }
this.selectionElement = selectionElement;
this.setWindowTitle(String.format("Edit %s", TextHelper.deproxyClassName(selectionElement.getEntity().getClass())));
}
public void addPages() {
CdmFormFactory formFactory = selectionElement.getFormFactory();
- ICdmBase entity = (ICdmBase) HibernateProxyHelper
+ CdmBase entity = HibernateProxyHelper
.deproxy(selectionElement.getEntity());
-
- if (entity instanceof Reference) {
+ //check if entity has already been persisted
+ if(entity.getId()==0){
+ rootElement = entity;
+ }
+ else{
+ IService<CdmBase> service = CdmStore.getService(entity);
+ rootElement = service.load(entity.getUuid());
+ }
+ if (rootElement.isInstanceOf(Reference.class)) {
addPage(new ReferenceWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Reference) entity));
- } else if (entity instanceof Team) {
+ (HibernateProxyHelper.deproxy(rootElement, Reference.class))));
+ } else if (rootElement.isInstanceOf(Team.class) && selectionElement instanceof EntitySelectionElementWithAbbreviatedTitle<?>) {
addPage(new TeamWizardPage(formFactory,
- selectionElement.getConversationHolder(), (Team) entity));
- } else if (entity instanceof Person) {
+ selectionElement.getConversationHolder(), HibernateProxyHelper.deproxy(rootElement, Team.class), true));
+ } else if (rootElement.isInstanceOf(Team.class) && !(selectionElement instanceof EntitySelectionElementWithAbbreviatedTitle<?>)) {
+ addPage(new TeamWizardPage(formFactory,
+ selectionElement.getConversationHolder(), HibernateProxyHelper.deproxy(rootElement, Team.class), false));
+ } else if (rootElement.isInstanceOf(Person.class)) {
addPage(new PersonWizardPage(formFactory,
- selectionElement.getConversationHolder(), (Person) entity));
- } else if (entity instanceof NonViralName) {
+ selectionElement.getConversationHolder(), HibernateProxyHelper.deproxy(rootElement, Person.class)));
+ } else if (rootElement.isInstanceOf(TaxonName.class)) {
addPage(new NonViralNameWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (NonViralName) entity));
- } else if (entity instanceof DerivedUnit) {
+ HibernateProxyHelper.deproxy(rootElement, TaxonName.class)));
+ } else if (rootElement.isInstanceOf(TaxonBase.class)) {
+ addPage(new TaxonWizardPage(formFactory,
+ selectionElement.getConversationHolder(),
+ HibernateProxyHelper.deproxy(rootElement, TaxonBase.class)));
+ } else if (rootElement.isInstanceOf(SpecimenOrObservationBase.class)) {
DerivedUnitFacade facade;
try {
- facade = DerivedUnitFacade.NewInstance(
- (DerivedUnit) entity,
- PreferencesUtil.getDerivedUnitConfigurator());
+ if(rootElement.isInstanceOf(DerivedUnit.class)){
+ facade = DerivedUnitFacade.NewInstance(
+ HibernateProxyHelper.deproxy(rootElement, DerivedUnit.class),
+ PreferencesUtil.getDerivedUnitConfigurator());
+ }
+ else {
+ facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.FieldUnit,
+ HibernateProxyHelper.deproxy(rootElement, FieldUnit.class),
+ PreferencesUtil.getDerivedUnitConfigurator());
+ }
+
} catch (DerivedUnitFacadeNotSupportedException e) {
// we should never get here
throw new IllegalStateException();
selectionElement.getConversationHolder(), facade));
addPage(new FieldUnitWizardPage(formFactory,
selectionElement.getConversationHolder(), facade));
- addPage(new DerivedUnitBaseWizardPage(formFactory,
- selectionElement.getConversationHolder(), facade));
- } else if (entity instanceof Collection) {
+ if(facade.innerDerivedUnit()!=null){
+ addPage(new DerivedUnitBaseWizardPage(formFactory,
+ selectionElement.getConversationHolder(), facade));
+ }
+ } else if (rootElement.isInstanceOf(Collection.class)) {
addPage(new CollectionWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Collection) entity));
- } else if (entity instanceof Institution) {
+ HibernateProxyHelper.deproxy(rootElement, Collection.class)));
+ } else if (rootElement instanceof Institution) {
addPage(new InstitutionWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Institution) entity));
- } else if (entity instanceof User) {
+ HibernateProxyHelper.deproxy(rootElement, Institution.class)));
+ } else if (rootElement instanceof User) {
addPage(new UserDetailWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (User) entity));
- } else if (entity instanceof Primer) {
+ HibernateProxyHelper.deproxy(rootElement, User.class)));
+ } else if (rootElement instanceof Primer) {
addPage(new PrimerWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Primer) entity));
- } else if (entity instanceof Amplification) {
+ HibernateProxyHelper.deproxy(rootElement, Primer.class)));
+ } else if (rootElement instanceof Amplification) {
addPage(new AmplificationGeneralWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Amplification) entity));
- addPage(new AmplificationPrimerWizardPage(formFactory,
+ HibernateProxyHelper.deproxy(rootElement, Amplification.class)));
+ } else if (rootElement instanceof PolytomousKey) {
+ addPage(new PolytomousKeyWizardPage(formFactory,
selectionElement.getConversationHolder(),
- (Amplification) entity));
- addPage(new AmplificationCloningWizardPage(formFactory,
- selectionElement.getConversationHolder(),
- (Amplification) entity));
- addPage(new AmplificationGelPhotoWizardPage(formFactory,
- selectionElement.getConversationHolder(),
- (Amplification) entity));
+ HibernateProxyHelper.deproxy(rootElement, PolytomousKey.class)));
} else {
MessagingUtils.warningDialog("Missing interface", this,
"No detail element for current selection");
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.wizard.Wizard#performFinish()
- */
/** {@inheritDoc} */
@Override
public boolean performFinish() {
+ IService<CdmBase> service = CdmStore.getService(rootElement);
+ if(rootElement.getId()!=0){
+ service.merge(rootElement, true);
+
+ }else{
+ rootElement = service.save(rootElement);
+ }
+ if(previousCdmEntitySession!=null){
+ selectionElement.setEntity(previousCdmEntitySession.load(rootElement, true));
+ }
+
return true;
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ if(cdmEntitySession != null) {
+ cdmEntitySession.dispose();
+ cdmEntitySession = null;
+ }
+ if(previousCdmEntitySession!=null){
+ previousCdmEntitySession.bind();
+ }
+ }
+
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ return cdmEntitySession;
+ }
+
+ @Override
+ public java.util.Collection<CdmBase> getRootEntities() {
+ return Collections.singleton(rootElement);
+ }
+
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ return null;
+ }
}