Project

General

Profile

« Previous | Next » 

Revision e4a9f18a

Added by Katja Luther about 5 years ago

ref #7680: refactor NewTaxonNodeWizard like other NewEntityWizards

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
12 12
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
13 13
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
14 14
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
15
import eu.etaxonomy.cdm.api.service.IClassificationService;
16 15
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
17
import eu.etaxonomy.cdm.api.service.ITaxonService;
18 16
import eu.etaxonomy.cdm.api.service.UpdateResult;
19 17
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
21 19
import eu.etaxonomy.cdm.model.reference.Reference;
22 20
import eu.etaxonomy.cdm.model.taxon.Classification;
23 21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
......
26 24
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
27 25
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
28 26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
29 28
import eu.etaxonomy.taxeditor.store.CdmStore;
30 29
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
31 30
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
......
37 36
 * @created Sep 15, 2009
38 37
 * @version 1.0
39 38
 */
40
public class NewTaxonNodeWizard extends AbstractNewEntityWizard<ITaxonTreeNode>{
39
public class NewTaxonNodeWizard extends AbstractNewEntityWizard<TaxonNode>{
41 40

  
42 41
    private TaxonNodeWizardPage taxonNodePage;
43 42
    private boolean openEmptyEditor;
......
71 70
            	    parentNodeUuid = parent.getUuid();
72 71
            	}
73 72

  
74
            	/*
75
            	 * for (HybridRelationship rel : childRelations){
76
           TaxonName name = rel.getHybridName();
77
           TaxonName parentName = rel.getParentName();
78
           nameService.saveOrUpdate(rel.getHybridName());
79
           nameService.save(rel.getParentName());
80
       }
81
            	 */
73

  
82 74
            	UpdateResult result;
83
            	if (!taxon.getName().getHybridChildRelations().isEmpty() || !taxon.getName().getHybridParentRelations().isEmpty()){
84
            	    Set<TaxonName> parentNames = new HashSet<>();
85
                    Set<TaxonName> childNames = new HashSet<>();
86
//                    for (HybridRelationship hybridRelationship: taxon.getName().getHybridChildRelations()){
87
//                        if (hybridRelationship.getParentName() != taxon.getName()){
88
//                            if (!hybridRelationship.getParentName().isPersited()){
89
//                                parentNames.add(hybridRelationship.getParentName());
90
//                            }
91
//                       }else {//if (hybridRelationship.getHybridName() != taxon.getName()){
92
//                           if (!hybridRelationship.getHybridName().isPersited()){
93
//                               childNames.add(hybridRelationship.getHybridName());
94
//                           }
95
//                        }
96
//                        for (HybridRelationship rel : taxon.getName().getHybridChildRelations()){
97
//                            TaxonName name = rel.getHybridName();
98
//                            TaxonName parentName = rel.getParentName();
99
//                            CdmStore.getService(INameService.class).save(rel.getHybridName());
100
//                            CdmStore.getService(INameService.class).save(rel.getParentName());
101
//                        }
102

  
103
//                    }
104

  
105
//                    for (HybridRelationship hybridRelationship: taxon.getName().getHybridParentRelations()){
106
//                        if (hybridRelationship.getParentName() != taxon.getName()){
107
//                            if (!hybridRelationship.getParentName().isPersited()){
108
//                                parentNames.add(hybridRelationship.getParentName());
109
//                            }
110
//                       }else {//if (hybridRelationship.getHybridName() != taxon.getName()){
111
//                           if (!hybridRelationship.getHybridName().isPersited()){
112
//                               childNames.add(hybridRelationship.getHybridName());
113
//                           }
114
//                        }
115
//
116
//                    }
117
//                    CdmStore.getService(INameService.class).save(childNames);
118
//                    CdmStore.getService(INameService.class).save(parentNames);
119

  
120
                }
75

  
121 76

  
122 77
            	if (taxon.getId() == 0){
123
            		result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon, parent.getReference(), parent.getMicroReference());
78
            	    //getEntity().setTaxon(taxon);
79
            		result = CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(getEntity());
80

  
124 81
            	}else{
125 82
            		result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parentNodeUuid, taxon.getUuid(), parent.getReference(), parent.getMicroReference());
126 83
            	}
......
166 123
    }
167 124

  
168 125
    @Override
169
    protected ITaxonTreeNode createNewEntity() {
126
    protected TaxonNode createNewEntity() {
170 127
        if(getSelection() != null){
171 128
            Object selectedObject = getSelection().getFirstElement();
172 129
            if(selectedObject instanceof TaxonNodeDto){
173 130
                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
174 131
            	TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
175
            	if(node.getTaxon()!=null){
176
            	    //FIXME this taxon is not used. Do we need this call?
177
            	    Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(node.getTaxon().getUuid());
178
            	}
179
            	else if(node.getClassification()!=null){
180
            	    return CdmStore.getService(IClassificationService.class).load(node.getClassification().getUuid());
181
            	}
182
                return node;
132
            	Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
133
            	Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
134
            	TaxonNode child = node.addChildTaxon(newTaxon, null, null);
135
//            	if(node.getTaxon()!=null){
136
//            	    //FIXME this taxon is not used. Do we need this call?
137
//            	    Taxon taxon = (Taxon) CdmStore.getService(ITaxonService.class).load(node.getTaxon().getUuid());
138
//            	}
139
//            	else if(node.getClassification()!=null){
140
//            	    return CdmStore.getService(IClassificationService.class).load(node.getClassification().getUuid());
141
//            	}
142
                return child;
183 143

  
184
            } else if(selectedObject instanceof Classification){
185
                return (Classification)selectedObject;
186 144
            }
187 145
        }
188 146

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/EditTaxonNodeWizard.java
9 9
package eu.etaxonomy.taxeditor.ui.section.classification;
10 10

  
11 11
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
12
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
13 12
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
14 13
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
15 14
import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
......
20 19
 * @date 23.03.2016
21 20
 *
22 21
 */
23
public class EditTaxonNodeWizard extends AbstractEditWizard<ITaxonTreeNode> {
22
public class EditTaxonNodeWizard extends AbstractEditWizard<TaxonNode> {
24 23

  
25 24
    private TaxonNodeWizardPage taxonNodePage;
26 25
    private IWizardPageListener wizardPageListener;
......
39 38
    @Override
40 39
    protected void saveEntity() {
41 40
        getConversationHolder().bind();
42
        TaxonNode node = (TaxonNode)getEntity();
41
        TaxonNode node = getEntity();
43 42

  
44 43
        MergeResult result = CdmStore.getService(ITaxonNodeService.class).merge(node, true);
45 44

  
......
59 58
     * @see eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard#setEntity(java.lang.Object)
60 59
     */
61 60
    @Override
62
    public void setEntity(ITaxonTreeNode entity) {
61
    public void setEntity(TaxonNode entity) {
63 62
        setWindowTitle(String.format("Edit %s", getEntityName()));
64 63
        entity = CdmStore.getService(ITaxonNodeService.class).load(entity.getUuid());
65 64
        super.setEntity(entity);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
45 45
 * @created Sep 27, 2010
46 46
 * @version 1.0
47 47
 */
48
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<ITaxonTreeNode> {
48
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
49 49

  
50 50
    private boolean createNew = false;
51 51

  
......
55 55

  
56 56
	private TaxonNodeSelectionElement selection_parentTaxonNode;
57 57

  
58
	private ITaxonTreeNode parentTreeNode;
58
	private TaxonNode parentTreeNode;
59 59

  
60 60
	private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
61 61
	private EntitySelectionElement<Reference> selection_SecRef;
......
99 99
	/** {@inheritDoc} */
100 100
	@Override
101 101
	protected void createControls(ICdmFormElement formElement,
102
	        ITaxonTreeNode entity, int style) {
102
	        TaxonNode entity, int style) {
103
	    taxon = entity.getTaxon();
103 104
	    if (isCreateNew()){
104 105
//    		selection_classification = formFactory
105 106
//    				.createSelectionElement(Classification.class,//getConversationHolder(),
106 107
//    				        formElement, "Classification",
107 108
//    						null, EntitySelectionElement.DELETABLE, style);
108 109
    		selection_parentTaxonNode = formFactory
109
    				.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", null,
110
    				.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
110 111
    						EntitySelectionElement.DELETABLE, style);
111 112

  
112 113
//    		selection_reuseExistingTaxon = formFactory
......
118 119
    		selection_reuseExistingName = formFactory
119 120
    				.createSelectionElement(TaxonName.class,//getConversationHolder(),
120 121
    				        formElement,
121
    						"Reuse existing name", null,
122
    						"Reuse existing name", taxon.getName(),
122 123
    						EntitySelectionElement.DELETABLE, style);
123 124
    		selection_SecRef = formFactory
124 125
                    .createSelectionElement(Reference.class,//getConversationHolder(),
125
                            formElement, "Secundum Reference", null,
126
                            formElement, "Secundum Reference", taxon.getSec(),
126 127
                            EntitySelectionElement.DELETABLE, style);
127 128

  
128 129
    		if (isCreateNew()){
......
133 134

  
134 135
    		}
135 136
	    }else{
136
	        TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", ((TaxonNode)entity).getClassification().getTitleCache(), style);
137
	        TextWithLabelElement textClassification = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
137 138
	        textClassification.setEnabled(false);
138 139

  
139
	        TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", ((TaxonNode)entity).getTaxon().getTitleCache(), style);
140
	        TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
140 141
	        textTaxon.setEnabled(false);
141 142

  
142 143
            TextWithLabelElement textTaxonSec = formFactory.createTextWithLabelElement(formElement,"Secundum Reference", "", style);
143
            if (((TaxonNode)entity).getTaxon().getSec() != null){
144
                textTaxonSec.setText(((TaxonNode)entity).getTaxon().getSec().getTitleCache());
144
            if (entity.getTaxon().getSec() != null){
145
                textTaxonSec.setText(taxon.getSec().getTitleCache());
145 146
            }
146 147
            textTaxonSec.setEnabled(false);
147 148

  
......
158 159
        if (!isCreateNew()){
159 160
            selection_Ref.setEntity(entity.getReference());
160 161
        }
161
		if (entity instanceof TaxonNode) {
162
        parentTreeNode = entity.getParent();
163
		if (entity instanceof TaxonNode && parentTreeNode.getTaxon() != null) {
162 164
		    checkbox_publish = formFactory.createCheckbox(formElement,
163
		            "Taxon is public", ((TaxonNode)entity).getTaxon().isPublish(), style);
165
		            "Taxon is public", parentTreeNode.getTaxon().isPublish(), style);
164 166
		}else{
165 167
		    checkbox_publish = formFactory.createCheckbox(formElement,
166 168
                    "Taxon is public", true, style);
167 169
		}
168 170
		checkbox_publish.setEnabled(isCreateNew());
169 171
		if(isCreateNew()){
170
		    setParentTreeNode(entity);
171
	        CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
172
		   setParentTreeNode(entity.getParent());
173
		   CdmPreference defaultPublish = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
172 174
	        if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.Publish.getKey())){
173 175
	            checkbox_publish.setSelection(true);
174 176
	        } else if (defaultPublish != null && defaultPublish.getValue().equals(PublishEnum.NotPublish.getKey())){
175 177
	            checkbox_publish.setSelection(false);
176 178
	        }else{
177
	            if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class)){
179
	            if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
178 180
	                checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
179 181
	            }else{
180 182
	                checkbox_publish.setSelection(true);
......
187 189
        }
188 190
		if (entity instanceof TaxonNode) {
189 191
		    checkbox_unplaced = formFactory.createCheckbox(formElement,
190
		            "Taxon is unplaced", ((TaxonNode)entity).isUnplaced(), style);
192
		            "Taxon is unplaced", entity.isUnplaced(), style);
191 193
		}else{
192 194
		    checkbox_unplaced = formFactory.createCheckbox(formElement,
193 195
                    "Taxon is unplaced", false, style);
......
198 200

  
199 201
		if (entity instanceof TaxonNode) {
200 202
		    checkbox_excluded = formFactory.createCheckbox(formElement,
201
		            "Taxon is excluded", ((TaxonNode)entity).isExcluded(), style);
202
		    multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", ((TaxonNode)entity).getExcludedNote(), 50, style);
203
		    multiLanguageTextExcludedNotes.setEnabled(((TaxonNode) entity).isExcluded());
203
		            "Taxon is excluded", entity.isExcluded(), style);
204
		    multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
205
		    multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
204 206
		}else{
205 207
		    checkbox_excluded = formFactory.createCheckbox(formElement,
206 208
                    "Taxon is excluded", false, style);
......
209 211
		}
210 212
		if (!isCreateNew()){
211 213
		    selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), style);
212
		    selectionNodeAgentRelation.setEntity((TaxonNode)entity);
214
		    selectionNodeAgentRelation.setEntity(entity);
213 215
		    selectionNodeAgentRelation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
214 216
		}
215 217
//		checkbox_openInEditor = formFactory.createCheckbox(formElement,
......
219 221

  
220 222
	private void preFillTaxonName() {
221 223
        if(getEntity() instanceof TaxonNode ){
222
            TaxonNode node = (TaxonNode)getEntity();
224
            TaxonNode node = parentTreeNode;
223 225
            if(node.getTaxon()!=null){
224 226
                Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
225 227
                if(taxon.getName()!=null){
......
250 252
	/** {@inheritDoc} */
251 253
	@Override
252 254
	public void handleEvent(Object eventSource) {
253
		if (eventSource == selection_classification) {
254
			setClassification(selection_classification.getEntity());
255
		} else if (eventSource == selection_parentTaxonNode) {
256
			setParentTreeNode(selection_parentTaxonNode.getEntity());
255
		if (eventSource == selection_parentTaxonNode) {
256
		    setParentTreeNode(selection_parentTaxonNode.getEntity());
257 257
		} else if (eventSource == selection_reuseExistingTaxon) {
258 258
				boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
259 259
				selection_reuseExistingName.setEnabled(enabled);
......
267 267

  
268 268
		} else if (eventSource == selection_reuseExistingName) {
269 269
		    boolean enabled = selection_reuseExistingName.getEntity() == null;
270
			setTaxon(selection_reuseExistingName.getEntity());
270
			setTaxon(HibernateProxyHelper.deproxy(selection_reuseExistingName.getEntity()));
271 271
			if (selection_reuseExistingTaxon != null){
272 272
			    selection_reuseExistingTaxon.setEnabled(enabled);
273 273
			}
274 274
			textNewTaxonName.setEnabled(enabled);
275

  
276 275
			complete = !textNewTaxonName.getText().isEmpty();
277 276
		}
278 277
		if (!isCreateNew()){
279 278
            if (eventSource == selection_Ref) {
280
                ((TaxonNode) getEntity()).setReference(selection_Ref.getEntity());
279
                getEntity().setReference(selection_Ref.getEntity());
281 280
            }else if (eventSource == selection_SecRef) {
282
                ((TaxonNode) getEntity()).getTaxon().setSec(selection_SecRef.getEntity());
281
                taxon.setSec(selection_SecRef.getEntity());
283 282
            }else if (eventSource == microReference) {
284
                ((TaxonNode) getEntity()).setMicroReference(microReference.getText());
283
                getEntity().setMicroReference(microReference.getText());
285 284
            }  else if (eventSource == checkbox_publish) {
286
                ((TaxonNode)getEntity()).getTaxon().setPublish(checkbox_publish.getSelection());
285
                taxon.setPublish(checkbox_publish.getSelection());
287 286
            }
288 287
		}
289 288
		if (eventSource == checkbox_excluded) {
290 289
            excluded = checkbox_excluded.getSelection();
291
            if (!isCreateNew()){
292
                ((TaxonNode)getEntity()).setExcluded(excluded);
293
            }
290

  
291
            getEntity().setExcluded(excluded);
292

  
294 293
            multiLanguageTextExcludedNotes.setEnabled(excluded);
295 294
        }
296 295
		if (eventSource == checkbox_unplaced) {
297 296
            unplaced = checkbox_unplaced.getSelection();
298
            if (!isCreateNew()){
299
                ((TaxonNode)getEntity()).setUnplaced(unplaced);
300
            }
297
            getEntity().setUnplaced(unplaced);
298

  
301 299
        }
302 300
		if (eventSource == textNewTaxonName) {
303 301
            boolean enabled = CdmUtils.isBlank(textNewTaxonName.getText());
......
334 332

  
335 333
	private void setClassification(Classification classification) {
336 334
		this.classification = classification;
337
		setParentTreeNode(classification);
335
		//setParentTreeNode(classification);
338 336
	}
339 337

  
340
	private void setParentTreeNode(ITaxonTreeNode parentTreeNode) {
338
	private void setParentTreeNode(TaxonNode parentTreeNode) {
341 339
		this.parentTreeNode = parentTreeNode;
342 340

  
343
		if (parentTreeNode instanceof Classification) {
344
			classification = (Classification) parentTreeNode;
341
		if (parentTreeNode.getTaxon() == null) {
342
			classification = parentTreeNode.getClassification();
345 343
			if (selection_classification != null){
346 344
			    selection_classification.setEntity(classification);
347 345
			}
348
			selection_parentTaxonNode.setEntity(null);
346
			selection_parentTaxonNode.setEntity(classification.getRootNode());
349 347
			selection_parentTaxonNode.setClassification(classification);
350 348
			selection_SecRef.setEntity(classification.getReference());
351
		} else if (parentTreeNode instanceof TaxonNode) {
349
		} else  {
352 350
			classification = HibernateProxyHelper
353
					.deproxy(((TaxonNode) parentTreeNode).getClassification());
351
					.deproxy(parentTreeNode.getClassification());
354 352
			if (selection_classification != null){
355 353
			    selection_classification.setEntity(classification);
356 354
			}
357 355
			selection_parentTaxonNode.setEntity(HibernateProxyHelper
358
                    .deproxy((TaxonNode) parentTreeNode));
356
                    .deproxy(parentTreeNode));
359 357
			selection_parentTaxonNode.setClassification(classification);
360
			selection_SecRef.setEntity(((TaxonNode)parentTreeNode).getTaxon().getSec());
361
		} else if(parentTreeNode == null){
362
			this.parentTreeNode = classification;
358
			selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
359

  
363 360
		}
364 361
	}
365 362

  
366
	private void setTreeNode(ITaxonTreeNode treeNode) {
363
	private void setTreeNode(TaxonNode treeNode) {
367 364
        classification = HibernateProxyHelper
368
                    .deproxy(((TaxonNode) treeNode).getClassification());
365
                    .deproxy(treeNode.getClassification());
369 366
        if (isCreateNew()){
370 367
           //selection_classification.setEntity(classification);
371
            selection_parentTaxonNode.setEntity(((TaxonNode) treeNode).getParent());
372
            selection_parentTaxonNode.setClassification(((TaxonNode) treeNode).getParent().getClassification());
373
            selection_SecRef.setEntity(((TaxonNode)treeNode).getTaxon().getSec());
368
            selection_parentTaxonNode.setEntity(treeNode.getParent());
369
            selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
370
            selection_SecRef.setEntity(treeNode.getTaxon().getSec());
374 371
        }
375 372
	}
376 373

  
377 374
	private void setTaxon(Taxon taxon) {
378 375
		this.taxon = taxon;
376
		getEntity().setTaxon(taxon);
379 377
		if (isCreateNew()){
380 378
		    textNewTaxonName.setText(taxon.getName().getTitleCache());
381 379
		}
......
394 392
		    if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
395 393
		    	 textNewTaxonName.setText(taxonName.getTitleCache());
396 394
		    }
395
		    getEntity().setTaxon(taxon);
397 396
//		    if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
398 397
//		        textNewTaxonName.setText(taxonName.getTitleCache());
399 398
//		    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeWizardPage.java
17 17
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18 18
import eu.etaxonomy.cdm.common.CdmUtils;
19 19
import eu.etaxonomy.cdm.model.name.INonViralName;
20
import eu.etaxonomy.cdm.model.name.TaxonName;
20 21
import eu.etaxonomy.cdm.model.reference.Reference;
21 22
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
22 23
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
35 36
 * @author n.hoffmann
36 37
 * @created Sep 15, 2009
37 38
 */
38
public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<ITaxonTreeNode> implements Listener{
39
public class TaxonNodeWizardPage extends AbstractCdmEntityWizardPage<TaxonNode> implements Listener{
39 40

  
40 41
    private final IWizardPageListener wizardPageListener;
41 42
    private final boolean isCreateNew;
......
59 60
     * @param closeOnEnterListener
60 61
	 */
61 62
	public TaxonNodeWizardPage(CdmFormFactory formFactory,
62
			ConversationHolder conversation, ITaxonTreeNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
63
			ConversationHolder conversation, TaxonNode entity, IWizardPageListener closeOnEnterListener, boolean isCreateNew) {
63 64
		super(formFactory, conversation, entity);
64 65
		this.wizardPageListener = closeOnEnterListener;
65 66
		setTitle("Edit taxon node");
......
73 74
	public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
74 75
	    TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement, this.isCreateNew);
75 76
		detailElement.setEntity(entity);
77

  
76 78
		formFactory.addPropertyChangeListener(this);
77 79
		if (isCreateNew){
78 80
		    detailElement.getMainControl().addListener(SWT.KeyDown, this);
......
129 131
	}
130 132

  
131 133
	public Taxon createTaxon() {
134
	    Taxon taxon;
135
	    String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
136
	    Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
137
	    if (parseHandler == null){
138
            parseHandler = ParseHandler.NewInstance(null);
139
        }
140
        final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
132 141
		if (((TaxonNodeDetailElement) getDetailElement()).getTaxon() == null){
133
			String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
134
			Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
135
			if (parseHandler == null){
136
			    parseHandler = ParseHandler.NewInstance(null);
137
			}
138
			final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
139

  
140
			Taxon taxon = Taxon.NewInstance(parseReferencedName, reference);
141
			taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
142
		    taxon = Taxon.NewInstance(parseReferencedName, reference);
142 143

  
143
			return taxon;
144 144
		} else{
145
			return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
145
		    taxon = ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
146
		    if (taxon.getName().getId() == 0){
147
		        taxon.setName((TaxonName) parseReferencedName);
148
		    }
149

  
146 150
		}
151
		taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
152

  
153
        return taxon;
147 154
	}
148 155

  
149 156
	public TaxonNode getTaxonNode(){
150
	   return (TaxonNode) ((TaxonNodeDetailElement) getDetailElement()).getEntity();
157
	   return ((TaxonNodeDetailElement) getDetailElement()).getEntity();
151 158
	}
152 159

  
153 160
	/** {@inheritDoc} */

Also available in: Unified diff