forgot to add new abstract class AbstractEditWizard
authorKatja Luther <k.luther@bgbm.org>
Wed, 23 Mar 2016 12:57:33 +0000 (13:57 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 23 Mar 2016 12:57:33 +0000 (13:57 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java [new file with mode: 0644]

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 (file)
index 0000000..e5a42f6
--- /dev/null
@@ -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<T> extends Wizard implements
+INewWizard, IConversationEnabled{
+
+    private ConversationHolder conversation;
+
+    protected CdmFormFactory formFactory;
+
+    private T entity;
+
+    private IWorkbench workbench;
+
+
+
+        /**
+         * <p>Constructor for AbstractNewEntityWizard.</p>
+         *
+         * @param <T> 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;
+        }
+
+        /**
+         * <p>Getter for the field <code>entity</code>.</p>
+         *
+         * @return a T object.
+         */
+        public T getEntity() {
+            return entity;
+        }
+
+        /**
+         * <p>Setter for the field <code>entity</code>.</p>
+         *
+         * @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();
+
+
+        }
+
+
+
+        /**
+         * <p>getConversationHolder</p>
+         *
+         * @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;
+        }
+
+
+
+}