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.handler;
|
10
|
|
11
|
import java.util.Iterator;
|
12
|
|
13
|
import org.eclipse.core.commands.AbstractHandler;
|
14
|
import org.eclipse.core.commands.ExecutionEvent;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.core.commands.common.NotDefinedException;
|
17
|
import org.eclipse.core.commands.operations.IUndoContext;
|
18
|
import org.eclipse.jface.dialogs.MessageDialog;
|
19
|
import org.eclipse.jface.viewers.ISelection;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.ui.IEditorPart;
|
22
|
import org.eclipse.ui.handlers.HandlerUtil;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
25
|
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
|
26
|
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation;
|
27
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
28
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
29
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
30
|
|
31
|
/**
|
32
|
* @author l.morris
|
33
|
* @date 22 Dec 2011
|
34
|
*
|
35
|
*/
|
36
|
public class DeleteTermBaseHandler extends AbstractHandler {
|
37
|
|
38
|
@Override
|
39
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
40
|
IEditorPart editor = HandlerUtil
|
41
|
.getActiveEditor(event);
|
42
|
|
43
|
if (editor.isDirty()){
|
44
|
boolean proceed = MessageDialog.openQuestion(null,
|
45
|
"Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
|
46
|
if (proceed) {
|
47
|
editor.doSave(null);
|
48
|
} else {
|
49
|
return null;
|
50
|
}
|
51
|
}
|
52
|
if (editor instanceof DefinedTermEditor){
|
53
|
DefinedTermEditor dfe = (DefinedTermEditor) editor;
|
54
|
try {
|
55
|
String label = event.getCommand().getName();
|
56
|
IUndoContext undoContext = StoreUtil.getUndoContext();
|
57
|
|
58
|
ISelection selection = dfe.getViewer().getSelection();
|
59
|
if(selection instanceof IStructuredSelection){
|
60
|
|
61
|
Iterator<TermBase> selectionIterator = ((IStructuredSelection) selection).iterator();
|
62
|
|
63
|
while (selectionIterator.hasNext()){
|
64
|
|
65
|
TermBase term = selectionIterator.next();
|
66
|
|
67
|
|
68
|
AbstractPostOperation operation =
|
69
|
new DeleteTermBaseOperation(label,
|
70
|
undoContext,
|
71
|
term,
|
72
|
dfe.getDefinedTermEditorInput(),
|
73
|
dfe);
|
74
|
}
|
75
|
}
|
76
|
} catch (NotDefinedException e) {
|
77
|
MessagingUtils.error(getClass(), e);
|
78
|
}
|
79
|
}
|
80
|
return null;
|
81
|
}
|
82
|
|
83
|
}
|