Project

General

Profile

Download (2.28 KB) Statistics
| Branch: | Tag: | Revision:
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.taxeditor.ui.element.CdmFormFactory;
22
/**
23
 * @author k.luther
24
 * @date 23.03.2016
25
 *
26
 */
27
public abstract class AbstractEditWizard<T> extends Wizard implements INewWizard{
28

    
29
    protected CdmFormFactory formFactory;
30

    
31
    private T entity;
32

    
33
    @Inject
34
    private IEclipseContext context;
35

    
36
    /**
37
     * <p>Constructor for AbstractNewEntityWizard.</p>
38
     *
39
     * @param <T> a T object.
40
     */
41
    @Inject
42
    public AbstractEditWizard(){
43
        setWindowTitle(String.format("New %s", getEntityName()));
44
    }
45

    
46
    /**
47
     * FIXME there might be a smarter way to do this,
48
     *
49
     * @return
50
     */
51
    protected abstract String getEntityName();
52

    
53
    /* (non-Javadoc)
54
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
55
     */
56
    /** {@inheritDoc} */
57
    @Override
58
    public boolean performFinish() {
59
        saveEntity();
60
        return true;
61
    }
62

    
63
    /**
64
     * <p>Getter for the field <code>entity</code>.</p>
65
     *
66
     * @return a T object.
67
     */
68
    public T getEntity() {
69
        return entity;
70
    }
71

    
72
    /**
73
     * <p>Setter for the field <code>entity</code>.</p>
74
     *
75
     * @param entity a T object.
76
     */
77
    public void setEntity(T entity){
78
        this.entity = entity;
79
    }
80

    
81
    /**
82
     * Adds the entity to the current persistence context
83
     */
84
    protected abstract void saveEntity();
85

    
86
    /* (non-Javadoc)
87
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
88
     */
89
    /** {@inheritDoc} */
90
    @Override
91
    public void init(IWorkbench workbench, IStructuredSelection selection) {
92
        formFactory = new CdmFormFactory(context.get(Shell.class).getDisplay());
93
    }
94
    
95

    
96
}
(1-1/12)