Project

General

Profile

Download (3.45 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.taxeditor.ui.section.classification;
11

    
12

    
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.ui.INewWizard;
17
import org.eclipse.ui.IWorkbench;
18

    
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
22
import eu.etaxonomy.taxeditor.model.AbstractUtility;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
/**
26
 * @author k.luther
27
 * @date 23.03.2016
28
 *
29
 */
30
public abstract class AbstractEditWizard<T> extends Wizard implements
31
INewWizard, IConversationEnabled{
32

    
33
    private ConversationHolder conversation;
34

    
35
    protected CdmFormFactory formFactory;
36

    
37
    private T entity;
38

    
39
    private IWorkbench workbench;
40

    
41

    
42

    
43
        /**
44
         * <p>Constructor for AbstractNewEntityWizard.</p>
45
         *
46
         * @param <T> a T object.
47
         */
48
        public AbstractEditWizard(){
49
            setWindowTitle(String.format("New %s", getEntityName()));
50
        }
51

    
52
        /**
53
         * FIXME there might be a smarter way to do this,
54
         *
55
         * @return
56
         */
57
        protected abstract String getEntityName();
58

    
59
        /* (non-Javadoc)
60
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
61
         */
62
        /** {@inheritDoc} */
63
        @Override
64
        public boolean performFinish() {
65
            saveEntity();
66

    
67
            conversation.commit();
68
            conversation.close();
69
            return true;
70
        }
71

    
72
        /**
73
         * <p>Getter for the field <code>entity</code>.</p>
74
         *
75
         * @return a T object.
76
         */
77
        public T getEntity() {
78
            return entity;
79
        }
80

    
81
        /**
82
         * <p>Setter for the field <code>entity</code>.</p>
83
         *
84
         * @param entity a T object.
85
         */
86
        public void setEntity(T entity){
87
            this.entity = entity;
88
        }
89

    
90
        /**
91
         * Adds the entity to the current persistence context
92
         */
93
        protected abstract void saveEntity();
94

    
95
        /* (non-Javadoc)
96
         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
97
         */
98
        /** {@inheritDoc} */
99
        @Override
100
        public void init(IWorkbench workbench, IStructuredSelection selection) {
101
            this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench();
102

    
103

    
104
            formFactory = new CdmFormFactory(Display.getCurrent(), null);
105
            conversation = CdmStore.createConversation();
106

    
107

    
108
        }
109

    
110

    
111

    
112
        /**
113
         * <p>getConversationHolder</p>
114
         *
115
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
116
         */
117
        @Override
118
        public ConversationHolder getConversationHolder() {
119
            return conversation;
120
        }
121

    
122
        /** {@inheritDoc} */
123
        @Override
124
        public void update(CdmDataChangeMap changeEvents) {}
125

    
126
        /**
127
         * @return the workbench
128
         */
129
        public IWorkbench getWorkbench() {
130
            return workbench;
131
        }
132

    
133

    
134

    
135
}
(1-1/12)