Project

General

Profile

« Previous | Next » 

Revision dcf7fd09

Added by Patrick Plitzner almost 6 years ago

ref #7010 Adapt molecular handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.molecular/src/main/java/eu/etaxonomy/taxeditor/molecular/editor/e4/handler/EditSequenceHandlerE4.java
12 12
import org.eclipse.e4.ui.services.IServiceConstants;
13 13
import org.eclipse.e4.ui.workbench.modeling.EModelService;
14 14
import org.eclipse.e4.ui.workbench.modeling.EPartService;
15
import org.eclipse.jface.viewers.IStructuredSelection;
15 16
import org.eclipse.jface.viewers.TreeNode;
16 17
import org.eclipse.ui.PartInitException;
17 18

  
......
35 36

  
36 37

  
37 38
    @Execute
38
    public void execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection,
39
    public void execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
39 40
            EPartService partService, EModelService modelService, MApplication application) {
40
        if(treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence){
41
            AlignmentEditorInput input = new AlignmentEditorInput(((Sequence)treeNodeOfSelection.getValue()).getUuid());  //TODO Should there always be a new instance created here? What if the specified CDM node is already opened in an AlignmentEditor? => Possible create Singleton that keeps instances by sequence objects in a map.
42
            try {
43
                String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_MOLECULAR_EDITOR_E4_ALIGNMENTEDITORE4;
44
                MPart part = EditorUtil.showPart(partId, modelService, partService, application);
45
                AlignmentEditorE4 alignmentEditor = (AlignmentEditorE4) part.getObject();
46
                alignmentEditor.init(input);
47
            }
48
            catch (PartInitException e) {
49
                logger.error(Messages.EditSequenceHandler_COULD_NOT_OPEN, e);
50
            }
41
        Sequence sequence = (Sequence) ((TreeNode) selection.getFirstElement()).getValue();
42
        AlignmentEditorInput input = new AlignmentEditorInput(sequence.getUuid());  //TODO Should there always be a new instance created here? What if the specified CDM node is already opened in an AlignmentEditor? => Possible create Singleton that keeps instances by sequence objects in a map.
43
        try {
44
            String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_MOLECULAR_EDITOR_E4_ALIGNMENTEDITORE4;
45
            MPart part = EditorUtil.showPart(partId, modelService, partService, application);
46
            AlignmentEditorE4 alignmentEditor = (AlignmentEditorE4) part.getObject();
47
            alignmentEditor.init(input);
48
        }
49
        catch (PartInitException e) {
50
            logger.error(Messages.EditSequenceHandler_COULD_NOT_OPEN, e);
51 51
        }
52 52
    }
53 53

  
54 54
    @CanExecute
55
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
55
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem) {
56 56
        boolean canExecute = false;
57
        if(selectedTreeNode!=null){
58
            Object value = selectedTreeNode.getValue();
59
            canExecute = value instanceof Sequence;
60
        }
57
        canExecute = selection.size()==1
58
                && selection.getFirstElement() instanceof TreeNode
59
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof Sequence;
61 60
        menuItem.setVisible(canExecute);
62 61
        return canExecute;
63 62
    }

Also available in: Unified diff