1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.newWizard;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
15
|
import org.eclipse.jface.wizard.Wizard;
|
16
|
import org.eclipse.swt.widgets.Display;
|
17
|
import org.eclipse.ui.INewWizard;
|
18
|
import org.eclipse.ui.IWorkbench;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
21
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
22
|
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
24
|
import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* <p>Abstract AbstractNewEntityWizard class.</p>
|
29
|
*
|
30
|
* @author n.hoffmann
|
31
|
* @created Jun 1, 2010
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
public abstract class AbstractNewEntityWizard<T extends IAnnotatableEntity> extends Wizard implements
|
35
|
INewWizard, IConversationEnabled {
|
36
|
private static final Logger logger = Logger
|
37
|
.getLogger(AbstractNewEntityWizard.class);
|
38
|
|
39
|
private ConversationHolder conversation;
|
40
|
|
41
|
protected CdmFormFactory formFactory;
|
42
|
|
43
|
protected T entity;
|
44
|
|
45
|
private IWorkbench workbench;
|
46
|
|
47
|
protected IStructuredSelection selection;
|
48
|
|
49
|
/**
|
50
|
* <p>Constructor for AbstractNewEntityWizard.</p>
|
51
|
*
|
52
|
* @param <T> a T object.
|
53
|
*/
|
54
|
public AbstractNewEntityWizard(){
|
55
|
setWindowTitle("New Entity");
|
56
|
}
|
57
|
|
58
|
/* (non-Javadoc)
|
59
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
60
|
*/
|
61
|
/** {@inheritDoc} */
|
62
|
@Override
|
63
|
public boolean performFinish() {
|
64
|
saveEntity();
|
65
|
|
66
|
conversation.commit();
|
67
|
conversation.close();
|
68
|
return true;
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* <p>Getter for the field <code>entity</code>.</p>
|
73
|
*
|
74
|
* @return a T object.
|
75
|
*/
|
76
|
public T getEntity() {
|
77
|
return entity;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* <p>Setter for the field <code>entity</code>.</p>
|
82
|
*
|
83
|
* @param entity a T object.
|
84
|
*/
|
85
|
public void setEntity(T entity){
|
86
|
this.entity = entity;
|
87
|
}
|
88
|
|
89
|
/**
|
90
|
* Adds the entity to the current persistence context
|
91
|
*/
|
92
|
protected abstract void saveEntity();
|
93
|
|
94
|
/* (non-Javadoc)
|
95
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
96
|
*/
|
97
|
/** {@inheritDoc} */
|
98
|
@Override
|
99
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
100
|
this.workbench = workbench;
|
101
|
this.selection = selection;
|
102
|
formFactory = new CdmFormFactory(Display.getCurrent(), null);
|
103
|
entity = createNewEntity();
|
104
|
conversation = CdmStore.createConversation();
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* <p>createNewEntity</p>
|
109
|
*
|
110
|
* @return a T object.
|
111
|
*/
|
112
|
protected abstract T createNewEntity();
|
113
|
|
114
|
/**
|
115
|
* <p>getConversationHolder</p>
|
116
|
*
|
117
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
118
|
*/
|
119
|
public ConversationHolder getConversationHolder() {
|
120
|
return conversation;
|
121
|
}
|
122
|
|
123
|
/** {@inheritDoc} */
|
124
|
public void update(CdmDataChangeMap changeEvents) {}
|
125
|
}
|