1 package eu
.etaxonomy
.taxeditor
.editor
.view
.derivate
.handler
;
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
.editor
.view
.derivate
.DerivateView
;
17 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
18 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
20 public class SingleReadHandler
extends AbstractHandler
{
23 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
24 IEditorPart activeEditor
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
25 ISelection clipBoardSelection
= LocalSelectionTransfer
.getTransfer().getSelection();
26 final ISelection selection
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
27 TreeNode clipBoardTreeNode
= EditorUtil
.getTreeNodeOfSelection(clipBoardSelection
);
28 TreeNode selectedTreeNode
= EditorUtil
.getTreeNodeOfSelection(selection
);
29 if(activeEditor
instanceof DerivateView
) {
30 DerivateView derivateView
= (DerivateView
)activeEditor
;
31 if(event
.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivative.copySingleReadToClipBoard")){ //$NON-NLS-1$
32 LocalSelectionTransfer
.getTransfer().setSelection(selection
);
34 else if(event
.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivative.reuseSingleRead")){ //$NON-NLS-1$
35 if(activeEditor
.isDirty()){
36 MessagingUtils
.warningDialog(DerivateView
.VIEW_HAS_UNSAVED_CHANGES
, this, DerivateView
.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION
);
39 if(clipBoardTreeNode
!=null && clipBoardTreeNode
.getValue() instanceof SingleRead
40 && selectedTreeNode
!=null && selectedTreeNode
.getValue() instanceof Sequence
){
41 SingleRead singleRead
= (SingleRead
)clipBoardTreeNode
.getValue();
42 Sequence sequence
= (Sequence
)selectedTreeNode
.getValue();
43 sequence
.addSingleRead(singleRead
);
44 CdmStore
.getService(ISequenceService
.class).merge(sequence
);
46 if(activeEditor
instanceof DerivateView
) {
47 derivateView
.getConversationHolder().commit();
48 derivateView
.refreshTree();
49 LocalSelectionTransfer
.getTransfer().setSelection(null);
53 else if(event
.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivative.removeSingleReadFromSequence")){ //$NON-NLS-1$
54 if(activeEditor
.isDirty()){
55 MessagingUtils
.warningDialog(DerivateView
.VIEW_HAS_UNSAVED_CHANGES
, this, DerivateView
.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION
);
58 if(selectedTreeNode
!=null && selectedTreeNode
.getParent()!=null &&
59 selectedTreeNode
.getValue() instanceof SingleRead
&& selectedTreeNode
.getParent().getValue() instanceof Sequence
) {
60 Sequence sequence
= (Sequence
) selectedTreeNode
.getParent().getValue();
61 sequence
.removeSingleRead((SingleRead
) selectedTreeNode
.getValue());
62 CdmStore
.getService(ISequenceService
.class).merge(sequence
);
64 if(activeEditor
instanceof DerivateView
) {
65 derivateView
.getConversationHolder().commit();
66 derivateView
.refreshTree();
70 derivateView
.updateLabelCache();
71 derivateView
.refreshTree();