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;
43 private boolean success
= true;
46 * <p>Constructor for AbstractNewEntityWizard.</p>
48 * @param <T> a T object.
51 public NewTaxonNodeWizard(){
52 setWindowTitle(Messages
.TaxonNodeWizardPage_new
);
57 public void addPages() {
58 taxonNodePage
= new TaxonNodeWizardPage(formFactory
, getConversationHolder(), getEntity(), wizardPageListener
, true);
59 addPage(taxonNodePage
);
64 protected void saveEntity() {
65 Taxon taxon
= taxonNodePage
.createTaxon();
66 if(taxon
== null || StringUtils
.isEmpty(taxon
.getName().getFullTitleCache())){
67 openEmptyEditor
= true;
69 getConversationHolder().bind();
70 // ITaxonTreeNode parent = getParentTreeNode();
73 // if(parent instanceof Classification){
74 // parentNodeUuid = ((Classification) parent).getRootNode().getUuid();
77 // parentNodeUuid = parent.getUuid();
80 result
= CdmStore
.getService(ITaxonNodeService
.class).saveNewTaxonNode(getEntity());
82 this.setEntity((TaxonNode
)result
.getCdmEntity());
83 CdmApplicationState
.getCurrentDataChangeService()
84 .fireChangeEvent(new CdmChangeEvent(Action
.Create
, result
.getUpdatedObjects(), NewTaxonNodeWizard
.class), true);
89 if (!result
.getExceptions().isEmpty()){
90 MessagingUtils
.error(getClass(), "Taxon could not be created", result
.getExceptions().iterator().next());
92 MessagingUtils
.warn(getClass(), "Taxon could not be created");
97 }catch(IllegalArgumentException e
){
98 MessagingUtils
.warningDialog("Taxon already exists in classfication", getClass(), e
.getMessage());
104 protected TaxonNode
createNewEntity() {
105 if(getSelection() != null){
106 Object selectedObject
= getSelection().getFirstElement();
107 if(selectedObject
instanceof TaxonNodeDto
){
108 TaxonNodeDto taxonNodeDto
= (TaxonNodeDto
) selectedObject
;
109 TaxonNode node
= CdmStore
.getService(ITaxonNodeService
.class).load(taxonNodeDto
.getUuid());
110 Reference sec
= node
.getTaxon() != null? node
.getTaxon().getSec():null;
111 Taxon newTaxon
= Taxon
.NewInstance(TaxonNameFactory
.NewNameInstance(PreferencesUtil
.getPreferredNomenclaturalCode(), null), sec
);
112 TaxonNode child
= node
.addChildTaxon(newTaxon
, null, null);
130 public boolean openInEditor() {
131 return isOpenInEditor
;
134 public void setOpenInEditor(boolean isOpenInEditor
) {
135 this.isOpenInEditor
= isOpenInEditor
;
143 public boolean openEmpty(){
144 return openInEditor() && openEmptyEditor
;
148 * <p>getTaxonNode</p>
150 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
152 public TaxonNode
getTaxonNode(){
153 if(generatedTaxonNodeUuid
!= null){
154 return CdmStore
.getService(ITaxonNodeService
.class).load(generatedTaxonNodeUuid
);
159 public ITaxonTreeNode
getParentTreeNode(){
160 return taxonNodePage
.getParentTreeNode();
164 protected String
getEntityName() {
168 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
169 this.wizardPageListener
= wizardPageListener
;
173 public boolean isSuccess() {
178 public void setSuccess(boolean success
) {
179 this.success
= success
;