Project

General

Profile

Download (4.86 KB) Statistics
| Branch: | Tag: | Revision:
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.editor.view.derivate.operation;
11

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

    
20
import eu.etaxonomy.cdm.api.service.DeleteResult;
21
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
22
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
27
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30
import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
31

    
32
/**
33
 *
34
 * @author pplitzner
35
 * @date Oct 21, 2014
36
 *
37
 */
38
public class DeleteDerivateOperation extends AbstractPostOperation<CdmBase> {
39

    
40
    private final SpecimenDeleteConfigurator deleteConfigurator;
41

    
42
    public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
43
            IPostOperationEnabled postOperationEnabled) {
44
        this(label, undoContext, element, postOperationEnabled, new SpecimenDeleteConfigurator());
45
    }
46

    
47
    public DeleteDerivateOperation(String label, IUndoContext undoContext, CdmBase element,
48
            IPostOperationEnabled postOperationEnabled, SpecimenDeleteConfigurator config) {
49
        super(label, undoContext, element, postOperationEnabled);
50
        this.deleteConfigurator = config;
51
    }
52

    
53

    
54
    /*
55
     * (non-Javadoc)
56
     *
57
     * @see
58
     * org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse
59
     * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
60
     */
61
    /** {@inheritDoc} */
62
    @Override
63
    public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
64
        if(getPostOperationEnabled() instanceof ISaveablePart){
65
            String confirmationQuestion = "Do you really want to delete the selected element";
66
            if(deleteConfigurator.isDeleteChildren()){
67
                confirmationQuestion += " and its children";
68
            }
69
            confirmationQuestion += "?";
70
            if(!DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfigurator, null, "Confirm Deletion", confirmationQuestion)){
71
                return Status.CANCEL_STATUS;
72
            }
73
            if(((ISaveablePart) getPostOperationEnabled()).isDirty()){
74
                MessagingUtils.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
75
                return Status.CANCEL_STATUS;
76
            }
77
        }
78
        DeleteResult deleteResult = CdmStore.getService(IOccurrenceService.class).deleteDerivateHierarchy(element, deleteConfigurator);
79
        if(deleteResult.isOk()){
80
            if(getPostOperationEnabled() instanceof DerivateView){
81
                DerivateView derivateView = (DerivateView) getPostOperationEnabled();
82
                //update DerivateView
83
                derivateView.getConversationHolder().commit();
84
                IStatus returnStatus = postExecute(null);
85
                //close if no more items left
86
                if(derivateView.getViewer().getTree().getItemCount()<1){
87
                    AbstractUtility.close(derivateView);
88
                }
89
                return returnStatus;
90
            }
91
        }
92
        else{
93
            MessagingUtils.warningDialog("Deletion failed", this, deleteResult.toString());
94
            return Status.CANCEL_STATUS;
95
        }
96
        return Status.OK_STATUS;
97
    }
98

    
99
    /*
100
     * (non-Javadoc)
101
     *
102
     * @see
103
     * org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse
104
     * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
105
     */
106
    /** {@inheritDoc} */
107
    @Override
108
    public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
109
        //no redo possible
110
        return Status.CANCEL_STATUS ;
111
    }
112

    
113
    /*
114
     * (non-Javadoc)
115
     *
116
     * @see
117
     * org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse
118
     * .core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
119
     */
120
    /** {@inheritDoc} */
121
    @Override
122
    public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
123
        //no undo possible
124
        return Status.CANCEL_STATUS;
125
    }
126
}
(1-1/2)