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