Revision df5f4832
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/DeleteTermBaseHandler.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
17 | 17 |
import org.eclipse.core.commands.common.NotDefinedException; |
18 | 18 |
import org.eclipse.core.commands.operations.IUndoContext; |
19 | 19 |
import org.eclipse.jface.dialogs.MessageDialog; |
20 |
import org.eclipse.jface.viewers.ISelection; |
|
20 | 21 |
import org.eclipse.jface.viewers.IStructuredSelection; |
22 |
import org.eclipse.ui.IEditorPart; |
|
21 | 23 |
import org.eclipse.ui.handlers.HandlerUtil; |
22 | 24 |
|
23 | 25 |
import eu.etaxonomy.cdm.model.common.TermBase; |
24 | 26 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
25 | 27 |
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation; |
28 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
26 | 29 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
27 | 30 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
28 | 31 |
import eu.etaxonomy.taxeditor.store.StoreUtil; |
... | ... | |
34 | 37 |
*/ |
35 | 38 |
public class DeleteTermBaseHandler extends AbstractHandler { |
36 | 39 |
|
37 |
/* (non-Javadoc) |
|
38 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
39 |
*/ |
|
40 | 40 |
@Override |
41 | 41 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
42 |
DefinedTermEditor editor = (DefinedTermEditor) HandlerUtil
|
|
42 |
IEditorPart editor = HandlerUtil
|
|
43 | 43 |
.getActiveEditor(event); |
44 | 44 |
|
45 | 45 |
if (editor.isDirty()){ |
... | ... | |
52 | 52 |
} |
53 | 53 |
} |
54 | 54 |
if (editor instanceof DefinedTermEditor){ |
55 |
DefinedTermEditor dfe = (DefinedTermEditor) editor;
|
|
56 |
try {
|
|
57 |
String label = event.getCommand().getName();
|
|
58 |
IUndoContext undoContext = StoreUtil.getUndoContext();
|
|
55 |
DefinedTermEditor dfe = (DefinedTermEditor) editor;
|
|
56 |
try {
|
|
57 |
String label = event.getCommand().getName();
|
|
58 |
IUndoContext undoContext = StoreUtil.getUndoContext();
|
|
59 | 59 |
|
60 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil
|
|
61 |
.getCurrentSelection(event);
|
|
60 |
ISelection selection = dfe.getViewer().getSelection();
|
|
61 |
if(selection instanceof IStructuredSelection){
|
|
62 | 62 |
|
63 |
Iterator<TermBase> selectionIterator = selection.iterator();
|
|
63 |
Iterator<TermBase> selectionIterator = ((IStructuredSelection) selection).iterator();
|
|
64 | 64 |
|
65 |
while (selectionIterator.hasNext()){
|
|
65 |
while (selectionIterator.hasNext()){
|
|
66 | 66 |
|
67 |
TermBase term = selectionIterator.next();
|
|
67 |
TermBase term = selectionIterator.next();
|
|
68 | 68 |
|
69 | 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 |
}
|
|
70 |
AbstractPostOperation operation =
|
|
71 |
new DeleteTermBaseOperation(label,
|
|
72 |
undoContext,
|
|
73 |
term,
|
|
74 |
dfe.getDefinedTermEditorInput(),
|
|
75 |
dfe);
|
|
76 |
AbstractUtility.executeOperation(operation);
|
|
77 |
} |
|
78 |
}
|
|
79 |
} catch (NotDefinedException e) {
|
|
80 |
MessagingUtils.error(getClass(), e);
|
|
81 |
}
|
|
82 | 82 |
} |
83 | 83 |
return null; |
84 | 84 |
} |
Also available in: Unified diff
Fix possible NPE #4850