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());
57 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
58 taxonNode
= CdmStore
.getService(ITaxonNodeService
.class).merge(taxonNode
);
60 taxonNode
= CdmStore
.getService(ITaxonNodeService
.class).save(taxonNode
);
62 generatedTaxonNodeUuid
= taxonNode
.getUuid();
64 Set
<CdmBase
> affectedObjects
= new HashSet
<CdmBase
>();
65 //FIXME:Remoting Hack for now - need to generalise this
66 // by making the affected objects a set of ICdmBase
67 // Also, this needs to be moved to the new operations
70 TaxonNode parentNode
= taxonNode
.getParent();
71 if(parentNode
.getParent() == null) {
72 affectedObjects
.add(taxonNode
.getClassification());
75 if(parentNode
instanceof TaxonNode
) {
76 affectedObjects
.add(parentNode
);
79 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
80 CdmApplicationState
.getCurrentDataChangeService()
81 .fireChangeEvent(new CdmChangeEvent(Action
.Create
, affectedObjects
, NewTaxonNodeWizard
.class), true);
83 }catch(IllegalArgumentException e
){
84 MessagingUtils
.warningDialog("Taxon already exists in classfication", getClass(), e
.getMessage());
90 protected ITaxonTreeNode
createNewEntity() {
91 if(getSelection() != null){
92 Object selectedObject
= getSelection().getFirstElement();
93 if(selectedObject
instanceof ITaxonTreeNode
){
94 ITaxonTreeNode treeNode
= (ITaxonTreeNode
) selectedObject
;
96 if(treeNode
instanceof Classification
){
97 return CdmStore
.getService(IClassificationService
.class).load(treeNode
.getUuid());
99 else if(treeNode
instanceof TaxonNode
){
100 return CdmStore
.getService(ITaxonNodeService
.class).load(treeNode
.getUuid());
109 * <p>openInEditor</p>
113 public boolean openInEditor(){
114 return taxonNodePage
.openInEditor();
122 public boolean openEmpty(){
123 return openInEditor() && openEmptyEditor
;
127 * <p>getTaxonNode</p>
129 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
131 public TaxonNode
getTaxonNode(){
132 if(generatedTaxonNodeUuid
!= null){
133 return CdmStore
.getService(ITaxonNodeService
.class).load(generatedTaxonNodeUuid
);
138 public ITaxonTreeNode
getParentTreeNode(){
139 return taxonNodePage
.getParentTreeNode();
143 protected String
getEntityName() {
147 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
148 this.wizardPageListener
= wizardPageListener
;