1
|
/**
|
2
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.taxeditor.ui.section.classification;
|
10
|
|
11
|
|
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.IWorkbench;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
19
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
20
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
21
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
/**
|
25
|
* @author k.luther
|
26
|
* @date 23.03.2016
|
27
|
*
|
28
|
*/
|
29
|
public abstract class AbstractEditWizard<T> extends Wizard implements
|
30
|
INewWizard, IConversationEnabled{
|
31
|
|
32
|
private ConversationHolder conversation;
|
33
|
|
34
|
protected CdmFormFactory formFactory;
|
35
|
|
36
|
private T entity;
|
37
|
|
38
|
private IWorkbench workbench;
|
39
|
|
40
|
|
41
|
|
42
|
/**
|
43
|
* <p>Constructor for AbstractNewEntityWizard.</p>
|
44
|
*
|
45
|
* @param <T> a T object.
|
46
|
*/
|
47
|
public AbstractEditWizard(){
|
48
|
setWindowTitle(String.format("New %s", getEntityName()));
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* FIXME there might be a smarter way to do this,
|
53
|
*
|
54
|
* @return
|
55
|
*/
|
56
|
protected abstract String getEntityName();
|
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 != null ? workbench : AbstractUtility.getWorkbench();
|
101
|
|
102
|
|
103
|
formFactory = new CdmFormFactory(Display.getCurrent(), null);
|
104
|
conversation = CdmStore.createConversation();
|
105
|
|
106
|
|
107
|
}
|
108
|
|
109
|
|
110
|
|
111
|
/**
|
112
|
* <p>getConversationHolder</p>
|
113
|
*
|
114
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
115
|
*/
|
116
|
@Override
|
117
|
public ConversationHolder getConversationHolder() {
|
118
|
return conversation;
|
119
|
}
|
120
|
|
121
|
/** {@inheritDoc} */
|
122
|
@Override
|
123
|
public void update(CdmDataChangeMap changeEvents) {}
|
124
|
|
125
|
/**
|
126
|
* @return the workbench
|
127
|
*/
|
128
|
public IWorkbench getWorkbench() {
|
129
|
return workbench;
|
130
|
}
|
131
|
|
132
|
|
133
|
|
134
|
}
|