4 package eu
.etaxonomy
.taxeditor
.newWizard
;
6 import java
.util
.HashSet
;
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
.IClassificationService
;
16 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
17 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
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
.taxeditor
.model
.MessagingUtils
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.ui
.section
.classification
.TaxonNodeWizardPage
;
27 * <p>NewTaxonNodeWizard class.</p>
30 * @created Sep 15, 2009
33 public class NewTaxonNodeWizard
extends AbstractNewEntityWizard
<ITaxonTreeNode
>{
35 private TaxonNodeWizardPage taxonNodePage
;
36 private boolean openEmptyEditor
;
37 private UUID generatedTaxonNodeUuid
;
38 private IWizardPageListener wizardPageListener
;
41 public void addPages() {
42 taxonNodePage
= new TaxonNodeWizardPage(formFactory
, getConversationHolder(), getEntity(), wizardPageListener
);
43 addPage(taxonNodePage
);
47 protected void saveEntity() {
48 if(taxonNodePage
.getTaxon() == null || StringUtils
.isEmpty(taxonNodePage
.getTaxon().getName().getFullTitleCache())){
49 openEmptyEditor
= true;
51 getConversationHolder().bind();
52 ITaxonTreeNode parent
= getParentTreeNode();
53 Taxon taxon
= taxonNodePage
.getTaxon();
55 TaxonNode taxonNode
= parent
.addChildTaxon(taxon
, parent
.getReference(), parent
.getMicroReference());
56 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
57 taxonNode
= CdmStore
.getService(ITaxonNodeService
.class).merge(taxonNode
);
59 taxonNode
= CdmStore
.getService(ITaxonNodeService
.class).save(taxonNode
);
61 generatedTaxonNodeUuid
= taxonNode
.getUuid();
62 Set
<CdmBase
> affectedObjects
= new HashSet
<CdmBase
>();
63 //FIXME:Remoting Hack for now - need to generalise this
64 // by making the affected objects a set of ICdmBase
65 // Also, this needs to be moved to the new operations
68 TaxonNode parentNode
= taxonNode
.getParent();
69 if(parentNode
.getParent() == null) {
70 affectedObjects
.add(taxonNode
.getClassification());
73 if(parentNode
instanceof TaxonNode
) {
74 affectedObjects
.add(parentNode
);
77 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
78 CdmApplicationState
.getCurrentDataChangeService()
79 .fireChangeEvent(new CdmChangeEvent(Action
.Create
, affectedObjects
, NewTaxonNodeWizard
.class), true);
81 }catch(IllegalArgumentException e
){
82 MessagingUtils
.warningDialog("Taxon already exists in classfication", getClass(), e
.getMessage());
88 protected ITaxonTreeNode
createNewEntity() {
89 if(getSelection() != null){
90 Object selectedObject
= getSelection().getFirstElement();
91 if(selectedObject
instanceof ITaxonTreeNode
){
92 ITaxonTreeNode treeNode
= (ITaxonTreeNode
) selectedObject
;
94 if(treeNode
instanceof Classification
){
95 return CdmStore
.getService(IClassificationService
.class).load(treeNode
.getUuid());
97 else if(treeNode
instanceof TaxonNode
){
98 return CdmStore
.getService(ITaxonNodeService
.class).load(treeNode
.getUuid());
107 * <p>openInEditor</p>
111 public boolean openInEditor(){
112 return taxonNodePage
.openInEditor();
120 public boolean openEmpty(){
121 return openInEditor() && openEmptyEditor
;
125 * <p>getTaxonNode</p>
127 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
129 public TaxonNode
getTaxonNode(){
130 if(generatedTaxonNodeUuid
!= null){
131 return CdmStore
.getService(ITaxonNodeService
.class).load(generatedTaxonNodeUuid
);
136 public ITaxonTreeNode
getParentTreeNode(){
137 return taxonNodePage
.getParentTreeNode();
141 protected String
getEntityName() {
145 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
146 this.wizardPageListener
= wizardPageListener
;