ref #10221: code cleaning
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / newWizard / AbstractNewEntityWizardParentChild.java
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
10 package eu.etaxonomy.taxeditor.newWizard;
11
12 import org.eclipse.e4.ui.workbench.IWorkbench;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.jface.wizard.Wizard;
15 import org.eclipse.swt.widgets.Display;
16
17 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
18 import eu.etaxonomy.taxeditor.store.CdmStore;
19 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
21 /**
22 *
23 * @author n.hoffmann
24 * @created Jun 1, 2010
25 * @version 1.0
26 */
27 public abstract class AbstractNewEntityWizardParentChild<T> extends Wizard {
28
29 protected CdmFormFactory formFactory;
30
31 private T parentEntity;
32 private T entity;
33 private boolean finished = false;
34
35
36 private IStructuredSelection selection;
37
38 public AbstractNewEntityWizardParentChild(){
39 setWindowTitle(String.format("New %s", getEntityName()));
40 }
41
42 /**
43 * FIXME there might be a smarter way to do this,
44 *
45 * @return
46 */
47 protected abstract String getEntityName();
48
49 /** {@inheritDoc} */
50 @Override
51 public boolean performFinish() {
52 if (finished){
53 return true;
54 }
55 saveEntity();
56 finished = true;
57 return true;
58 }
59
60 public T getParentEntity() {
61 return parentEntity;
62 }
63
64 public void setParentEntity(T entity){
65 this.parentEntity = entity;
66 }
67
68 public T getEntity() {
69 return entity;
70 }
71
72 public void setEntity(T entity){
73 this.entity = entity;
74 }
75
76
77 /**
78 * Adds the entity to the current persistence context
79 */
80 protected abstract void saveEntity();
81
82 /** {@inheritDoc} */
83 public void init(IWorkbench workbench, IStructuredSelection selection) {
84 formFactory = new CdmFormFactory(Display.getCurrent(), null);
85 this.selection = selection;
86
87 createParentEntity();
88
89
90 }
91
92 protected abstract void createParentEntity();
93
94 public IStructuredSelection getSelection() {
95 return selection;
96 }
97 }