Revision ea3b1f1c
Added by Patrick Plitzner over 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/MoveSynonymToAnotherAcceptedTaxonHandler.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.taxeditor.editor.name.handler; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.UUID; |
|
6 |
|
|
3 | 7 |
import org.apache.log4j.Logger; |
4 | 8 |
import org.eclipse.core.commands.AbstractHandler; |
5 | 9 |
import org.eclipse.core.commands.ExecutionEvent; |
... | ... | |
9 | 13 |
import org.eclipse.ui.IEditorInput; |
10 | 14 |
import org.eclipse.ui.handlers.HandlerUtil; |
11 | 15 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
import java.util.UUID; |
|
15 |
|
|
16 | 16 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
17 | 17 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
18 | 18 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
... | ... | |
22 | 22 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
23 | 23 |
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation; |
24 | 24 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
25 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
25 | 26 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
26 | 27 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog; |
27 | 28 |
|
... | ... | |
35 | 36 |
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event); |
36 | 37 |
Shell shell = HandlerUtil.getActiveShell(event); |
37 | 38 |
IEditorInput input = editor.getEditorInput(); |
39 |
// Get synonym from selection before possible save dialog |
|
40 |
// because the selection will be null if save dialog is shown |
|
41 |
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
42 |
|
|
38 | 43 |
if (!EditorUtil.forceUserSave(editor, shell)) { |
39 | 44 |
return null; |
40 | 45 |
} |
... | ... | |
44 | 49 |
return null; |
45 | 50 |
} |
46 | 51 |
|
47 |
// Get synonym from selection |
|
48 |
StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
49 |
if (!(selection.getFirstElement() instanceof Synonym)) { |
|
52 |
if (selection==null || !(selection.getFirstElement() instanceof Synonym)) { |
|
53 |
MessagingUtils.warningDialog("No selection", this, "No synonym selected"); |
|
50 | 54 |
logger.error("Selection does not contain a Synonym"); |
51 | 55 |
return null; |
52 | 56 |
} |
... | ... | |
55 | 59 |
Taxon oldParent = ((TaxonEditorInput)input).getTaxon(); |
56 | 60 |
List<UUID> excludeTaxa = new ArrayList<UUID>(); |
57 | 61 |
excludeTaxa.add(oldParent.getUuid()); |
58 |
|
|
59 |
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", null, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
|
|
62 |
|
|
63 |
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(editor.getSite().getShell(), editor.getConversationHolder(), "Select new accepted taxon", null, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
|
|
60 | 64 |
if(newParentNode!=null){ |
61 | 65 |
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(), |
62 | 66 |
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor); |
Also available in: Unified diff
Fix possible NPE and widget disposed exception