1
|
package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
|
2
|
|
3
|
import javax.inject.Named;
|
4
|
|
5
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
6
|
import org.eclipse.e4.core.di.annotations.Execute;
|
7
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
8
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
9
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
10
|
import org.eclipse.jface.util.LocalSelectionTransfer;
|
11
|
import org.eclipse.jface.viewers.ISelection;
|
12
|
import org.eclipse.jface.viewers.TreeNode;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
15
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
16
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
17
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
18
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
|
19
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
|
22
|
public class SingleReadReuseHandler {
|
23
|
|
24
|
@Execute
|
25
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode){
|
26
|
ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
|
27
|
TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeOfSelection(clipBoardSelection);
|
28
|
DerivateView derivateView = (DerivateView)part.getObject();
|
29
|
if(derivateView.isDirty()){
|
30
|
MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
|
31
|
return;
|
32
|
}
|
33
|
if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
|
34
|
&& selectedTreeNode!=null && selectedTreeNode.getValue() instanceof Sequence){
|
35
|
SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
|
36
|
Sequence sequence = (Sequence)selectedTreeNode.getValue();
|
37
|
sequence.addSingleRead(singleRead);
|
38
|
CdmStore.getService(ISequenceService.class).merge(sequence);
|
39
|
|
40
|
derivateView.getConversationHolder().commit();
|
41
|
derivateView.refreshTree();
|
42
|
LocalSelectionTransfer.getTransfer().setSelection(null);
|
43
|
}
|
44
|
derivateView.updateLabelCache();
|
45
|
derivateView.refreshTree();
|
46
|
}
|
47
|
|
48
|
@CanExecute
|
49
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
|
50
|
boolean canExecute = false;
|
51
|
Object value = selectedTreeNode.getValue();
|
52
|
TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
|
53
|
if(value instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead
|
54
|
&& !((Sequence) value).getSingleReads().contains(clipboardNode.getValue())){
|
55
|
canExecute = true;
|
56
|
}
|
57
|
menuItem.setVisible(canExecute);
|
58
|
return canExecute;
|
59
|
}
|
60
|
|
61
|
}
|