From 757fd419e15351e50435ac7c48de7ee89c2916fb Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Wed, 23 Mar 2016 13:57:33 +0100 Subject: [PATCH] forgot to add new abstract class AbstractEditWizard --- .../classification/AbstractEditWizard.java | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java new file mode 100644 index 000000000..e5a42f6ec --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java @@ -0,0 +1,135 @@ +// $Id$ +/** +* Copyright (C) 2016 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.classification; + + +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + +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.model.AbstractUtility; +import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; +/** + * @author k.luther + * @date 23.03.2016 + * + */ +public abstract class AbstractEditWizard extends Wizard implements +INewWizard, IConversationEnabled{ + + private ConversationHolder conversation; + + protected CdmFormFactory formFactory; + + private T entity; + + private IWorkbench workbench; + + + + /** + *

Constructor for AbstractNewEntityWizard.

+ * + * @param a T object. + */ + public AbstractEditWizard(){ + setWindowTitle(String.format("New %s", getEntityName())); + } + + /** + * FIXME there might be a smarter way to do this, + * + * @return + */ + protected abstract String getEntityName(); + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + /** {@inheritDoc} */ + @Override + public boolean performFinish() { + saveEntity(); + + conversation.commit(); + conversation.close(); + return true; + } + + /** + *

Getter for the field entity.

+ * + * @return a T object. + */ + public T getEntity() { + return entity; + } + + /** + *

Setter for the field entity.

+ * + * @param entity a T object. + */ + public void setEntity(T entity){ + this.entity = entity; + } + + /** + * Adds the entity to the current persistence context + */ + protected abstract void saveEntity(); + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + /** {@inheritDoc} */ + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench(); + + + formFactory = new CdmFormFactory(Display.getCurrent(), null); + conversation = CdmStore.createConversation(); + + + } + + + + /** + *

getConversationHolder

+ * + * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + */ + @Override + public ConversationHolder getConversationHolder() { + return conversation; + } + + /** {@inheritDoc} */ + @Override + public void update(CdmDataChangeMap changeEvents) {} + + /** + * @return the workbench + */ + public IWorkbench getWorkbench() { + return workbench; + } + + + +} -- 2.34.1