1 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
;
3 import org
.eclipse
.core
.commands
.AbstractHandler
;
4 import org
.eclipse
.core
.commands
.ExecutionEvent
;
5 import org
.eclipse
.core
.commands
.ExecutionException
;
6 import org
.eclipse
.jface
.util
.LocalSelectionTransfer
;
7 import org
.eclipse
.jface
.viewers
.ISelection
;
8 import org
.eclipse
.jface
.viewers
.TreeNode
;
9 import org
.eclipse
.ui
.IEditorPart
;
10 import org
.eclipse
.ui
.PlatformUI
;
12 import eu
.etaxonomy
.cdm
.api
.service
.molecular
.ISequenceService
;
13 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
14 import eu
.etaxonomy
.cdm
.model
.molecular
.SingleRead
;
15 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
16 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
17 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
19 public class PasteDerivateCommand
extends AbstractHandler
{
23 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
24 IEditorPart activeEditor
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
25 if(activeEditor
.isDirty()){
26 AbstractUtility
.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
29 ISelection clipBoardSelection
= LocalSelectionTransfer
.getTransfer().getSelection();
30 final ISelection pasteSelection
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
32 TreeNode clipBoardTreeNode
= EditorUtil
.getTreeNodeValueOfSelection(clipBoardSelection
);
33 TreeNode pasteTreeNode
= EditorUtil
.getTreeNodeValueOfSelection(pasteSelection
);
34 if(clipBoardTreeNode
!=null && clipBoardTreeNode
.getValue() instanceof SingleRead
35 && pasteTreeNode
!=null && pasteTreeNode
.getValue() instanceof Sequence
){
36 SingleRead singleRead
= (SingleRead
)clipBoardTreeNode
.getValue();
37 Sequence sequence
= (Sequence
)pasteTreeNode
.getValue();
38 sequence
.addSingleRead(singleRead
);
39 CdmStore
.getService(ISequenceService
.class).saveOrUpdate(sequence
);
40 if(activeEditor
instanceof DerivateView
) {
41 DerivateView derivateView
= (DerivateView
)activeEditor
;
42 derivateView
.getViewer().setInput(derivateView
.getEditorInput());
43 LocalSelectionTransfer
.getTransfer().setSelection(null);