1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.newWizard;
|
5
|
|
6
|
import java.util.Map;
|
7
|
import java.util.UUID;
|
8
|
|
9
|
import javax.inject.Inject;
|
10
|
|
11
|
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
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
15
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
16
|
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
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
|
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.store.CdmStore;
|
26
|
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
|
28
|
|
29
|
/**
|
30
|
* <p>NewTaxonNodeWizard class.</p>
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Sep 15, 2009
|
34
|
*/
|
35
|
public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<TaxonNode>{
|
36
|
|
37
|
private TaxonNodeWizardPage taxonNodePage;
|
38
|
private boolean openEmptyEditor;
|
39
|
private UUID generatedTaxonNodeUuid;
|
40
|
private IWizardPageListener wizardPageListener;
|
41
|
private boolean isOpenInEditor = false;
|
42
|
private boolean success = true;
|
43
|
|
44
|
/**
|
45
|
* <p>Constructor for AbstractNewEntityWizard.</p>
|
46
|
*
|
47
|
* @param <T> a T object.
|
48
|
*/
|
49
|
@Inject
|
50
|
public NewTaxonNodeWizard(){
|
51
|
setWindowTitle(Messages.TaxonNodeWizardPage_new);
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public void addPages() {
|
56
|
taxonNodePage = new TaxonNodeWizardPage(formFactory, getConversationHolder(), getParentEntity(), wizardPageListener, true);
|
57
|
addPage(taxonNodePage);
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
protected void saveEntity() {
|
62
|
CreateTaxonDTO taxon = taxonNodePage.createTaxon();
|
63
|
if(taxon == null ){
|
64
|
openEmptyEditor = true;
|
65
|
}else{
|
66
|
getConversationHolder().bind();
|
67
|
try{
|
68
|
UpdateResult result;
|
69
|
TaxonNode parent = getParentEntity();
|
70
|
|
71
|
Map<Language, LanguageString> nodes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
|
72
|
UUID refUuid = parent.getReference() != null? parent.getReference().getUuid(): null;
|
73
|
|
74
|
TaxonNodeStatus status = null;
|
75
|
if( ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isUnplaced()){
|
76
|
status = TaxonNodeStatus.UNPLACED;
|
77
|
}else if( ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isPlacementDoubtful()){
|
78
|
status = TaxonNodeStatus.DOUBTFUL;
|
79
|
}else if (((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isExcluded()){
|
80
|
status = TaxonNodeStatus.EXCLUDED;
|
81
|
}
|
82
|
if (status == null){
|
83
|
nodes = null;
|
84
|
}
|
85
|
result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, refUuid, parent.getMicroReference(),
|
86
|
status, nodes);
|
87
|
|
88
|
|
89
|
if (result.isOk()){
|
90
|
this.setEntity((TaxonNode)result.getCdmEntity());
|
91
|
CdmApplicationState.getCurrentDataChangeService()
|
92
|
.fireChangeEvent(new CdmChangeEvent(Action.Create, result.getUpdatedObjects(), NewTaxonNodeWizard.class), true);
|
93
|
|
94
|
}else{
|
95
|
setSuccess(false);
|
96
|
if (!result.isOk()){
|
97
|
if (!result.getExceptions().isEmpty()){
|
98
|
MessagingUtils.error(getClass(), "Taxon could not be created", result.getExceptions().iterator().next());
|
99
|
}else{
|
100
|
MessagingUtils.warn(getClass(), "Taxon could not be created");
|
101
|
}
|
102
|
|
103
|
}
|
104
|
}
|
105
|
}catch(IllegalArgumentException e){
|
106
|
MessagingUtils.warningDialog("Taxon already exists in classfication", getClass(), e.getMessage());
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
// @Override
|
112
|
// protected TaxonNode createNewEntity() {
|
113
|
// if(getSelection() != null){
|
114
|
// Object selectedObject = getSelection().getFirstElement();
|
115
|
// if(selectedObject instanceof TaxonNodeDto){
|
116
|
// TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
|
117
|
// TaxonNode node = CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
|
118
|
// Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
|
119
|
// Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
|
120
|
// TaxonNode child = node.addChildTaxon(newTaxon, null, null);
|
121
|
//
|
122
|
// return child;
|
123
|
//
|
124
|
// }
|
125
|
// }
|
126
|
//
|
127
|
// return null;
|
128
|
// }
|
129
|
|
130
|
|
131
|
/**
|
132
|
* <p>
|
133
|
* openInEditor
|
134
|
* </p>
|
135
|
*
|
136
|
* @return a boolean.
|
137
|
*/
|
138
|
public boolean openInEditor() {
|
139
|
return isOpenInEditor ;
|
140
|
}
|
141
|
|
142
|
public void setOpenInEditor(boolean isOpenInEditor) {
|
143
|
this.isOpenInEditor = isOpenInEditor;
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* <p>openEmpty</p>
|
148
|
*
|
149
|
* @return a boolean.
|
150
|
*/
|
151
|
public boolean openEmpty(){
|
152
|
return openInEditor() && openEmptyEditor;
|
153
|
}
|
154
|
|
155
|
/**
|
156
|
* <p>getTaxonNode</p>
|
157
|
*
|
158
|
* @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
|
159
|
*/
|
160
|
public TaxonNode getTaxonNode(){
|
161
|
if(generatedTaxonNodeUuid != null){
|
162
|
return CdmStore.getService(ITaxonNodeService.class).load(generatedTaxonNodeUuid);
|
163
|
}
|
164
|
return null;
|
165
|
}
|
166
|
|
167
|
public ITaxonTreeNode getParentTreeNode(){
|
168
|
return taxonNodePage.getParentTreeNode();
|
169
|
}
|
170
|
|
171
|
@Override
|
172
|
protected String getEntityName() {
|
173
|
return "Taxon";
|
174
|
}
|
175
|
|
176
|
public void addWizardPageListener(IWizardPageListener wizardPageListener){
|
177
|
this.wizardPageListener = wizardPageListener;
|
178
|
}
|
179
|
|
180
|
|
181
|
public boolean isSuccess() {
|
182
|
return success;
|
183
|
}
|
184
|
|
185
|
|
186
|
public void setSuccess(boolean success) {
|
187
|
this.success = success;
|
188
|
}
|
189
|
|
190
|
@Override
|
191
|
public void createParentEntity() {
|
192
|
Object selectedObject = getSelection().getFirstElement();
|
193
|
if(selectedObject instanceof TaxonNodeDto){
|
194
|
if(selectedObject instanceof TaxonNodeDto){
|
195
|
TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
|
196
|
setParentEntity(CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid()));
|
197
|
}
|
198
|
}
|
199
|
}
|
200
|
|
201
|
|
202
|
}
|