Project

General

Profile

Download (2.59 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.molecular.editor.e4.handler;
2

    
3

    
4
import javax.inject.Named;
5

    
6
import org.eclipse.e4.core.di.annotations.CanExecute;
7
import org.eclipse.e4.core.di.annotations.Execute;
8
import org.eclipse.e4.core.di.annotations.Optional;
9
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
11
import org.eclipse.e4.ui.services.IServiceConstants;
12
import org.eclipse.e4.ui.workbench.modeling.EPartService;
13
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
14
import org.eclipse.jface.viewers.TreeNode;
15
import org.eclipse.ui.PartInitException;
16

    
17
import eu.etaxonomy.cdm.model.molecular.Sequence;
18
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditorInput;
19
import eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4;
20
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
21

    
22

    
23

    
24
/**
25
 * Opens the alignment editor from the CDM tree.
26
 *
27
 * @author Ben Stöver
28
 * @author pplitzner
29
 */
30
public class EditSequenceHandlerE4 {
31
    private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EditSequenceHandlerE4.class);
32

    
33

    
34
    @Execute
35
    public void execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)TreeNode treeNodeOfSelection,
36
            EPartService partService) {
37
        if(treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence){
38
            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.
39
            try {
40
                MPart part = partService.createPart("eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4");
41
                part = partService.showPart(part, PartState.ACTIVATE);
42
                AlignmentEditorE4 alignmentEditor = (AlignmentEditorE4) part.getObject();
43
                alignmentEditor.init(input);
44
            }
45
            catch (PartInitException e) {
46
                logger.error(Messages.EditSequenceHandler_COULD_NOT_OPEN, e);
47
            }
48
        }
49
    }
50

    
51
    @CanExecute
52
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
53
        boolean canExecute = false;
54
        if(selectedTreeNode!=null){
55
            Object value = selectedTreeNode.getValue();
56
            canExecute = value instanceof Sequence;
57
        }
58
        menuItem.setVisible(canExecute);
59
        return canExecute;
60
    }
61
}
(8-8/17)