--- /dev/null
+/**
+* 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 org.eclipse.e4.ui.workbench.IWorkbench;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+
+/**
+ *
+ * @author n.hoffmann
+ * @created Jun 1, 2010
+ * @version 1.0
+ */
+public abstract class AbstractNewEntityWizardParentChild<T> extends Wizard implements
+ IConversationEnabled {
+
+ private ConversationHolder conversation;
+
+ protected CdmFormFactory formFactory;
+
+ private T parentEntity;
+ private T entity;
+ private boolean finished = false;
+
+
+ private IStructuredSelection selection;
+
+ public AbstractNewEntityWizardParentChild(){
+ setWindowTitle(String.format("New %s", getEntityName()));
+ }
+
+ /**
+ * FIXME there might be a smarter way to do this,
+ *
+ * @return
+ */
+ protected abstract String getEntityName();
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean performFinish() {
+ if (finished){
+ return true;
+ }
+ saveEntity();
+
+ conversation.commit();
+ conversation.close();
+ conversation = null;
+
+ finished = true;
+ return true;
+ }
+
+ public T getParentEntity() {
+ return parentEntity;
+ }
+
+ public void setParentEntity(T entity){
+ this.parentEntity = entity;
+ }
+
+ public T getEntity() {
+ return entity;
+ }
+
+ public void setEntity(T entity){
+ this.entity = entity;
+ }
+
+
+ /**
+ * Adds the entity to the current persistence context
+ */
+ protected abstract void saveEntity();
+
+ /** {@inheritDoc} */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ formFactory = new CdmFormFactory(Display.getCurrent(), null);
+ conversation = CdmStore.createConversation();
+ this.selection = selection;
+
+ createParentEntity();
+
+
+ }
+
+
+
+ protected abstract void createParentEntity();
+
+ @Override
+ public ConversationHolder getConversationHolder() {
+ return conversation;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {}
+
+ public IStructuredSelection getSelection() {
+ return selection;
+ }
+}