2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.handler
;
11 import java
.util
.Iterator
;
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
;
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
.AbstractUtility
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
37 public class DeleteTermBaseHandler
extends AbstractHandler
{
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 IEditorPart editor
= HandlerUtil
42 .getActiveEditor(event
);
44 if (editor
.isDirty()){
45 boolean proceed
= MessageDialog
.openQuestion(null,
46 "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
53 if (editor
instanceof DefinedTermEditor
){
54 DefinedTermEditor dfe
= (DefinedTermEditor
) editor
;
56 String label
= event
.getCommand().getName();
57 IUndoContext undoContext
= StoreUtil
.getUndoContext();
59 ISelection selection
= dfe
.getViewer().getSelection();
60 if(selection
instanceof IStructuredSelection
){
62 Iterator
<TermBase
> selectionIterator
= ((IStructuredSelection
) selection
).iterator();
64 while (selectionIterator
.hasNext()){
66 TermBase term
= selectionIterator
.next();
69 AbstractPostOperation operation
=
70 new DeleteTermBaseOperation(label
,
73 dfe
.getDefinedTermEditorInput(),
75 AbstractUtility
.executeOperation(operation
);
78 } catch (NotDefinedException e
) {
79 MessagingUtils
.error(getClass(), e
);