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")){
32 LocalSelectionTransfer
.getTransfer().setSelection(selection
);
34 else if(event
.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivative.reuseSingleRead")){
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 if(CdmStore
.getCurrentSessionManager().isRemoting()){
45 CdmStore
.getService(ISequenceService
.class).merge(sequence
);
48 CdmStore
.getService(ISequenceService
.class).saveOrUpdate(sequence
);
50 if(activeEditor
instanceof DerivateView
) {
51 derivateView
.getConversationHolder().commit();
52 derivateView
.refreshTree();
53 LocalSelectionTransfer
.getTransfer().setSelection(null);
57 else if(event
.getCommand().getId().equals("eu.etaxonomy.taxeditor.editor.derivative.removeSingleReadFromSequence")){
58 if(activeEditor
.isDirty()){
59 MessagingUtils
.warningDialog(DerivateView
.VIEW_HAS_UNSAVED_CHANGES
, this, DerivateView
.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION
);
62 if(selectedTreeNode
!=null && selectedTreeNode
.getParent()!=null &&
63 selectedTreeNode
.getValue() instanceof SingleRead
&& selectedTreeNode
.getParent().getValue() instanceof Sequence
) {
64 Sequence sequence
= (Sequence
) selectedTreeNode
.getParent().getValue();
65 sequence
.removeSingleRead((SingleRead
) selectedTreeNode
.getValue());
66 if(CdmStore
.getCurrentSessionManager().isRemoting()){
67 CdmStore
.getService(ISequenceService
.class).merge(sequence
);
70 CdmStore
.getService(ISequenceService
.class).saveOrUpdate(sequence
);
72 if(activeEditor
instanceof DerivateView
) {
73 derivateView
.getConversationHolder().commit();
74 derivateView
.refreshTree();
78 derivateView
.updateLabelCache();
79 derivateView
.refreshTree();