Project

General

Profile

« Previous | Next » 

Revision 2c6df741

Added by Katja Luther almost 4 years ago

ref #8857: move taxon creation to server

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/AbstractNewEntityWizardParentChild.java
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

  
10
package eu.etaxonomy.taxeditor.newWizard;
11

  
12
import org.eclipse.e4.ui.workbench.IWorkbench;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.swt.widgets.Display;
16

  
17
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22

  
23
/**
24
 *
25
 * @author n.hoffmann
26
 * @created Jun 1, 2010
27
 * @version 1.0
28
 */
29
public abstract class AbstractNewEntityWizardParentChild<T> extends Wizard implements
30
		IConversationEnabled {
31

  
32
	private ConversationHolder conversation;
33

  
34
	protected CdmFormFactory formFactory;
35

  
36
	private T parentEntity;
37
	private T entity;
38
	private boolean finished = false;
39

  
40

  
41
	private IStructuredSelection selection;
42

  
43
	public AbstractNewEntityWizardParentChild(){
44
		setWindowTitle(String.format("New %s", getEntityName()));
45
	}
46

  
47
	/**
48
	 * FIXME there might be a smarter way to do this,
49
	 *
50
	 * @return
51
	 */
52
	protected abstract String getEntityName();
53

  
54
	/** {@inheritDoc} */
55
	@Override
56
	public boolean performFinish() {
57
	    if (finished){
58
	        return true;
59
	    }
60
		saveEntity();
61

  
62
		conversation.commit();
63
		conversation.close();
64
		conversation = null;
65

  
66
		finished = true;
67
		return true;
68
	}
69

  
70
	public T getParentEntity() {
71
		return parentEntity;
72
	}
73

  
74
	public void setParentEntity(T entity){
75
		this.parentEntity = entity;
76
	}
77

  
78
	public T getEntity() {
79
        return entity;
80
    }
81

  
82
    public void setEntity(T entity){
83
        this.entity = entity;
84
    }
85

  
86

  
87
	/**
88
	 * Adds the entity to the current persistence context
89
	 */
90
	protected abstract void saveEntity();
91

  
92
	/** {@inheritDoc} */
93
	public void init(IWorkbench workbench, IStructuredSelection selection) {
94
	    formFactory = new CdmFormFactory(Display.getCurrent(), null);
95
	    conversation = CdmStore.createConversation();
96
	    this.selection = selection;
97

  
98
	    createParentEntity();
99

  
100

  
101
	}
102

  
103

  
104

  
105
	protected abstract void createParentEntity();
106

  
107
	@Override
108
    public ConversationHolder getConversationHolder() {
109
		return conversation;
110
	}
111

  
112
	/** {@inheritDoc} */
113
	@Override
114
    public void update(CdmDataChangeMap changeEvents) {}
115

  
116
	public IStructuredSelection getSelection() {
117
		return selection;
118
	}
119
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
3 3
 */
4 4
package eu.etaxonomy.taxeditor.newWizard;
5 5

  
6
import java.util.Map;
6 7
import java.util.UUID;
7 8

  
8 9
import javax.inject.Inject;
9 10

  
10
import org.apache.commons.lang.StringUtils;
11

  
12 11
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
13 12
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
14 13
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
15 14
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
16 15
import eu.etaxonomy.cdm.api.service.UpdateResult;
17
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
18
import eu.etaxonomy.cdm.model.reference.Reference;
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 19
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
21 20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
22 21
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
23 22
import eu.etaxonomy.taxeditor.l10n.Messages;
24 23
import eu.etaxonomy.taxeditor.model.MessagingUtils;
25
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
26 24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
27 26
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeWizardPage;
28 27

  
29 28
/**
......
32 31
 * @author n.hoffmann
33 32
 * @created Sep 15, 2009
34 33
 */
35
public class NewTaxonNodeWizard extends AbstractNewEntityWizard<TaxonNode>{
34
public class NewTaxonNodeWizard extends AbstractNewEntityWizardParentChild<TaxonNode>{
36 35

  
37 36
    private TaxonNodeWizardPage taxonNodePage;
38 37
    private boolean openEmptyEditor;
......
53 52

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

  
60 59
    @Override
61 60
    protected void saveEntity() {
62
        Taxon taxon = taxonNodePage.createTaxon();
63
        if(taxon == null || StringUtils.isEmpty(taxon.getName().getFullTitleCache())){
61
        CreateTaxonDTO taxon = taxonNodePage.createTaxon();
62
        if(taxon == null ){
64 63
            openEmptyEditor = true;
65 64
        }else{
66 65
            getConversationHolder().bind();
67
//            ITaxonTreeNode parent = getParentTreeNode();
68 66
            try{
69
            	UUID parentNodeUuid;
70
//            	if(parent instanceof Classification){
71
//            	    parentNodeUuid = ((Classification) parent).getRootNode().getUuid();
72
//            	}
73
//            	else{
74
//            	    parentNodeUuid = parent.getUuid();
75
//            	}
76
            	UpdateResult result;
77
            	result = CdmStore.getService(ITaxonNodeService.class).saveNewTaxonNode(getEntity());
67
             	UpdateResult result;
68
             	TaxonNode parent = getParentEntity();
69
             	Map<Language, LanguageString> nodes = ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).getMultiLanguageTextExcludedNotes();
70
             	UUID refUuid = parent.getReference() != null? parent.getReference().getUuid(): null;
71

  
72
            	result = CdmStore.getService(ITaxonNodeService.class).createNewTaxonNode(parent.getUuid(), taxon, refUuid, parent.getMicroReference(), ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isUnplaced(), ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isPlacementDoubtful(), ((TaxonNodeDetailElement)taxonNodePage.getDetailElement()).isExcluded(), nodes);
78 73
            	if (result.isOk()){
79 74
            	    this.setEntity((TaxonNode)result.getCdmEntity());
80 75
            	    CdmApplicationState.getCurrentDataChangeService()
......
97 92
        }
98 93
    }
99 94

  
100
    @Override
101
    protected TaxonNode createNewEntity() {
102
        if(getSelection() != null){
103
            Object selectedObject = getSelection().getFirstElement();
104
            if(selectedObject instanceof TaxonNodeDto){
105
                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
106
            	TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
107
            	Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
108
            	Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
109
            	TaxonNode child = node.addChildTaxon(newTaxon, null, null);
110

  
111
                return child;
112

  
113
            }
114
        }
115

  
116
        return null;
117
    }
95
//    @Override
96
//    protected TaxonNode createNewEntity() {
97
//        if(getSelection() != null){
98
//            Object selectedObject = getSelection().getFirstElement();
99
//            if(selectedObject instanceof TaxonNodeDto){
100
//                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
101
//            	TaxonNode node =  CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid());
102
//            	Reference sec = node.getTaxon() != null? node.getTaxon().getSec():null;
103
//            	Taxon newTaxon = Taxon.NewInstance(TaxonNameFactory.NewNameInstance(PreferencesUtil.getPreferredNomenclaturalCode(), null), sec);
104
//            	TaxonNode child = node.addChildTaxon(newTaxon, null, null);
105
//
106
//                return child;
107
//
108
//            }
109
//        }
110
//
111
//        return null;
112
//    }
118 113

  
119 114

  
120 115
    /**
......
176 171
        this.success = success;
177 172
    }
178 173

  
174
    @Override
175
    public void createParentEntity() {
176
        Object selectedObject = getSelection().getFirstElement();
177
        if(selectedObject instanceof TaxonNodeDto){
178
            if(selectedObject instanceof TaxonNodeDto){
179
                TaxonNodeDto taxonNodeDto = (TaxonNodeDto) selectedObject;
180
                setParentEntity(CdmStore.getService(ITaxonNodeService.class).load(taxonNodeDto.getUuid()));
181
            }
182
        }
183
    }
179 184

  
180 185

  
181 186
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.ui.section.classification;
11 11

  
12
import java.util.HashMap;
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.Map;
13 15

  
14 16
import org.apache.commons.lang.StringUtils;
17
import org.eclipse.swt.SWT;
15 18
import org.eclipse.swt.widgets.Control;
16 19
import org.eclipse.swt.widgets.Text;
17 20

  
......
25 28
import eu.etaxonomy.cdm.model.name.TaxonName;
26 29
import eu.etaxonomy.cdm.model.reference.Reference;
27 30
import eu.etaxonomy.cdm.model.taxon.Classification;
28
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
29 31
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31 33
import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache;
32 34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
33 36
import eu.etaxonomy.taxeditor.store.StoreUtil;
34 37
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
35 38
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
36 39
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
40
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
37 41
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
38 42
import eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement;
39 43
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
......
50 54
public class TaxonNodeDetailElement extends AbstractCdmDetailElement<TaxonNode> {
51 55

  
52 56
    private boolean createNew = false;
53

  
54
//	private EntitySelectionElement<Classification> selection_classification;
55

  
56 57
	private Classification classification;
58
	private TaxonNode parentNode;
59
	private Taxon taxon;
57 60

  
58 61
	private TaxonNodeSelectionElement selection_parentTaxonNode;
59

  
60
	private TaxonNode parentTreeNode;
61

  
62 62
	private EntitySelectionElement<Taxon> selection_reuseExistingTaxon;
63
	private EntitySelectionElement<Reference> selection_SecRef;
63
	private EntitySelectionElement<TaxonName> selection_reuseExistingName;
64

  
65
    private EntitySelectionElement<Reference> selection_SecRef;
64 66
	private EntitySelectionElement<Reference> selection_Ref;
65
	TextWithLabelElement textTaxonSec;
67

  
68

  
69
    TextWithLabelElement textTaxonSec;
70

  
66 71
	private TextWithLabelElement microReference;
67 72

  
68
	private Taxon taxon;
69 73

  
70
	private TextWithLabelElement textNewTaxonName;
74
    private TextWithLabelElement textNewTaxonName;
71 75

  
72 76
	private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
73 77

  
74
//	private CheckboxElement checkbox_openInEditor;
75

  
76 78
	private CheckboxElement checkbox_unplaced;
77

  
78 79
	private CheckboxElement checkbox_excluded;
79 80
	private CheckboxElement checkbox_publish;
80 81
	private CheckboxElement checkbox_placementDoubtful;
81 82

  
82

  
83

  
84 83
    private MultilanguageTextElement multiLanguageTextExcludedNotes;
85 84

  
86
//	private boolean openInEditor;
87 85

  
88 86
	private boolean complete;
89 87

  
......
91 89
	private boolean unplaced = false;
92 90
	private boolean placementDoubtful = false;
93 91

  
94
	private EntitySelectionElement<TaxonName> selection_reuseExistingName;
92

  
95 93

  
96 94
	public TaxonNodeDetailElement(CdmFormFactory formFactory,
97 95
			ICdmFormElement formElement, boolean isCreateNew) {
......
100 98
	}
101 99

  
102 100

  
101
	public Map<Language, LanguageString> getMultiLanguageTextExcludedNotes() {
102
        return multiLanguageTextExcludedNotes.getMultilanguageText();
103
    }
104

  
105

  
106

  
107
    public boolean isExcluded() {
108
        return excluded;
109
    }
110

  
111

  
112

  
113
    public boolean isUnplaced() {
114
        return unplaced;
115
    }
116

  
117

  
118

  
119
    public boolean isPlacementDoubtful() {
120
        return placementDoubtful;
121
    }
122

  
123
    public Reference getRef() {
124
        return selection_Ref.getEntity();
125
    }
126
    public TaxonName getExistingName() {
127
        return selection_reuseExistingName.getEntity();
128
    }
129
    public String getMicroReference() {
130
        return microReference.getText();
131
    }
103 132

  
104 133
	/** {@inheritDoc} */
105 134
	@Override
106 135
	protected void createControls(ICdmFormElement formElement,
107 136
	        TaxonNode entity, int style) {
108
	    taxon = entity.getTaxon();
109
	    if (isCreateNew()){
110
//    		selection_classification = formFactory
111
//    				.createSelectionElement(Classification.class,//getConversationHolder(),
112
//    				        formElement, "Classification",
113
//    						null, EntitySelectionElement.DELETABLE, style);
137
//	    taxon = entity.getTaxon();
114 138

  
139
	    if (isCreateNew()){
140
//	        setParentTreeNode(entity);
115 141
    		selection_parentTaxonNode = formFactory
116
    				.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentTreeNode,
142
    				.createTaxonNodeSelectionElement(getConversationHolder(), formElement, "Parent", parentNode,
117 143
    						EntitySelectionElement.DELETABLE, style, 100);
118 144

  
119

  
120

  
121 145
    		selection_Ref = formFactory
122 146
                    .createSelectionElement(Reference.class,
123 147
                            formElement, "Parent Child Relation Source", null,
124 148
                            EntitySelectionElement.DELETABLE, style, 100);
125 149

  
126

  
127 150
            microReference = formFactory.createTextWithLabelElement(formElement,"Detail", "", style);
128
            microReference.setText(getEntity().getMicroReference());
151
            microReference.setText(parentNode.getMicroReference());
129 152

  
130 153
    		selection_reuseExistingTaxon = formFactory
131 154
    				.createSelectionElement(Taxon.class,//getConversationHolder(),
......
136 159
    		selection_reuseExistingName = formFactory
137 160
    				.createSelectionElement(TaxonName.class,//getConversationHolder(),
138 161
    				        formElement,
139
    						"Reuse existing name", taxon.getName(),
162
    						"Reuse existing name", taxon != null? taxon.getName(): null,
140 163
    						EntitySelectionElement.DELETABLE, style);
141 164
    		selection_SecRef = formFactory
142 165
                    .createSelectionElement(Reference.class,//getConversationHolder(),
143
                            formElement, "Secundum Reference", taxon.getSec(),
166
                            formElement, "Secundum Reference", taxon != null? taxon.getSec(): null,
144 167
                            EntitySelectionElement.DELETABLE, style, 100);
145 168

  
146 169
    		if (isCreateNew()){
......
151 174

  
152 175
    		}
153 176
	    }else{
177
	        taxon = getEntity().getTaxon();
154 178
	        if (entity.getParent().getTaxon() == null){
155 179
	            TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Classification", entity.getClassification().getTitleCache(), style);
156 180
                textParent.setEnabled(false);
......
158 182
	            TextWithLabelElement textParent = formFactory.createTextWithLabelElement(formElement,"Parent", entity.getParent().getTaxon().getTitleCache(), style);
159 183
	            textParent.setEnabled(false);
160 184
	        }
161
//	        TextWithLabelElement textTaxon = formFactory.createTextWithLabelElement(formElement,"Taxon", taxon.getTitleCache(), style);
162
//	        textTaxon.setEnabled(false);
185

  
163 186
	        selection_Ref = formFactory
164 187
                    .createSelectionElement(Reference.class,
165 188
                            formElement, "Parent Child Relation Source", null,
......
186 209
            if (entity.getReference() != null){
187 210
                selection_Ref.setEntity(entity.getReference());
188 211
            }
212

  
189 213
        }
190
        parentTreeNode = entity.getParent();
214

  
191 215

  
192 216

  
193 217

  
......
201 225

  
202 226

  
203 227
		if(isCreateNew()){
204
		   setParentTreeNode(entity.getParent());
228

  
205 229

  
206 230
		   String defaultPublish = PreferencesUtil.getStringValue(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
207 231
	        if (defaultPublish != null && defaultPublish.equals(PublishEnum.Publish.getKey())){
......
209 233
	        } else if (defaultPublish != null && defaultPublish.equals(PublishEnum.NotPublish.getKey())){
210 234
	            checkbox_publish.setSelection(false);
211 235
	        }else{
212
	            if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class) && ((TaxonNode)this.getParentTreeNode()).getTaxon() != null){
213
	                checkbox_publish.setSelection(((TaxonNode)this.getParentTreeNode()).getTaxon().isPublish());
236
	            if(this.getParentTreeNode() != null &&  this.getParentTreeNode().isInstanceOf(TaxonNode.class) && this.getParentTreeNode().getTaxon() != null){
237
	                checkbox_publish.setSelection(this.getParentTreeNode().getTaxon().isPublish());
214 238
	            }else{
215 239
	                checkbox_publish.setSelection(true);
216 240
	            }
......
218 242

  
219 243
	    } else{
220 244
            setTreeNode(entity);
221

  
222 245
            complete = true;
223 246
        }
224 247

  
......
229 252
		    preFillTaxonName();
230 253
		}
231 254

  
232
		if (entity instanceof TaxonNode) {
233
		    checkbox_excluded = formFactory.createCheckbox(formElement,
234
		            "Taxon is excluded", entity.isExcluded(), style);
235
		    multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
236
		    multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
237
		}else{
238
		    checkbox_excluded = formFactory.createCheckbox(formElement,
239
                    "Taxon is excluded", false, style);
240
		    multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", new HashMap<Language, LanguageString>(), 50, style);
241
            multiLanguageTextExcludedNotes.setEnabled(false);
242
		}
255
	    checkbox_excluded = formFactory.createCheckbox(formElement,
256
	            "Taxon is excluded", entity.isExcluded(), style);
257
	    multiLanguageTextExcludedNotes = formFactory.createMultiLanguageTextElement(formElement, "Excluded Notes", entity.getExcludedNote(), 50, style);
258
	    multiLanguageTextExcludedNotes.setEnabled(entity.isExcluded());
259

  
243 260
		if (!isCreateNew()){
244 261
		    selectionNodeAgentRelation = formFactory.createTaxonNodeAgentRelationCollectionSection(formElement, getConversationHolder(), StoreUtil.getSectionStyle(TaxonNodeAgentRelationCollectionSection.class, entity.getClass().getCanonicalName()));
245 262
		    selectionNodeAgentRelation.setEntity(entity);
......
249 266
	}
250 267

  
251 268
	private void preFillTaxonName() {
252
        if(getEntity() instanceof TaxonNode ){
253
            TaxonNode node = parentTreeNode;
254
            if(node.getTaxon()!=null){
255
                Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
256
                if(taxon.getName()!=null){
257
                    TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
258
                    if (!isCreateNew()){
259
                        textNewTaxonName.setText(name.getNameCache());
260
                    } else if( ! name.isSupraGeneric() && name.getRank() != null){
261
                        String taxonName = "";
262
                        if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
263
                            taxonName = name.getGenusOrUninomial();
264
                        }
265
                        else if(name.isSpecies() || name.isInfraSpecific() ){
266
                            taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
267
                        }
268
                        if (StringUtils.isNotBlank(taxonName)){
269
                        	textNewTaxonName.setText(taxonName + " ");
270
                        	if(textNewTaxonName.getMainControl() instanceof Text){
271
                        		Text text = (Text)textNewTaxonName.getMainControl();
272
                        		text.setSelection(textNewTaxonName.getText().length());
273
                        	}
274
                        }
269
        TaxonNode node = parentNode;
270
        if(node.getTaxon()!=null){
271
            Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
272
            if(taxon.getName()!=null){
273
                TaxonName name = HibernateProxyHelper.deproxy(node.getTaxon().getName());
274
                if (!isCreateNew()){
275
                    textNewTaxonName.setText(name.getNameCache());
276
                } else if( ! name.isSupraGeneric() && name.getRank() != null){
277
                    String taxonName = "";
278
                    if(name.isGenus() || name.isInfraGeneric()|| name.isSpeciesAggregate() ){
279
                        taxonName = name.getGenusOrUninomial();
280
                    }
281
                    else if(name.isSpecies() || name.isInfraSpecific() ){
282
                        taxonName = CdmUtils.concat(" ", name.getGenusOrUninomial(),name.getSpecificEpithet());
283
                    }
284
                    if (StringUtils.isNotBlank(taxonName)){
285
                    	textNewTaxonName.setText(taxonName + " ");
286
                    	if(textNewTaxonName.getMainControl() instanceof Text){
287
                    		Text text = (Text)textNewTaxonName.getMainControl();
288
                    		text.setSelection(textNewTaxonName.getText().length());
289
                    	}
275 290
                    }
276 291
                }
277 292
            }
278 293
        }
294

  
279 295
    }
280 296

  
281 297
	/** {@inheritDoc} */
......
290 306
		            if (isCreateNew()){
291 307
		               selection_SecRef.setEntity(getTaxon().getSec());
292 308
		            }else{
293
		                textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
309
		               textTaxonSec.setText((getTaxon().getSec().getTitleCache()));
294 310
		            }
295 311
		        }else{
296 312
		            if (isCreateNew()){
297 313
	                       selection_SecRef.setEntity(null);
298 314
	                    }else{
299
	                        textTaxonSec.setText("");
315
	                       textTaxonSec.setText("");
300 316
	                    }
301 317
		        }
302 318
		        checkbox_publish.setSelected(getTaxon().isPublish());
......
318 334
		}
319 335

  
320 336
        if (eventSource == selection_Ref) {
321
            getEntity().setReference(selection_Ref.getEntity());
337
            if(!isCreateNew()){
338
                getEntity().setReference(selection_Ref.getEntity());
339
            }
322 340
        }else if (eventSource == selection_SecRef) {
323
            taxon.setSec(selection_SecRef.getEntity());
341
            if (taxon != null){
342
                taxon.setSec(selection_SecRef.getEntity());
343
            }
324 344
        }else if (eventSource == microReference) {
325
            getEntity().setMicroReference(microReference.getText());
345
            if(!isCreateNew()){
346
                getEntity().setMicroReference(microReference.getText());
347
            }
326 348
        }  else if (eventSource == checkbox_publish) {
327
            taxon.setPublish(checkbox_publish.getSelection());
349
            if (taxon != null){
350
                taxon.setPublish(checkbox_publish.getSelection());
351
            }
328 352
        }
329 353

  
330 354
		if (eventSource == checkbox_excluded) {
331 355
            excluded = checkbox_excluded.getSelection();
332

  
333
            getEntity().setExcluded(excluded);
356
            if (!isCreateNew()){
357
                getEntity().setExcluded(excluded);
358
            }
334 359

  
335 360
            multiLanguageTextExcludedNotes.setEnabled(excluded);
336 361
        }
337 362
		if (eventSource == checkbox_unplaced) {
338 363
            unplaced = checkbox_unplaced.getSelection();
339
            getEntity().setUnplaced(unplaced);
364
            if (!isCreateNew()){
365
                getEntity().setUnplaced(unplaced);
366
            }
340 367

  
341 368
        }
342 369

  
343 370
		if (eventSource == checkbox_placementDoubtful) {
344 371
		    placementDoubtful = checkbox_placementDoubtful.getSelection();
345
            getEntity().setDoubtful(placementDoubtful);
372
		    if (!isCreateNew()){
373
		        getEntity().setDoubtful(placementDoubtful);
374
		    }
346 375

  
347 376
        }
348 377
		if (eventSource == textNewTaxonName) {
......
370 399

  
371 400

  
372 401

  
373
	public ITaxonTreeNode getParentTreeNode() {
374
		return parentTreeNode;
375
	}
376

  
377
	private void setClassification(Classification classification) {
378
		this.classification = classification;
379
		//setParentTreeNode(classification);
402
	public TaxonNode getParentTreeNode() {
403
		return parentNode;
380 404
	}
381 405

  
382
	private void setParentTreeNode(TaxonNode parentTreeNode) {
383
		this.parentTreeNode = parentTreeNode;
384

  
406
	public void setParentTreeNode(TaxonNode parentTreeNode) {
407
		this.parentNode = parentTreeNode;
408
		updateContent();
385 409
		if (parentTreeNode.getTaxon() == null) {
386 410
			classification = parentTreeNode.getClassification();
387
//			if (selection_classification != null){
388
//			    selection_classification.setEntity(classification);
389
//			}
390
			selection_parentTaxonNode.setEntity(classification.getRootNode());
391
			selection_parentTaxonNode.setClassification(classification);
392
			selection_SecRef.setEntity(classification.getReference());
411
			if (selection_parentTaxonNode != null){
412
    			selection_parentTaxonNode.setEntity(classification.getRootNode());
413
    			selection_parentTaxonNode.setClassification(classification);
414
    			selection_SecRef.setEntity(classification.getReference());
415
			}
393 416
		} else  {
394 417
			classification = HibernateProxyHelper
395 418
					.deproxy(parentTreeNode.getClassification());
396
//			if (selection_classification != null){
397
//			    selection_classification.setEntity(classification);
398
//			}
399
			selection_parentTaxonNode.setEntity(HibernateProxyHelper
400
                    .deproxy(parentTreeNode));
401
			selection_parentTaxonNode.setClassification(classification);
402
			selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
419
			if (selection_parentTaxonNode != null){
420
			    selection_parentTaxonNode.setEntity(HibernateProxyHelper.deproxy(parentTreeNode));
421
			    selection_parentTaxonNode.setClassification(classification);
422
	            selection_SecRef.setEntity(parentTreeNode.getTaxon().getSec());
423
			}
424

  
403 425

  
404 426
		}
405 427
	}
428
	@Override
429
	protected void updateControlStates(){
430
        Collection<Object> except = new ArrayList<Object>();
431
        for(ICdmFormElement formElement:getElements()){
432
            if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
433
                except.add(formElement);
434
            }
435
        }
436
        if (isCreateNew() ){
437
            enabled = true;
438
        }else{
439
            enabled = getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
440
        }
441
        setEnabled(enabled, except);
442
    }
406 443

  
407 444
	private void setTreeNode(TaxonNode treeNode) {
408 445
        classification = HibernateProxyHelper
409 446
                    .deproxy(treeNode.getClassification());
410 447
        if (isCreateNew()){
411
           //selection_classification.setEntity(classification);
412
            selection_parentTaxonNode.setEntity(treeNode.getParent());
413
            selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
414
            selection_SecRef.setEntity(treeNode.getTaxon().getSec());
448
           selection_parentTaxonNode.setEntity(treeNode.getParent());
449
           selection_parentTaxonNode.setClassification(treeNode.getParent().getClassification());
450
           selection_SecRef.setEntity(treeNode.getTaxon().getSec());
415 451
        }
416 452
	}
417 453

  
418 454
	private void setTaxon(Taxon taxon) {
419 455
		this.taxon = taxon;
420
		getEntity().setTaxon(taxon);
456
		if (!isCreateNew()){
457
		    getEntity().setTaxon(taxon);
458
		}
421 459
		this.set_publish(taxon.isPublish());
422 460
		if (isCreateNew()){
423 461
		    textNewTaxonName.setText(taxon.getName().getTitleCache());
......
445 483
		    if (textNewTaxonName.getText() == null || !taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
446 484
		    	 textNewTaxonName.setText(taxonName.getTitleCache());
447 485
		    }
448
		    getEntity().setTaxon(taxon);
449
//		    if (!taxonName.getTitleCache().trim().equals(textNewTaxonName.getText().trim())){
450
//		        textNewTaxonName.setText(taxonName.getTitleCache());
451
//		    }
486
		    if (!isCreateNew()){
487
		        getEntity().setTaxon(taxon);
488
		    }
489

  
452 490
		} else {
453 491
		    textNewTaxonName.setText(null);
454 492
		}
455 493
	}
456 494

  
457
//	private void setOpenInEditor(boolean openInEditor) {
458
//		this.openInEditor = openInEditor;
459
//	}
460

  
461 495
	public String getTaxonName() {
462 496
        return textNewTaxonName.getText();
463 497
    }
......
465 499
        return taxon;
466 500
    }
467 501

  
468
	public Reference getReference(){
502
	public Reference getSecReference(){
469 503
	    return selection_SecRef.getSelection();
470 504
	}
471 505

  
......
488 522
        return createNew;
489 523
    }
490 524

  
491

  
492

  
493 525
    public boolean is_publish() {
494 526
        boolean isPublishPreference = true;
495 527
        CdmPreference defaultPublish = CdmPreferenceCache.instance().get(PreferencePredicate.DefaultBehaviourForPublishFlag.getKey());
......
503 535
        this.checkbox_publish.setSelection(publish);
504 536
    }
505 537

  
538
    /**
539
     * Updates all widgets to display the latest data
540
     */
541
    @Override
542
    protected void updateContent() {
543
        removeElements();
544
        if (isCreateNew()){
545
            createControls(this, parentNode, SWT.NONE);
546
        }else{
547
            createControls(this, getEntity(), SWT.NONE);
548
        }
549
        updateControlStates();
550
    }
551

  
506 552

  
507 553
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeWizardPage.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.ui.section.classification;
11 11

  
12
import java.util.UUID;
13

  
12 14
import org.eclipse.jface.util.PropertyChangeEvent;
13 15
import org.eclipse.swt.SWT;
14 16
import org.eclipse.swt.widgets.Event;
15 17
import org.eclipse.swt.widgets.Listener;
16 18

  
17 19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.service.dto.CreateTaxonDTO;
18 21
import eu.etaxonomy.cdm.common.CdmUtils;
19
import eu.etaxonomy.cdm.model.name.INonViralName;
20
import eu.etaxonomy.cdm.model.name.TaxonName;
21
import eu.etaxonomy.cdm.model.reference.Reference;
22
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24 22
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25 23
import eu.etaxonomy.taxeditor.l10n.Messages;
26 24
import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
25
import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
27 26
import eu.etaxonomy.taxeditor.parser.ParseHandler;
28 27
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
29 28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
79 78
	@Override
80 79
	public TaxonNodeDetailElement createElement(ICdmFormElement rootElement) {
81 80
	    TaxonNodeDetailElement detailElement = formFactory.createTaxonNodeDetailElement(rootElement, this.isCreateNew);
82
		detailElement.setEntity(entity);
83

  
84
		formFactory.addPropertyChangeListener(this);
85 81
		if (isCreateNew){
86
		    detailElement.getMainControl().addListener(SWT.KeyDown, this);
82
		    detailElement.setParentTreeNode(((NewTaxonNodeWizard)getWizard()).getParentEntity());
83
		}else{
84
		    detailElement.setEntity(entity);
87 85
		}
86

  
87
		formFactory.addPropertyChangeListener(this);
88
//		if (isCreateNew){
89
//		    detailElement.getMainControl().addListener(SWT.KeyDown, this);
90
//		}
88 91
		return detailElement;
89 92
	}
90 93

  
......
131 134
	 *
132 135
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
133 136
	 */
134
	public ITaxonTreeNode getParentTreeNode() {
137
	public TaxonNode getParentTreeNode() {
135 138
		return ((TaxonNodeDetailElement) getDetailElement())
136 139
				.getParentTreeNode();
137 140
	}
138 141

  
139
	public Taxon createTaxon() {
140
	    Taxon taxon;
141
	    String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
142
	    Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
143
	    if (parseHandler == null){
144
            parseHandler = ParseHandler.NewInstance(null);
145
        }
146
        final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
147
		if (((TaxonNodeDetailElement) getDetailElement()).getTaxon() == null){
148
		    taxon = Taxon.NewInstance(parseReferencedName, reference);
149

  
150
		} else{
151
		    taxon = ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
152
		    if (taxon.getName().getId() == 0){
153
		        taxon.setName((TaxonName) parseReferencedName);
154
		    }
155
		    taxon.setSec(reference);
156

  
157
		}
158
		taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
159

  
160
        return taxon;
142
	public CreateTaxonDTO createTaxon() {
143

  
144
	    UUID nameUuid = null;
145
	    String taxonNameString = null;
146
	    if (((TaxonNodeDetailElement) getDetailElement()).getExistingName() != null){
147
	        nameUuid = ((TaxonNodeDetailElement) getDetailElement()).getExistingName().getUuid();
148
	    }else{
149
	        taxonNameString = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
150
	    }
151

  
152
	    UUID secUuid = null;
153
	    if (((TaxonNodeDetailElement) getDetailElement()).getSecReference() != null){
154
	        secUuid = ((TaxonNodeDetailElement) getDetailElement()).getSecReference().getUuid();
155
	    }
156
	    boolean isPublish = ((TaxonNodeDetailElement) getDetailElement()).is_publish();
157

  
158

  
159
	    CreateTaxonDTO createDto = new CreateTaxonDTO(nameUuid, secUuid,null,false, null,isPublish, taxonNameString);
160
//	    Taxon taxon;
161
//	    String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
162
//	    Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
163
//	    if (parseHandler == null){
164
//            parseHandler = ParseHandler.NewInstance(null);
165
//        }
166
//        final INonViralName parseReferencedName = parseHandler.parseAndResolveDuplicates(taxonName);
167
//		if (((TaxonNodeDetailElement) getDetailElement()).getTaxon() == null){
168
//		    taxon = Taxon.NewInstance(parseReferencedName, reference);
169
//
170
//		} else{
171
//		    taxon = ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
172
//		    if (taxon.getName().getId() == 0){
173
//		        taxon.setName((TaxonName) parseReferencedName);
174
//		    }
175
//		    taxon.setSec(reference);
176
//
177
//		}
178
//		taxon.setPublish( ((TaxonNodeDetailElement) getDetailElement()).is_publish());
179

  
180
        return createDto;
161 181
	}
162 182

  
163 183
	public TaxonNode getTaxonNode(){

Also available in: Unified diff