4 package eu
.etaxonomy
.taxeditor
.newWizard
;
9 import javax
.inject
.Inject
;
11 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
12 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
;
13 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
.Action
;
14 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
15 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
16 import eu
.etaxonomy
.cdm
.api
.service
.dto
.CreateTaxonDTO
;
17 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
18 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNodeStatus
;
22 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
23 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.classification
.TaxonNodeDetailElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.classification
.TaxonNodeWizardPage
;
30 * <p>NewTaxonNodeWizard class.</p>
33 * @created Sep 15, 2009
35 public class NewTaxonNodeWizard
extends AbstractNewEntityWizardParentChild
<TaxonNode
>{
37 private TaxonNodeWizardPage taxonNodePage
;
38 private boolean openEmptyEditor
;
39 private UUID generatedTaxonNodeUuid
;
40 private IWizardPageListener wizardPageListener
;
41 private boolean isOpenInEditor
= false;
42 private boolean success
= true;
45 * <p>Constructor for AbstractNewEntityWizard.</p>
47 * @param <T> a T object.
50 public NewTaxonNodeWizard(){
51 setWindowTitle(Messages
.TaxonNodeWizardPage_new
);
55 public void addPages() {
56 taxonNodePage
= new TaxonNodeWizardPage(formFactory
, getConversationHolder(), getParentEntity(), wizardPageListener
, true);
57 addPage(taxonNodePage
);
61 protected void saveEntity() {
62 CreateTaxonDTO taxon
= taxonNodePage
.createTaxon();
64 openEmptyEditor
= true;
66 getConversationHolder().bind();
69 TaxonNode parent
= getParentEntity();
70 Map
<Language
, LanguageString
> nodes
= ((TaxonNodeDetailElement
)taxonNodePage
.getDetailElement()).getMultiLanguageTextExcludedNotes();
71 UUID refUuid
= parent
.getReference() != null? parent
.getReference().getUuid(): null;
73 TaxonNodeStatus status
= null;
74 if( ((TaxonNodeDetailElement
)taxonNodePage
.getDetailElement()).isUnplaced()){
75 status
= TaxonNodeStatus
.UNPLACED
;
76 }else if( ((TaxonNodeDetailElement
)taxonNodePage
.getDetailElement()).isPlacementDoubtful()){
77 status
= TaxonNodeStatus
.DOUBTFUL
;
78 }else if (((TaxonNodeDetailElement
)taxonNodePage
.getDetailElement()).isExcluded()){
79 status
= TaxonNodeStatus
.EXCLUDED
;
81 result
= CdmStore
.getService(ITaxonNodeService
.class).createNewTaxonNode(parent
.getUuid(), taxon
, refUuid
, parent
.getMicroReference(),
86 this.setEntity((TaxonNode
)result
.getCdmEntity());
87 CdmApplicationState
.getCurrentDataChangeService()
88 .fireChangeEvent(new CdmChangeEvent(Action
.Create
, result
.getUpdatedObjects(), NewTaxonNodeWizard
.class), true);
93 if (!result
.getExceptions().isEmpty()){
94 MessagingUtils
.error(getClass(), "Taxon could not be created", result
.getExceptions().iterator().next());
96 MessagingUtils
.warn(getClass(), "Taxon could not be created");
101 }catch(IllegalArgumentException e
){
102 MessagingUtils
.warningDialog("Taxon already exists in classfication", getClass(), e
.getMessage());
108 // protected TaxonNode createNewEntity() {
109 // if(getSelection() != null){
110 // Object selectedObject = getSelection().getFirstElement();
111 // if(selectedObject instanceof TaxonNodeDto){
112 // TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
113 // TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
114 // Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
115 // Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
116 // TaxonNode child = node.addChildTaxon(newTaxon, null, null);
134 public boolean openInEditor() {
135 return isOpenInEditor
;
138 public void setOpenInEditor(boolean isOpenInEditor
) {
139 this.isOpenInEditor
= isOpenInEditor
;
147 public boolean openEmpty(){
148 return openInEditor() && openEmptyEditor
;
152 * <p>getTaxonNode</p>
154 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
156 public TaxonNode
getTaxonNode(){
157 if(generatedTaxonNodeUuid
!= null){
158 return CdmStore
.getService(ITaxonNodeService
.class).load(generatedTaxonNodeUuid
);
163 public ITaxonTreeNode
getParentTreeNode(){
164 return taxonNodePage
.getParentTreeNode();
168 protected String
getEntityName() {
172 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
173 this.wizardPageListener
= wizardPageListener
;
177 public boolean isSuccess() {
182 public void setSuccess(boolean success
) {
183 this.success
= success
;
187 public void createParentEntity() {
188 Object selectedObject
= getSelection().getFirstElement();
189 if(selectedObject
instanceof TaxonNodeDto
){
190 if(selectedObject
instanceof TaxonNodeDto
){
191 TaxonNodeDto taxonNodeDto
= (TaxonNodeDto
) selectedObject
;
192 setParentEntity(CdmStore
.getService(ITaxonNodeService
.class).load(taxonNodeDto
.getUuid()));