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.core.di.annotations.Optional;
|
8
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
9
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
10
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
11
|
import org.eclipse.jface.viewers.TreeNode;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
14
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
15
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
16
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
|
17
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
18
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
19
|
|
20
|
public class SingleReadRemoveHandler {
|
21
|
|
22
|
@Execute
|
23
|
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode){
|
24
|
DerivateView derivateView = (DerivateView)part.getObject();
|
25
|
if(derivateView.isDirty()){
|
26
|
MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
|
27
|
return;
|
28
|
}
|
29
|
if(selectedTreeNode!=null && selectedTreeNode.getParent()!=null &&
|
30
|
selectedTreeNode.getValue() instanceof SingleRead && selectedTreeNode.getParent().getValue() instanceof Sequence) {
|
31
|
Sequence sequence = (Sequence) selectedTreeNode.getParent().getValue();
|
32
|
sequence.removeSingleRead((SingleRead) selectedTreeNode.getValue());
|
33
|
CdmStore.getService(ISequenceService.class).merge(sequence);
|
34
|
|
35
|
derivateView.getConversationHolder().commit();
|
36
|
derivateView.refreshTree();
|
37
|
}
|
38
|
derivateView.updateLabelCache();
|
39
|
derivateView.refreshTree();
|
40
|
}
|
41
|
|
42
|
@CanExecute
|
43
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
|
44
|
@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode,
|
45
|
MHandledMenuItem menuItem) {
|
46
|
boolean canExecute = false;
|
47
|
if(selectedTreeNode!=null){
|
48
|
Object value = selectedTreeNode.getValue();
|
49
|
canExecute = value instanceof SingleRead && ((DerivateView) part.getObject()).getMultiLinkSingleReads().contains(value);
|
50
|
}
|
51
|
menuItem.setVisible(canExecute);
|
52
|
return canExecute;
|
53
|
}
|
54
|
|
55
|
}
|