4 package eu
.etaxonomy
.taxeditor
.newWizard
;
8 import javax
.inject
.Inject
;
10 import org
.apache
.commons
.lang
.StringUtils
;
12 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
13 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
;
14 import eu
.etaxonomy
.cdm
.api
.application
.CdmChangeEvent
.Action
;
15 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
16 import eu
.etaxonomy
.cdm
.api
.service
.UpdateResult
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
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
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.classification
.TaxonNodeWizardPage
;
30 * <p>NewTaxonNodeWizard class.</p>
33 * @created Sep 15, 2009
36 public class NewTaxonNodeWizard
extends AbstractNewEntityWizard
<TaxonNode
>{
38 private TaxonNodeWizardPage taxonNodePage
;
39 private boolean openEmptyEditor
;
40 private UUID generatedTaxonNodeUuid
;
41 private IWizardPageListener wizardPageListener
;
42 private boolean isOpenInEditor
= false;
45 * <p>Constructor for AbstractNewEntityWizard.</p>
47 * @param <T> a T object.
50 public NewTaxonNodeWizard(){
51 setWindowTitle(Messages
.TaxonNodeWizardPage_new
);
56 public void addPages() {
57 taxonNodePage
= new TaxonNodeWizardPage(formFactory
, getConversationHolder(), getEntity(), wizardPageListener
, true);
58 addPage(taxonNodePage
);
63 protected void saveEntity() {
64 Taxon taxon
= taxonNodePage
.createTaxon();
65 if(taxon
== null || StringUtils
.isEmpty(taxon
.getName().getFullTitleCache())){
66 openEmptyEditor
= true;
68 getConversationHolder().bind();
69 // ITaxonTreeNode parent = getParentTreeNode();
72 // if(parent instanceof Classification){
73 // parentNodeUuid = ((Classification) parent).getRootNode().getUuid();
76 // parentNodeUuid = parent.getUuid();
79 result
= CdmStore
.getService(ITaxonNodeService
.class).saveNewTaxonNode(getEntity());
81 this.setEntity((TaxonNode
)result
.getCdmEntity());
82 CdmApplicationState
.getCurrentDataChangeService()
83 .fireChangeEvent(new CdmChangeEvent(Action
.Create
, result
.getUpdatedObjects(), NewTaxonNodeWizard
.class), true);
87 if (!result
.getExceptions().isEmpty()){
88 MessagingUtils
.error(getClass(), "Taxon could not be created", result
.getExceptions().iterator().next());
90 MessagingUtils
.warn(getClass(), "Taxon could not be created");
94 }catch(IllegalArgumentException e
){
95 MessagingUtils
.warningDialog("Taxon already exists in classfication", getClass(), e
.getMessage());
101 protected TaxonNode
createNewEntity() {
102 if(getSelection() != null){
103 Object selectedObject
= getSelection().getFirstElement();
104 if(selectedObject
instanceof TaxonNodeDto
){
105 TaxonNodeDto taxonNodeDto
= (TaxonNodeDto
) selectedObject
;
106 TaxonNode node
= CdmStore
.getService(ITaxonNodeService
.class).load(taxonNodeDto
.getUuid());
107 Reference sec
= node
.getTaxon() != null? node
.getTaxon().getSec():null;
108 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewNameInstance(PreferencesUtil
.getPreferredNomenclaturalCode(), null), sec
);
109 TaxonNode child
= node
.addChildTaxon(newTaxon
, null, null);
127 public boolean openInEditor() {
128 return isOpenInEditor
;
131 public void setOpenInEditor(boolean isOpenInEditor
) {
132 this.isOpenInEditor
= isOpenInEditor
;
140 public boolean openEmpty(){
141 return openInEditor() && openEmptyEditor
;
145 * <p>getTaxonNode</p>
147 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
149 public TaxonNode
getTaxonNode(){
150 if(generatedTaxonNodeUuid
!= null){
151 return CdmStore
.getService(ITaxonNodeService
.class).load(generatedTaxonNodeUuid
);
156 public ITaxonTreeNode
getParentTreeNode(){
157 return taxonNodePage
.getParentTreeNode();
161 protected String
getEntityName() {
165 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
166 this.wizardPageListener
= wizardPageListener
;