Revision 1c12d52c
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/AbstractNewEntityWizard.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.newWizard; |
11 | 11 |
|
12 |
import org.eclipse.e4.ui.workbench.IWorkbench; |
|
12 | 13 |
import org.eclipse.jface.viewers.IStructuredSelection; |
13 | 14 |
import org.eclipse.jface.wizard.Wizard; |
14 | 15 |
import org.eclipse.swt.widgets.Display; |
15 |
import org.eclipse.ui.INewWizard; |
|
16 |
import org.eclipse.ui.ISelectionService; |
|
17 |
import org.eclipse.ui.IWorkbench; |
|
18 | 16 |
|
19 | 17 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
20 | 18 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
21 | 19 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
22 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
23 | 20 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
24 | 21 |
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; |
25 | 22 |
|
26 | 23 |
/** |
27 |
* <p>Abstract AbstractNewEntityWizard class.</p> |
|
28 | 24 |
* |
29 | 25 |
* @author n.hoffmann |
30 | 26 |
* @created Jun 1, 2010 |
31 | 27 |
* @version 1.0 |
32 | 28 |
*/ |
33 | 29 |
public abstract class AbstractNewEntityWizard<T> extends Wizard implements |
34 |
INewWizard, IConversationEnabled {
|
|
30 |
IConversationEnabled { |
|
35 | 31 |
|
36 | 32 |
private ConversationHolder conversation; |
37 | 33 |
|
... | ... | |
39 | 35 |
|
40 | 36 |
private T entity; |
41 | 37 |
|
42 |
private IWorkbench workbench; |
|
43 |
|
|
44 | 38 |
private IStructuredSelection selection; |
45 | 39 |
|
46 |
/** |
|
47 |
* <p>Constructor for AbstractNewEntityWizard.</p> |
|
48 |
* |
|
49 |
* @param <T> a T object. |
|
50 |
*/ |
|
51 | 40 |
public AbstractNewEntityWizard(){ |
52 | 41 |
setWindowTitle(String.format("New %s", getEntityName())); |
53 | 42 |
} |
... | ... | |
59 | 48 |
*/ |
60 | 49 |
protected abstract String getEntityName(); |
61 | 50 |
|
62 |
/* (non-Javadoc) |
|
63 |
* @see org.eclipse.jface.wizard.Wizard#performFinish() |
|
64 |
*/ |
|
65 | 51 |
/** {@inheritDoc} */ |
66 | 52 |
@Override |
67 | 53 |
public boolean performFinish() { |
... | ... | |
72 | 58 |
return true; |
73 | 59 |
} |
74 | 60 |
|
75 |
/** |
|
76 |
* <p>Getter for the field <code>entity</code>.</p> |
|
77 |
* |
|
78 |
* @return a T object. |
|
79 |
*/ |
|
80 | 61 |
public T getEntity() { |
81 | 62 |
return entity; |
82 | 63 |
} |
83 | 64 |
|
84 |
/** |
|
85 |
* <p>Setter for the field <code>entity</code>.</p> |
|
86 |
* |
|
87 |
* @param entity a T object. |
|
88 |
*/ |
|
89 | 65 |
public void setEntity(T entity){ |
90 | 66 |
this.entity = entity; |
91 | 67 |
} |
... | ... | |
95 | 71 |
*/ |
96 | 72 |
protected abstract void saveEntity(); |
97 | 73 |
|
98 |
/* (non-Javadoc) |
|
99 |
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) |
|
100 |
*/ |
|
101 | 74 |
/** {@inheritDoc} */ |
102 |
@Override |
|
103 | 75 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
104 |
this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench(); |
|
105 |
|
|
106 |
if(selection == null){ |
|
107 |
ISelectionService service = this.workbench.getActiveWorkbenchWindow().getSelectionService(); |
|
108 |
if(service.getSelection() instanceof IStructuredSelection){ |
|
109 |
selection = (IStructuredSelection) service.getSelection(); |
|
110 |
} |
|
111 |
} |
|
112 |
this.selection = selection; |
|
113 |
|
|
114 |
formFactory = new CdmFormFactory(Display.getCurrent(), null); |
|
115 |
conversation = CdmStore.createConversation(); |
|
76 |
formFactory = new CdmFormFactory(Display.getCurrent(), null); |
|
77 |
conversation = CdmStore.createConversation(); |
|
78 |
this.selection = selection; |
|
116 | 79 |
entity = createNewEntity(); |
117 | 80 |
|
118 | 81 |
} |
119 | 82 |
|
120 |
/** |
|
121 |
* <p>createNewEntity</p> |
|
122 |
* |
|
123 |
* @return a T object. |
|
124 |
*/ |
|
125 | 83 |
protected abstract T createNewEntity(); |
126 | 84 |
|
127 |
/** |
|
128 |
* <p>getConversationHolder</p> |
|
129 |
* |
|
130 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
131 |
*/ |
|
132 | 85 |
@Override |
133 | 86 |
public ConversationHolder getConversationHolder() { |
134 | 87 |
return conversation; |
... | ... | |
138 | 91 |
@Override |
139 | 92 |
public void update(CdmDataChangeMap changeEvents) {} |
140 | 93 |
|
141 |
/** |
|
142 |
* @return the workbench |
|
143 |
*/ |
|
144 |
public IWorkbench getWorkbench() { |
|
145 |
return workbench; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* @return the selection |
|
150 |
*/ |
|
151 | 94 |
public IStructuredSelection getSelection() { |
152 | 95 |
return selection; |
153 | 96 |
} |
Also available in: Unified diff
ref #6913 Remove workbench and selection handling from edit/new wizards