Project

General

Profile

Download (7.19 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.navigation.navigator.operation;
11

    
12
import java.util.HashSet;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IStatus;
21

    
22
import eu.etaxonomy.cdm.api.application.ICdmRepository;
23
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
24
import eu.etaxonomy.cdm.api.service.DeleteResult;
25
import eu.etaxonomy.cdm.api.service.IClassificationService;
26
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
27
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
28
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
29
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
30
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
31
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
32
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
33
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
34
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
35
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
36
import eu.etaxonomy.taxeditor.store.CdmStore;
37

    
38
/**
39
 * <p>DeleteTreeNodeOperation class.</p>
40
 *
41
 * @author n.hoffmann
42
 * @created Jan 20, 2010
43
 * @version 1.0
44
 */
45
public class DeleteOperation extends AbstractPersistentPostOperation{
46

    
47
    private static final String TAXON_NODE_COULD_NOT_BE_DELETED = Messages.DeleteOperation_DELETE_FAIL;
48
    private Set<TaxonNodeDto> treeNodes;
49
    protected final TaxonDeletionConfigurator config;
50
    private final ICdmEntitySessionEnabled cdmEntitySessionEnabled;
51

    
52
    /**
53
     * <p>Constructor for DeleteTreeNodeOperation.</p>
54
     *
55
     * @param label a {@link java.lang.String} object.
56
     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
57
     * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
58
     * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
59
     * @param treeNodes a {@link java.util.Set} object.
60
     */
61
    public DeleteOperation(String label, IUndoContext undoContext,
62
            TaxonNodeDto taxonNode, TaxonDeletionConfigurator config,
63
            IPostOperationEnabled postOperationEnabled,
64
            IConversationEnabled conversationEnabled,
65
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
66
        super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
67
        this.taxonNode = taxonNode;
68
        this.config = config;
69
        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
70
    }
71

    
72
    /**
73
     * <p>Constructor for DeleteTreeNodeOperation.</p>
74
     *
75
     * @param label a {@link java.lang.String} object.
76
     * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
77
     * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
78
     * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
79
     * @param treeNodes a {@link java.util.Set} object.
80
     */
81
    public DeleteOperation(String label, IUndoContext undoContext,
82
            Set<TaxonNodeDto> treeNodes, TaxonDeletionConfigurator config,
83
            IPostOperationEnabled postOperationEnabled,
84
            IConversationEnabled conversationEnabled,
85
            ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
86
        super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
87
        this.treeNodes = treeNodes;
88
        this.config = config;
89
        this.cdmEntitySessionEnabled = cdmEntitySessionEnabled;
90
    }
91

    
92

    
93

    
94

    
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
97
	 */
98
	/** {@inheritDoc} */
99
	@Override
100
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
101
			throws ExecutionException {
102

    
103
		bind();
104
		monitor.worked(20);
105
		ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
106
		ITaxonNodeService service = controller.getTaxonNodeService();
107
		if(taxonNode != null && taxonNode.getTaxonUuid() != null ){
108
			//((TaxonNode) treeNode).delete();
109

    
110
//			element = ((TaxonNode)taxonNode).getTaxon();
111

    
112
			DeleteResult result = service.deleteTaxonNode(taxonNode.getUuid(), config);
113
			if (result.isError() && !result.getExceptions().isEmpty()){
114

    
115
				DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
116
			} else if (!result.getExceptions().isEmpty()){
117
				String separator = ", "; //$NON-NLS-1$
118
			    String exceptionString = ""; //$NON-NLS-1$
119
			    for (Exception exception : result.getExceptions()) {
120
		            exceptionString += exception.getLocalizedMessage()+separator;
121
		        }
122
			    DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteOperation_DELETE_SUCCESS, TaxeditorNavigationPlugin.PLUGIN_ID);
123
			}
124

    
125

    
126
		}else if(taxonNode != null && taxonNode.getTaxonUuid() == null){
127
//			Classification taxonomicTree = taxonNode.getClassificationUUID();
128

    
129
			DeleteResult result = CdmStore.getService(IClassificationService.class).delete(taxonNode.getClassificationUUID());
130
            if (result.isError() && !result.getExceptions().isEmpty()){
131
                //TODO:Error message!
132
                DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
133
            }
134
        } else {
135
            Set<UUID> treeNodeUuids = new HashSet<UUID>();
136
            ITaxonTreeNode entity = null;
137
            for(TaxonNodeDto treeNode : treeNodes) {
138
                treeNodeUuids.add(treeNode.getUuid());
139
            }
140

    
141
            DeleteResult result = service.deleteTaxonNodes(treeNodeUuids, config);
142
            if (result.isError() && !result.getExceptions().isEmpty()){
143
				//TODO:Error message!
144
                DeleteResultMessagingUtils.messageDialogWithDetails(result, TAXON_NODE_COULD_NOT_BE_DELETED, TaxeditorNavigationPlugin.PLUGIN_ID);
145
			}
146

    
147
        }
148

    
149
        monitor.worked(40);
150

    
151
        return postExecute(null);
152
    }
153

    
154
    /* (non-Javadoc)
155
     * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
156
     */
157
    /** {@inheritDoc} */
158
    @Override
159
    public IStatus redo(IProgressMonitor monitor, IAdaptable info)
160
            throws ExecutionException {
161
        return null;
162
    }
163

    
164
    /* (non-Javadoc)
165
     * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
166
     */
167
    /** {@inheritDoc} */
168
    @Override
169
    public IStatus undo(IProgressMonitor monitor, IAdaptable info)
170
            throws ExecutionException {
171
        return null;
172
    }
173
}
(2-2/9)