Project

General

Profile

Download (2.8 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.editor.view.descriptive.operation;
10

    
11
import org.eclipse.core.commands.ExecutionException;
12
import org.eclipse.core.commands.operations.IUndoContext;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17

    
18
import eu.etaxonomy.cdm.api.service.IDescriptionService;
19
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
20
import eu.etaxonomy.cdm.model.name.TaxonName;
21
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
22
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
23
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

    
26
/**
27
 * @author k.luther
28
 * @since 4 Mar 2019
29
 *
30
 */
31
public class DeleteTaxonNameDescriptionOperation extends AbstractPostOperation<TaxonName> {
32
    private final TaxonNameDescription description;
33
    /**
34
     * @param label
35
     * @param undoContext
36
     * @param element
37
     * @param postOperationEnabled
38
     * @param cdmEntitySessionEnabled
39
     */
40
    public DeleteTaxonNameDescriptionOperation(String label, IUndoContext undoContext, TaxonNameDescription description,
41
            IPostOperationEnabled postOperationEnabled, ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
42
        super(label, undoContext, description.getTaxonName(), postOperationEnabled, cdmEntitySessionEnabled);
43
        this.description = description;
44

    
45
    }
46

    
47
    /**
48
     * {@inheritDoc}
49
     */
50
    @Override
51
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
52

    
53
        monitor.worked(20);
54
        if (description != null && description.isPersited()){
55
//          element.removeDescription(description);
56
            CdmStore.getService(IDescriptionService.class).deleteDescription(description.getUuid());
57
            element.removeDescription(description);
58
            return postExecute(element);
59
        }else if (description != null && !description.isPersited()){
60
            element.removeDescription(description);
61
            return Status.OK_STATUS;
62
        }
63
        return null;
64
    }
65

    
66
    /**
67
     * {@inheritDoc}
68
     */
69
    @Override
70
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
71
        return execute(monitor, info);
72
    }
73

    
74
    /**
75
     * {@inheritDoc}
76
     */
77
    @Override
78
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
79
        element.addDescription(description);
80

    
81
        return postExecute(null);
82
    }
83

    
84
}
(9-9/11)