Project

General

Profile

Download (2.67 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.AppModelId;
19
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditorInput;
20
import eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4;
21
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
22

    
23

    
24

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

    
34

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

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