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
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
25 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
28 * <p>Abstract AbstractNewEntityWizard class.</p>
31 * @created Jun 1, 2010
34 public abstract class AbstractNewEntityWizard
<T
> extends Wizard
implements
35 INewWizard
, IConversationEnabled
{
37 private ConversationHolder conversation
;
39 protected CdmFormFactory formFactory
;
43 private IWorkbench workbench
;
45 private IStructuredSelection selection
;
48 * <p>Constructor for AbstractNewEntityWizard.</p>
50 * @param <T> a T object.
52 public AbstractNewEntityWizard(){
53 setWindowTitle("New Entity");
57 * @see org.eclipse.jface.wizard.Wizard#performFinish()
61 public boolean performFinish() {
64 conversation
.commit();
70 * <p>Getter for the field <code>entity</code>.</p>
74 public T
getEntity() {
79 * <p>Setter for the field <code>entity</code>.</p>
81 * @param entity a T object.
83 public void setEntity(T entity
){
88 * Adds the entity to the current persistence context
90 protected abstract void saveEntity();
93 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
97 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
98 this.workbench
= workbench
!= null ? workbench
: StoreUtil
.getWorkbench();
100 if(selection
== null){
101 ISelectionService service
= (ISelectionService
) this.workbench
.getActiveWorkbenchWindow().getSelectionService();
102 if(service
.getSelection() instanceof IStructuredSelection
){
103 selection
= (IStructuredSelection
) service
.getSelection();
106 this.selection
= selection
;
108 formFactory
= new CdmFormFactory(Display
.getCurrent(), null);
109 conversation
= CdmStore
.createConversation();
110 entity
= createNewEntity();
115 * <p>createNewEntity</p>
117 * @return a T object.
119 protected abstract T
createNewEntity();
122 * <p>getConversationHolder</p>
124 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
126 public ConversationHolder
getConversationHolder() {
131 public void update(CdmDataChangeMap changeEvents
) {}
134 * @return the workbench
136 public IWorkbench
getWorkbench() {
141 * @return the selection
143 public IStructuredSelection
getSelection() {