2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.newWizard
;
12 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
13 import org
.eclipse
.jface
.wizard
.Wizard
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.ui
.INewWizard
;
16 import org
.eclipse
.ui
.ISelectionService
;
17 import org
.eclipse
.ui
.IWorkbench
;
19 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
21 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
22 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.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(String
.format("New %s", getEntityName()));
57 * FIXME there might be a smarter way to do this,
61 protected abstract String
getEntityName();
64 * @see org.eclipse.jface.wizard.Wizard#performFinish()
68 public boolean performFinish() {
71 conversation
.commit();
77 * <p>Getter for the field <code>entity</code>.</p>
81 public T
getEntity() {
86 * <p>Setter for the field <code>entity</code>.</p>
88 * @param entity a T object.
90 public void setEntity(T entity
){
95 * Adds the entity to the current persistence context
97 protected abstract void saveEntity();
100 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
104 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
105 this.workbench
= workbench
!= null ? workbench
: AbstractUtility
.getWorkbench();
107 if(selection
== null){
108 ISelectionService service
= this.workbench
.getActiveWorkbenchWindow().getSelectionService();
109 if(service
.getSelection() instanceof IStructuredSelection
){
110 selection
= (IStructuredSelection
) service
.getSelection();
113 this.selection
= selection
;
115 formFactory
= new CdmFormFactory(Display
.getCurrent(), null);
116 conversation
= CdmStore
.createConversation();
117 entity
= createNewEntity();
122 * <p>createNewEntity</p>
124 * @return a T object.
126 protected abstract T
createNewEntity();
129 * <p>getConversationHolder</p>
131 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
134 public ConversationHolder
getConversationHolder() {
140 public void update(CdmDataChangeMap changeEvents
) {}
143 * @return the workbench
145 public IWorkbench
getWorkbench() {
150 * @return the selection
152 public IStructuredSelection
getSelection() {