Project

General

Profile

Download (3.87 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.definedterm.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.DeleteResult;
19
import eu.etaxonomy.cdm.api.service.ITermService;
20
import eu.etaxonomy.cdm.api.service.IVocabularyService;
21
import eu.etaxonomy.cdm.api.service.config.TermDeletionConfigurator;
22
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
25
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
26
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
29
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
31
import eu.etaxonomy.taxeditor.store.StoreUtil;
32
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
33

    
34
/**
35
 * @author l.morris
36
 * @date 22 Dec 2011
37
 *
38
 */
39
public class DeleteTermBaseOperation extends AbstractPostTaxonOperation {
40

    
41
	private final TermEditorInput definedEditorInput;
42
	private final AbstractTermDto termBase;
43

    
44
	public DeleteTermBaseOperation(String label,
45
			IUndoContext undoContext,
46
			AbstractTermDto termBase,
47
			TermEditorInput definedEditorInput,
48
			IPostOperationEnabled postOperationEnabled) {
49
		super(label, undoContext, postOperationEnabled);
50
		this.termBase = termBase;
51
		this.definedEditorInput = definedEditorInput;
52
	}
53

    
54
	@Override
55
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
56
			throws ExecutionException {
57
		if (termBase instanceof TermVocabularyDto) {
58
			definedEditorInput.getVocabularies().remove(termBase);
59

    
60
			DeleteResult result =	CdmStore.getService(IVocabularyService.class).delete(termBase.getUuid());
61
			if (!result.isOk()){
62
			    return showErrorMessage(result);
63
			}
64

    
65
		} else if (termBase instanceof TermDto) {
66
			DeleteResult result =	CdmStore.getService(ITermService.class).delete(termBase.getUuid(),
67
			        new TermDeletionConfigurator());
68
			if (!result.isOk()){
69
			    return showErrorMessage(result);
70
            }
71
		}
72
		return postExecute(termBase);
73
	}
74

    
75
	private IStatus showErrorMessage(DeleteResult result) {
76
	    StringBuffer errorString = new StringBuffer();
77
        for (Exception e:result.getExceptions()){
78
            errorString.append(e.getMessage() + System.lineSeparator());
79
        }
80
        IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), errorString.toString());
81
        String delete_failed = Messages.DeleteTermBaseOperation_DELETE_FAILED;
82
        if (result.isAbort()){
83
            MessagingUtils.warningDialog(delete_failed, this, status);
84
        }else{
85
            if (result.getExceptions().iterator().hasNext()){
86
                MessagingUtils.errorDialog(delete_failed, this.getClass(),null, TaxeditorStorePlugin.PLUGIN_ID, result.getExceptions().iterator().next(), true);
87
            }else{
88
                MessagingUtils.warningDialog(delete_failed, this, status);
89
            }
90
        }
91
        return status;
92
    }
93

    
94
    @Override
95
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
96
			throws ExecutionException {
97
		return null;
98
	}
99

    
100
	@Override
101
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
102
			throws ExecutionException {
103
		return null;
104
	}
105

    
106
}
(3-3/4)