Project

General

Profile

Download (4.12 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.editor.definedterm.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

    
19
import eu.etaxonomy.cdm.api.service.ITermService;
20
import eu.etaxonomy.cdm.api.service.IVocabularyService;
21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22
import eu.etaxonomy.cdm.model.common.TermBase;
23
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27
import eu.etaxonomy.taxeditor.store.StoreUtil;
28

    
29
/**
30
 * @author l.morris
31
 * @date 22 Dec 2011
32
 *
33
 */
34
public class DeleteTermBaseOperation extends AbstractPostOperation {
35

    
36
	private TermBase termBase;
37
	private DefinedTermEditor definedTermEditor;
38
	/**
39
	 * @param label
40
	 * @param undoContext
41
	 * @param postOperationEnabled
42
	 */
43
	public DeleteTermBaseOperation(String label, IUndoContext undoContext, TermBase termBase,
44
			DefinedTermEditor definedTermEditor) {
45
		super(label, undoContext, definedTermEditor);
46
		this.termBase = termBase;
47
		this.definedTermEditor = definedTermEditor;
48
	}
49

    
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
52
	 */
53
	@Override
54
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55
			throws ExecutionException {
56
		
57
		
58
		
59
		if (termBase instanceof TermVocabulary) {
60
			
61
			if (!((TermVocabulary)termBase).getTerms().isEmpty()) {
62
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Delete all terms from this vocaulary before deleting the vocabulary.");
63
				StoreUtil.warningDialog("Vocabulary not empty", termBase, status);
64
				return status;
65
			}
66
			definedTermEditor.getInMemoryVocabularies().remove(termBase); 
67
			CdmStore.getService(IVocabularyService.class).delete((TermVocabulary)termBase);
68
			
69
		} else if (termBase instanceof DefinedTermBase) {
70
			
71
			
72
			DefinedTermBase definedTermBase = (DefinedTermBase) termBase;
73
			if(!definedTermBase.getIncludes().isEmpty()){
74
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "This term includes other terms. Please delete the included terms before deleting this term.");				
75
				StoreUtil.warningDialog("Term has included terms", termBase, status);
76
				return status;
77
			} 
78
						
79
			DefinedTermBase partOf = definedTermBase.getPartOf();
80
			if(partOf != null){
81
				partOf.removeIncludes(definedTermBase);
82
			}
83
			
84
			DefinedTermBase kindOf = definedTermBase.getKindOf();
85
			if(kindOf != null){
86
				definedTermBase.removeGeneralization(kindOf);
87
			}
88
			
89
			TermVocabulary vocabulary = definedTermBase.getVocabulary();
90
			if(vocabulary != null){
91
				vocabulary.removeTerm(definedTermBase);
92
			}
93
			CdmStore.getService(ITermService.class).delete((DefinedTermBase)termBase);
94
			
95
		}
96
		
97
		return postExecute(termBase);
98
	}
99

    
100
	/* (non-Javadoc)
101
	 * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
102
	 */
103
	@Override
104
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
105
			throws ExecutionException {
106
		// TODO Auto-generated method stub
107
		return null;
108
	}
109

    
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
112
	 */
113
	@Override
114
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
115
			throws ExecutionException {
116
		// TODO Auto-generated method stub
117
		return null;
118
	}
119

    
120
}
(3-3/4)