Project

General

Profile

Download (5.29 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.newWizard;
10

    
11
import java.util.Map;
12
import java.util.UUID;
13

    
14
import javax.inject.Inject;
15

    
16
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
17
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
18
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
19
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
20
import eu.etaxonomy.cdm.api.service.UpdateResult;
21
import eu.etaxonomy.cdm.api.service.dto.CreateTaxonDTO;
22
import eu.etaxonomy.cdm.model.common.Language;
23
import eu.etaxonomy.cdm.model.common.LanguageString;
24
import eu.etaxonomy.cdm.model.reference.NamedSource;
25
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
28
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
29
import eu.etaxonomy.taxeditor.l10n.Messages;
30
import eu.etaxonomy.taxeditor.model.MessagingUtils;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
33
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
34

    
35
/**
36
 * NewTaxonNodeWizard class.
37
 *
38
 * @author n.hoffmann
39
 * @created Sep 15, 2009
40
 */
41
public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<TaxonNode>{
42

    
43
    private TaxonNodeWizardPage taxonNodePage;
44
    private boolean openEmptyEditor;
45
    private UUID generatedTaxonNodeUuid;
46
    private IWizardPageListener wizardPageListener;
47
    private boolean isOpenInEditor = false;
48
    private boolean success = true;
49

    
50
    @Inject
51
    public NewTaxonNodeWizard(){
52
        setWindowTitle(Messages.TaxonNodeWizardPage_new);
53
    }
54

    
55
    @Override
56
    public void addPages() {
57
        taxonNodePage = new TaxonNodeWizardPage(formFactory, getParentEntity(), wizardPageListener, true);
58
        addPage(taxonNodePage);
59
    }
60

    
61
    @Override
62
    protected void saveEntity() {
63
        CreateTaxonDTO taxon = taxonNodePage.createTaxon();
64
        if(taxon == null ){
65
            openEmptyEditor = true;
66
        }else{
67
           try{
68
             	UpdateResult result;
69
             	TaxonNode parent = getParentEntity();
70

    
71
             	Map<Language, LanguageString> notes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
72
             	NamedSource source = parent.getSource().checkEmpty()? null: parent.getSource();
73

    
74
             	TaxonNodeStatus status = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getTaxonNodeStatus();
75
             	if (status == null){
76
             	    notes = null;
77
             	}
78

    
79
             	result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(),
80
             	        taxon, source, parent.getMicroReference(), status, notes);
81

    
82

    
83
            	if (result.isOk()){
84
            	    this.setEntity((TaxonNode)result.getCdmEntity());
85
                    CdmApplicationState.getCurrentDataChangeService()
86
                             .fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
87

    
88
	             }else{
89
	                 setSuccess(false);
90
	                 if (!result.isOk()){
91
	                     if (!result.getExceptions().isEmpty()){
92
	                         MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
93
	                     }else{
94
	                         MessagingUtils.warn(getClass(), "Taxon could not be created");
95
	                     }
96

    
97
	                 }
98
	             }
99
          }catch(IllegalArgumentException e){
100
                MessagingUtils.warningDialog("Taxon already exists in classfication", getClass(), e.getMessage());
101
            }
102
        }
103
    }
104

    
105
    public boolean openInEditor() {
106
        return isOpenInEditor ;
107
    }
108

    
109
    public void setOpenInEditor(boolean isOpenInEditor) {
110
        this.isOpenInEditor = isOpenInEditor;
111
    }
112

    
113
    public boolean openEmpty(){
114
        return openInEditor() && openEmptyEditor;
115
    }
116

    
117
    public TaxonNode getTaxonNode(){
118
        if(generatedTaxonNodeUuid != null){
119
            return CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
120
        }
121
        return null;
122
    }
123

    
124
    public ITaxonTreeNode getParentTreeNode(){
125
        return taxonNodePage.getParentTreeNode();
126
    }
127

    
128
    @Override
129
    protected String getEntityName() {
130
        return "Taxon";
131
    }
132

    
133
    public void addWizardPageListener(IWizardPageListener wizardPageListener){
134
        this.wizardPageListener = wizardPageListener;
135
    }
136

    
137
    public boolean isSuccess() {
138
        return success;
139
    }
140

    
141
    public void setSuccess(boolean success) {
142
        this.success = success;
143
    }
144

    
145
    @Override
146
    public void createParentEntity() {
147
        Object selectedObject = getSelection().getFirstElement();
148
        if(selectedObject instanceof TaxonNodeDto){
149
            if(selectedObject instanceof TaxonNodeDto){
150
                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
151
                setParentEntity(CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid()));
152
            }
153
        }
154
    }
155
}
(21-21/28)