3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.newWizard
;
13 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
14 import org
.eclipse
.jface
.wizard
.Wizard
;
15 import org
.eclipse
.swt
.widgets
.Display
;
16 import org
.eclipse
.ui
.INewWizard
;
17 import org
.eclipse
.ui
.ISelectionService
;
18 import org
.eclipse
.ui
.IWorkbench
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
22 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
23 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
24 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
29 * <p>Abstract AbstractNewEntityWizard class.</p>
32 * @created Jun 1, 2010
35 public abstract class AbstractNewEntityWizard
<T
> extends Wizard
implements
36 INewWizard
, IConversationEnabled
{
38 private ConversationHolder conversation
;
40 protected CdmFormFactory formFactory
;
44 private IWorkbench workbench
;
46 private IStructuredSelection selection
;
49 * <p>Constructor for AbstractNewEntityWizard.</p>
51 * @param <T> a T object.
53 public AbstractNewEntityWizard(){
54 setWindowTitle(String
.format("New %s", getEntityName()));
58 * FIXME there might be a smarter way to do this,
62 protected abstract String
getEntityName();
65 * @see org.eclipse.jface.wizard.Wizard#performFinish()
69 public boolean performFinish() {
72 conversation
.commit();
78 * <p>Getter for the field <code>entity</code>.</p>
82 public T
getEntity() {
87 * <p>Setter for the field <code>entity</code>.</p>
89 * @param entity a T object.
91 public void setEntity(T entity
){
96 * Adds the entity to the current persistence context
98 protected abstract void saveEntity();
101 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
105 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
106 this.workbench
= workbench
!= null ? workbench
: AbstractUtility
.getWorkbench();
108 if(selection
== null){
109 ISelectionService service
= this.workbench
.getActiveWorkbenchWindow().getSelectionService();
110 if(service
.getSelection() instanceof IStructuredSelection
){
111 selection
= (IStructuredSelection
) service
.getSelection();
114 this.selection
= selection
;
116 formFactory
= new CdmFormFactory(Display
.getCurrent(), null);
117 conversation
= CdmStore
.createConversation();
118 entity
= createNewEntity();
123 * <p>createNewEntity</p>
125 * @return a T object.
127 protected abstract T
createNewEntity();
130 * <p>getConversationHolder</p>
132 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
135 public ConversationHolder
getConversationHolder() {
141 public void update(CdmDataChangeMap changeEvents
) {}
144 * @return the workbench
146 public IWorkbench
getWorkbench() {
151 * @return the selection
153 public IStructuredSelection
getSelection() {