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