2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.newWizard
;
12 import java
.util
.List
;
14 import org
.eclipse
.e4
.ui
.workbench
.IWorkbench
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.swt
.widgets
.Display
;
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
;
27 * <p>NewReferenceWizard class.</p>
30 * @created Jun 1, 2010
32 public class NewReferenceWizard
extends AbstractNewEntityWizard
<Reference
> {
34 private ReferenceWizardPage referencePage
;
35 private ReferenceType refType
= null;
37 public NewReferenceWizard(ReferenceType type
){
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());
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());
57 addPage(referencePage
);
62 protected Reference
createNewEntity() {
64 List
<ReferenceType
> inReferenceTypes
= ReferenceType
.inReferenceContraints(refType
);
65 if (!inReferenceTypes
.isEmpty()){
66 return ReferenceFactory
.newReference(inReferenceTypes
.iterator().next());
69 return ReferenceFactory
.newGeneric();
74 protected void saveEntity() {
75 CdmStore
.getService(IReferenceService
.class).save(getEntity());
80 public void setEntity(Reference entity
) {
81 super.setEntity(entity
);
82 if (referencePage
!= null){
83 referencePage
.getDetailElement().setEntity(entity
);
88 protected String
getEntityName() {