1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.newWizard;
|
11
|
|
12
|
import org.eclipse.e4.ui.workbench.IWorkbench;
|
13
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
14
|
import org.eclipse.jface.wizard.Wizard;
|
15
|
import org.eclipse.swt.widgets.Display;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
19
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22
|
|
23
|
/**
|
24
|
*
|
25
|
* @author n.hoffmann
|
26
|
* @created Jun 1, 2010
|
27
|
* @version 1.0
|
28
|
*/
|
29
|
public abstract class AbstractNewEntityWizard<T> extends Wizard implements
|
30
|
IConversationEnabled {
|
31
|
|
32
|
private ConversationHolder conversation;
|
33
|
|
34
|
protected CdmFormFactory formFactory;
|
35
|
|
36
|
private T entity;
|
37
|
|
38
|
private IStructuredSelection selection;
|
39
|
|
40
|
public AbstractNewEntityWizard(){
|
41
|
setWindowTitle(String.format("New %s", getEntityName()));
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* FIXME there might be a smarter way to do this,
|
46
|
*
|
47
|
* @return
|
48
|
*/
|
49
|
protected abstract String getEntityName();
|
50
|
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
public boolean performFinish() {
|
54
|
saveEntity();
|
55
|
|
56
|
conversation.commit();
|
57
|
conversation.close();
|
58
|
conversation = null;
|
59
|
return true;
|
60
|
}
|
61
|
|
62
|
public T getEntity() {
|
63
|
return entity;
|
64
|
}
|
65
|
|
66
|
public void setEntity(T entity){
|
67
|
this.entity = entity;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Adds the entity to the current persistence context
|
72
|
*/
|
73
|
protected abstract void saveEntity();
|
74
|
|
75
|
/** {@inheritDoc} */
|
76
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
77
|
formFactory = new CdmFormFactory(Display.getCurrent(), null);
|
78
|
conversation = CdmStore.createConversation();
|
79
|
this.selection = selection;
|
80
|
entity = createNewEntity();
|
81
|
|
82
|
}
|
83
|
|
84
|
protected abstract T createNewEntity();
|
85
|
|
86
|
@Override
|
87
|
public ConversationHolder getConversationHolder() {
|
88
|
return conversation;
|
89
|
}
|
90
|
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
public void update(CdmDataChangeMap changeEvents) {}
|
94
|
|
95
|
public IStructuredSelection getSelection() {
|
96
|
return selection;
|
97
|
}
|
98
|
}
|