Project

General

Profile

Download (1.56 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.newWizard;
10

    
11
import org.eclipse.e4.ui.workbench.IWorkbench;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.swt.widgets.Display;
15

    
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17

    
18
/**
19
 * @author n.hoffmann
20
 * @created Jun 1, 2010
21
 */
22
public abstract class AbstractNewEntityWizard<T>
23
        extends Wizard {
24

    
25
	protected CdmFormFactory formFactory;
26

    
27
	private T entity;
28

    
29
	protected IStructuredSelection selection;
30

    
31
	public AbstractNewEntityWizard(){
32
		setWindowTitle(String.format("New %s", getEntityName()));
33
	}
34

    
35
	/**
36
	 * FIXME there might be a smarter way to do this,
37
	 */
38
	protected abstract String getEntityName();
39

    
40
	@Override
41
	public boolean performFinish() {
42
		saveEntity();
43
		return true;
44
	}
45

    
46
	public T getEntity() {
47
		return entity;
48
	}
49

    
50
	public void setEntity(T entity){
51
		this.entity = entity;
52
	}
53

    
54
	/**
55
	 * Adds the entity to the current persistence context
56
	 */
57
	protected abstract void saveEntity();
58

    
59
	public void init(IWorkbench workbench, IStructuredSelection selection) {
60
	    formFactory = new CdmFormFactory(Display.getCurrent(), null);
61
	    this.selection = selection;
62
	 	entity = createNewEntity();
63

    
64
	}
65

    
66
	protected abstract T createNewEntity();
67

    
68
	public IStructuredSelection getSelection() {
69
		return selection;
70
	}
71
}
(1-1/28)