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 java.util.List;
|
13
|
|
14
|
import org.eclipse.e4.ui.workbench.IWorkbench;
|
15
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
16
|
import org.eclipse.swt.widgets.Display;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
21
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
|
25
|
|
26
|
/**
|
27
|
* <p>NewReferenceWizard class.</p>
|
28
|
*
|
29
|
* @author n.hoffmann
|
30
|
* @created Jun 1, 2010
|
31
|
*/
|
32
|
public class NewReferenceWizard extends AbstractNewEntityWizard<Reference> {
|
33
|
|
34
|
private ReferenceWizardPage referencePage;
|
35
|
private ReferenceType refType = null;
|
36
|
|
37
|
public NewReferenceWizard(ReferenceType type){
|
38
|
super();
|
39
|
refType = type;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
44
|
formFactory = new CdmFormFactory(Display.getCurrent(), null);
|
45
|
conversation = CdmStore.createConversation();
|
46
|
this.selection = selection;
|
47
|
setEntity(createNewEntity());
|
48
|
|
49
|
}
|
50
|
|
51
|
/** {@inheritDoc} */
|
52
|
@Override
|
53
|
public void addPages() {
|
54
|
// TODO disabling external service wizard page for now
|
55
|
// addPage(new ExternalReferenceServiceWizardPage(formFactory, getConversationHolder(), entity));
|
56
|
referencePage = new ReferenceWizardPage(formFactory, getConversationHolder(), getEntity(), false);
|
57
|
addPage(referencePage);
|
58
|
}
|
59
|
|
60
|
/** {@inheritDoc} */
|
61
|
@Override
|
62
|
protected Reference createNewEntity() {
|
63
|
if (refType != null){
|
64
|
List<ReferenceType> inReferenceTypes = ReferenceType.inReferenceContraints(refType);
|
65
|
if (!inReferenceTypes.isEmpty()){
|
66
|
return ReferenceFactory.newReference(inReferenceTypes.iterator().next());
|
67
|
}
|
68
|
}
|
69
|
return ReferenceFactory.newGeneric();
|
70
|
}
|
71
|
|
72
|
/** {@inheritDoc} */
|
73
|
@Override
|
74
|
protected void saveEntity() {
|
75
|
CdmStore.getService(IReferenceService.class).save(getEntity());
|
76
|
}
|
77
|
|
78
|
/** {@inheritDoc} */
|
79
|
@Override
|
80
|
public void setEntity(Reference entity) {
|
81
|
super.setEntity(entity);
|
82
|
if (referencePage != null){
|
83
|
referencePage.getDetailElement().setEntity(entity);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
protected String getEntityName() {
|
89
|
return "Reference";
|
90
|
}
|
91
|
}
|