1 package eu
.etaxonomy
.taxeditor
.editor
.name
.handler
;
3 import java
.util
.ArrayList
;
7 import org
.apache
.log4j
.Logger
;
8 import org
.eclipse
.core
.commands
.AbstractHandler
;
9 import org
.eclipse
.core
.commands
.ExecutionEvent
;
10 import org
.eclipse
.core
.commands
.ExecutionException
;
11 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
12 import org
.eclipse
.swt
.widgets
.Shell
;
13 import org
.eclipse
.ui
.IEditorInput
;
14 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
16 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
18 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
20 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
21 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
22 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
23 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.MoveSynonymToAnotherAcceptedTaxonOperation
;
24 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
25 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
27 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
29 public class MoveSynonymToAnotherAcceptedTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
30 private static final Logger logger
= Logger
31 .getLogger(MoveSynonymToAnotherAcceptedTaxonHandler
.class);
32 private MultiPageTaxonEditor editor
;
35 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
36 editor
= (MultiPageTaxonEditor
) HandlerUtil
.getActiveEditor(event
);
37 Shell shell
= HandlerUtil
.getActiveShell(event
);
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
);
43 if (!EditorUtil
.forceUserSave(editor
, shell
)) {
47 if (!(input
instanceof TaxonEditorInput
)) {
48 logger
.error("Editor input is not TaxonEditorInput");
52 if (selection
==null || !(selection
.getFirstElement() instanceof Synonym
)) {
53 MessagingUtils
.warningDialog("No selection", this, "No synonym selected");
54 logger
.error("Selection does not contain a Synonym");
58 Synonym synonym
= (Synonym
) selection
.getFirstElement();
59 Taxon oldParent
= ((TaxonEditorInput
)input
).getTaxon();
60 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
61 excludeTaxa
.add(oldParent
.getUuid());
63 TaxonNode newParentNode
= TaxonNodeSelectionDialog
.select(editor
.getSite().getShell(), editor
.getConversationHolder(), "Select new accepted taxon", null, null, ((TaxonEditorInput
)input
).getTaxonNode().getClassification());
64 if(newParentNode
!=null){
65 MoveSynonymToAnotherAcceptedTaxonOperation operation
= new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil
.getUndoContext(),
66 oldParent
.getUuid(), synonym
.getUuid(), newParentNode
.getTaxon(), editor
);
68 AbstractUtility
.executeOperation(operation
);
75 public boolean postOperation(CdmBase objectAffectedByOperation
) {
76 // TODO Auto-generated method stub
81 public boolean onComplete() {
82 // TODO Auto-generated method stub