Project

General

Profile

Download (6.22 KB) Statistics
| Branch: | Tag: | Revision:
1 f211dd28 n.hoffmann
/**
2 f6a8dc56 Patric Plitzner
 *
3 f211dd28 n.hoffmann
 */
4
package eu.etaxonomy.taxeditor.newWizard;
5
6 2c6df741 Katja Luther
import java.util.Map;
7 f211dd28 n.hoffmann
import java.util.UUID;
8
9 3c401181 Katja Luther
import javax.inject.Inject;
10
11 b13da0b9 Cherian Mathew
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 f211dd28 n.hoffmann
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
15 5b03e061 Katja Luther
import eu.etaxonomy.cdm.api.service.UpdateResult;
16 2c6df741 Katja Luther
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 eccc9d31 Katja Luther
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
20 f6a8dc56 Patric Plitzner
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
21 f211dd28 n.hoffmann
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22 c929d34b Katja Luther
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
23 795080d7 Katja Luther
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
24 3c401181 Katja Luther
import eu.etaxonomy.taxeditor.l10n.Messages;
25 41e2f693 Cherian Mathew
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.store.CdmStore;
27 2c6df741 Katja Luther
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
28 f211dd28 n.hoffmann
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
29
30
/**
31
 * <p>NewTaxonNodeWizard class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created Sep 15, 2009
35
 */
36 2c6df741 Katja Luther
public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<TaxonNode>{
37 f211dd28 n.hoffmann
38 b13da0b9 Cherian Mathew
    private TaxonNodeWizardPage taxonNodePage;
39
    private boolean openEmptyEditor;
40
    private UUID generatedTaxonNodeUuid;
41 750c0b1b Patric Plitzner
    private IWizardPageListener wizardPageListener;
42 d607cf23 Katja Luther
    private boolean isOpenInEditor = false;
43 d446db04 Katja Luther
    private boolean success = true;
44 f211dd28 n.hoffmann
45 3c401181 Katja Luther
    @Inject
46
    public NewTaxonNodeWizard(){
47
        setWindowTitle(Messages.TaxonNodeWizardPage_new);
48
    }
49
50 b13da0b9 Cherian Mathew
    @Override
51
    public void addPages() {
52 2c6df741 Katja Luther
        taxonNodePage = new TaxonNodeWizardPage(formFactory, getConversationHolder(), getParentEntity(), wizardPageListener, true);
53 b13da0b9 Cherian Mathew
        addPage(taxonNodePage);
54
    }
55
56
    @Override
57
    protected void saveEntity() {
58 2c6df741 Katja Luther
        CreateTaxonDTO taxon = taxonNodePage.createTaxon();
59
        if(taxon == null ){
60 b13da0b9 Cherian Mathew
            openEmptyEditor = true;
61
        }else{
62
            getConversationHolder().bind();
63
            try{
64 2c6df741 Katja Luther
             	UpdateResult result;
65
             	TaxonNode parent = getParentEntity();
66 b7797c35 Katja Luther
67 fee89c0b Andreas Müller
             	Map<Language, LanguageString> notes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
68 eccc9d31 Katja Luther
             	DescriptionElementSource source = parent.getSource().checkEmpty()? null: parent.getSource();
69
70 2c6df741 Katja Luther
71 fee89c0b Andreas Müller
             	TaxonNodeStatus status = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getTaxonNodeStatus();
72 b7797c35 Katja Luther
             	if (status == null){
73 fee89c0b Andreas Müller
             	    notes = null;
74 b7797c35 Katja Luther
             	}
75 de6b6edb Katja Luther
             	if (taxonNodePage.getExistingTaxon() != null){
76
             	    result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxonNodePage.getExistingTaxon().getUuid(), null, null);
77
             	}else{
78
             	    result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, source, parent.getMicroReference(),
79 fee89c0b Andreas Müller
            	         status, notes);
80 de6b6edb Katja Luther
             	}
81 c929d34b Katja Luther
82 d3b9767b Katja Luther
            	if (result.isOk()){
83 18960c83 Katja Luther
            	    this.setEntity((TaxonNode)result.getCdmEntity());
84 d4de1459 Katja Luther
                    CdmApplicationState.getCurrentDataChangeService()
85
                             .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
86 396bb36e Patrick Plitzner
87 d3b9767b Katja Luther
	             }else{
88 d446db04 Katja Luther
	                 setSuccess(false);
89 d3b9767b Katja Luther
	                 if (!result.isOk()){
90
	                     if (!result.getExceptions().isEmpty()){
91
	                         MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
92
	                     }else{
93
	                         MessagingUtils.warn(getClass(), "Taxon could not be created");
94
	                     }
95 d446db04 Katja Luther
96 d3b9767b Katja Luther
	                 }
97
	             }
98
          }catch(IllegalArgumentException e){
99 b13da0b9 Cherian Mathew
                MessagingUtils.warningDialog("Taxon already exists in classfication", getClass(), e.getMessage());
100
            }
101
        }
102
    }
103
104 2c6df741 Katja Luther
//    @Override
105
//    protected TaxonNode createNewEntity() {
106
//        if(getSelection() != null){
107
//            Object selectedObject = getSelection().getFirstElement();
108
//            if(selectedObject instanceof TaxonNodeDto){
109
//                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
110
//            	TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
111
//            	Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
112
//            	Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
113
//            	TaxonNode child = node.addChildTaxon(newTaxon, null, null);
114
//
115
//                return child;
116
//
117
//            }
118
//        }
119
//
120
//        return null;
121
//    }
122 b13da0b9 Cherian Mathew
123 d607cf23 Katja Luther
    public boolean openInEditor() {
124
        return isOpenInEditor ;
125
    }
126
127
    public void setOpenInEditor(boolean isOpenInEditor) {
128
        this.isOpenInEditor = isOpenInEditor;
129 b13da0b9 Cherian Mathew
    }
130
131
    public boolean openEmpty(){
132
        return openInEditor() && openEmptyEditor;
133
    }
134
135
    public TaxonNode getTaxonNode(){
136
        if(generatedTaxonNodeUuid != null){
137
            return CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
138
        }
139
        return null;
140
    }
141
142
    public ITaxonTreeNode getParentTreeNode(){
143
        return taxonNodePage.getParentTreeNode();
144
    }
145
146
    @Override
147
    protected String getEntityName() {
148
        return "Taxon";
149
    }
150
151
    public void addWizardPageListener(IWizardPageListener wizardPageListener){
152
        this.wizardPageListener = wizardPageListener;
153
    }
154 750c0b1b Patric Plitzner
155 d446db04 Katja Luther
    public boolean isSuccess() {
156
        return success;
157
    }
158
159
    public void setSuccess(boolean success) {
160
        this.success = success;
161
    }
162
163 2c6df741 Katja Luther
    @Override
164
    public void createParentEntity() {
165
        Object selectedObject = getSelection().getFirstElement();
166
        if(selectedObject instanceof TaxonNodeDto){
167
            if(selectedObject instanceof TaxonNodeDto){
168
                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
169
                setParentEntity(CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid()));
170
            }
171
        }
172
    }
173 e3240965 Andreas Kohlbecker
}