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 javax.inject.Inject;
|
13
|
|
14
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
15
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
import org.eclipse.jface.wizard.Wizard;
|
18
|
import org.eclipse.ui.INewWizard;
|
19
|
import org.eclipse.ui.IWorkbench;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
22
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
27
|
/**
|
28
|
* @author k.luther
|
29
|
* @date 23.03.2016
|
30
|
*
|
31
|
*/
|
32
|
public abstract class AbstractEditWizard<T> extends Wizard implements
|
33
|
INewWizard, IConversationEnabled{
|
34
|
|
35
|
private ConversationHolder conversation;
|
36
|
|
37
|
protected CdmFormFactory formFactory;
|
38
|
|
39
|
private T entity;
|
40
|
|
41
|
private IWorkbench workbench;
|
42
|
|
43
|
private IEclipseContext context;
|
44
|
|
45
|
/**
|
46
|
* <p>Constructor for AbstractNewEntityWizard.</p>
|
47
|
*
|
48
|
* @param <T> a T object.
|
49
|
*/
|
50
|
@Inject
|
51
|
public AbstractEditWizard(){
|
52
|
setWindowTitle(String.format("New %s", getEntityName()));
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* FIXME there might be a smarter way to do this,
|
57
|
*
|
58
|
* @return
|
59
|
*/
|
60
|
protected abstract String getEntityName();
|
61
|
|
62
|
/* (non-Javadoc)
|
63
|
* @see org.eclipse.jface.wizard.Wizard#performFinish()
|
64
|
*/
|
65
|
/** {@inheritDoc} */
|
66
|
@Override
|
67
|
public boolean performFinish() {
|
68
|
saveEntity();
|
69
|
|
70
|
conversation.commit();
|
71
|
conversation.close();
|
72
|
return true;
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* <p>Getter for the field <code>entity</code>.</p>
|
77
|
*
|
78
|
* @return a T object.
|
79
|
*/
|
80
|
public T getEntity() {
|
81
|
return entity;
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* <p>Setter for the field <code>entity</code>.</p>
|
86
|
*
|
87
|
* @param entity a T object.
|
88
|
*/
|
89
|
public void setEntity(T entity){
|
90
|
this.entity = entity;
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* Adds the entity to the current persistence context
|
95
|
*/
|
96
|
protected abstract void saveEntity();
|
97
|
|
98
|
/* (non-Javadoc)
|
99
|
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
|
100
|
*/
|
101
|
/** {@inheritDoc} */
|
102
|
@Override
|
103
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
104
|
this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench();
|
105
|
|
106
|
|
107
|
formFactory = ContextInjectionFactory.make(CdmFormFactory.class, context);
|
108
|
conversation = CdmStore.createConversation();
|
109
|
|
110
|
|
111
|
}
|
112
|
|
113
|
|
114
|
|
115
|
/**
|
116
|
* <p>getConversationHolder</p>
|
117
|
*
|
118
|
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
119
|
*/
|
120
|
@Override
|
121
|
public ConversationHolder getConversationHolder() {
|
122
|
return conversation;
|
123
|
}
|
124
|
|
125
|
/** {@inheritDoc} */
|
126
|
@Override
|
127
|
public void update(CdmDataChangeMap changeEvents) {}
|
128
|
|
129
|
/**
|
130
|
* @return the workbench
|
131
|
*/
|
132
|
public IWorkbench getWorkbench() {
|
133
|
return workbench;
|
134
|
}
|
135
|
|
136
|
|
137
|
|
138
|
}
|