Project

General

Profile

« Previous | Next » 

Revision 0b9a76dd

Added by Patrick Plitzner about 6 years ago

Create taxon/parse name when wizard is closed and not with every key
stroke #5605

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonNodeWizard.java
48 48

  
49 49
    @Override
50 50
    protected void saveEntity() {
51
        if(taxonNodePage.getTaxon() == null || StringUtils.isEmpty(taxonNodePage.getTaxon().getName().getFullTitleCache())){
51
        Taxon taxon = taxonNodePage.createTaxon();
52
        if(taxon == null || StringUtils.isEmpty(taxon.getName().getFullTitleCache())){
52 53
            openEmptyEditor = true;
53 54
        }else{
54 55
            getConversationHolder().bind();
55 56
            ITaxonTreeNode parent = getParentTreeNode();
56
            Taxon taxon = taxonNodePage.getTaxon();
57 57
            Reference sec = taxon.getSec();
58 58
            taxon.setSec(null);
59 59
            try{
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeDetailElement.java
11 11
package eu.etaxonomy.taxeditor.ui.section.classification;
12 12

  
13 13
import org.apache.commons.lang.StringUtils;
14
import org.eclipse.swt.widgets.Control;
14 15
import org.eclipse.swt.widgets.Text;
15 16

  
16 17
import eu.etaxonomy.cdm.common.CdmUtils;
......
22 23
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
23 24
import eu.etaxonomy.cdm.model.taxon.Taxon;
24 25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.taxeditor.parser.ParseHandler;
26 26
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
27 27
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
28 28
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
......
55 55

  
56 56
	private Taxon taxon;
57 57

  
58
	private Reference secReference;
59

  
60 58
	private TextWithLabelElement textNewTaxonName;
61 59

  
62 60
	private TaxonNodeAgentRelationCollectionSection selectionNodeAgentRelation;
......
170 168
			setClassification(selection_classification.getEntity());
171 169
		} else if (eventSource == selection_parentTaxonNode) {
172 170
			setParentTreeNode(selection_parentTaxonNode.getEntity());
173
		} else if (eventSource == selection_SecRef) {
174
			setSecReference(selection_SecRef.getEntity());
175 171
		} else if (eventSource == selection_reuseExistingTaxon) {
176 172
				boolean enabled = selection_reuseExistingTaxon.getEntity() == null;
177 173
				selection_reuseExistingName.setEnabled(enabled);
......
203 199
			selection_reuseExistingTaxon.setEnabled(enabled);
204 200
			selection_reuseExistingName.setEnabled(enabled);
205 201

  
206
			setTaxon(textNewTaxonName.getText());
207 202
			complete = !textNewTaxonName.getText().isEmpty();
208 203
		} else if (eventSource == checkbox_openInEditor) {
209 204
			setOpenInEditor(checkbox_openInEditor.getSelection());
......
229 224
		return parentTreeNode;
230 225
	}
231 226

  
232
	public Taxon getTaxon() {
233
		return taxon;
234
	}
235

  
236 227
	private void setClassification(Classification classification) {
237 228
		this.classification = classification;
238 229
		setParentTreeNode(classification);
......
268 259
        selection_SecRef.setEntity(((TaxonNode)treeNode).getTaxon().getSec());
269 260
	}
270 261

  
271
	private void setSecReference(Reference secRef){
272
		this.secReference = secRef;
273
		setTaxon(textNewTaxonName.getText());
274
	}
275

  
276 262
	private void setTaxon(Taxon taxon) {
277 263
		this.taxon = taxon;
278 264
		if (isCreateNew()){
......
281 267
		selection_SecRef.setEntity(taxon.getSec());
282 268
	}
283 269

  
284
	private void setTaxon(String taxonNameString) {
285
		TaxonNameBase taxonName = ParseHandler.parseReferencedName(
286
				taxonNameString, null);
287
		setTaxon(taxonName);
288
	}
289

  
290 270
	private void setTaxon(TaxonNameBase taxonName) {
291 271
		Reference secundum = null;
292 272
		if (getParentTreeNode() != null) {
293 273
			if (this.selection_SecRef.getEntity() != null){
294 274
				secundum = this.selection_SecRef.getEntity();
295
			} /*else if (getParentTreeNode() instanceof Classification) {
296
				secundum = ((Classification) getParentTreeNode())
297
						.getReference();
298
			} else if (getParentTreeNode() instanceof TaxonNode) {
299
				secundum = ((TaxonNode) getParentTreeNode()).getTaxon()
300
						.getSec();
301
			}*/
275
			}
302 276
		}
303 277
		if (taxonName != null){
304 278
		    taxon = Taxon.NewInstance(taxonName, secundum);
......
314 288
		this.openInEditor = openInEditor;
315 289
	}
316 290

  
317
	public TextWithLabelElement getTextNewTaxonName() {
318
        return textNewTaxonName;
291
	public String getTaxonName() {
292
        return textNewTaxonName.getText();
319 293
    }
320 294

  
295
	public Reference getReference(){
296
	    return selection_SecRef.getSelection();
297
	}
298

  
299
	public Control getMainControl(){
300
	    return textNewTaxonName.getMainControl();
301
	}
302

  
321 303
	public boolean isComplete() {
322 304
	    boolean allComplete = true;
323 305
	    if (!isCreateNew()){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/TaxonNodeWizardPage.java
16 16
import org.eclipse.swt.widgets.Listener;
17 17

  
18 18
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19
import eu.etaxonomy.cdm.model.name.NonViralName;
20
import eu.etaxonomy.cdm.model.reference.Reference;
19 21
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20 22
import eu.etaxonomy.cdm.model.taxon.Taxon;
21 23
import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
24
import eu.etaxonomy.taxeditor.parser.ParseHandler;
22 25
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
23 26
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 27
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
......
75 78
		detailElement.setEntity(entity);
76 79
		formFactory.addPropertyChangeListener(this);
77 80
		if (isCreateNew){
78
		    detailElement.getTextNewTaxonName().getMainControl().addListener(SWT.KeyDown, this);
81
		    detailElement.getMainControl().addListener(SWT.KeyDown, this);
79 82
		}
80 83
		return detailElement;
81 84
	}
......
112 115
			setMessage("No classification set.", WARNING);
113 116
		}
114 117
		else if(isCreateNew ){
115
		    if(detailElement.getTextNewTaxonName().getText().isEmpty()){
118
		    if(detailElement.getTaxonName().isEmpty()){
116 119
		        setMessage("No taxon name set.", ERROR);
117 120
		    } else{
118 121
		        setMessage(null);
......
144 147
				.getParentTreeNode();
145 148
	}
146 149

  
147
	public Taxon getTaxon() {
148
		return ((TaxonNodeDetailElement) getDetailElement()).getTaxon();
150
	public Taxon createTaxon() {
151
		String taxonName = ((TaxonNodeDetailElement) getDetailElement()).getTaxonName();
152
		Reference reference = ((TaxonNodeDetailElement) getDetailElement()).getReference();
153
		NonViralName parseReferencedName = ParseHandler.parseReferencedName(taxonName, null);
154
		return Taxon.NewInstance(parseReferencedName, reference);
149 155
	}
150 156

  
151 157
	/*
......
163 169
    @Override
164 170
    public void handleEvent(Event event) {
165 171
        TaxonNodeDetailElement detailElement = (TaxonNodeDetailElement) getDetailElement();
166
        if(event.widget == detailElement.getTextNewTaxonName().getMainControl()
172
        if(event.widget == detailElement.getMainControl()
167 173
                && event.keyCode == SWT.CR && isPageComplete()){
168 174
            wizardPageListener.close();
169 175
        }

Also available in: Unified diff