Project

General

Profile

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

    
3
import javax.inject.Named;
4

    
5
import org.apache.logging.log4j.Logger;
6
import org.apache.logging.log4j.LogManager;
7
import org.eclipse.e4.core.di.annotations.CanExecute;
8
import org.eclipse.e4.core.di.annotations.Execute;
9
import org.eclipse.e4.core.di.annotations.Optional;
10
import org.eclipse.e4.ui.model.application.MApplication;
11
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
12
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
13
import org.eclipse.e4.ui.services.IServiceConstants;
14
import org.eclipse.e4.ui.workbench.modeling.EModelService;
15
import org.eclipse.e4.ui.workbench.modeling.EPartService;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.viewers.TreeNode;
18
import org.eclipse.ui.PartInitException;
19

    
20
import eu.etaxonomy.cdm.model.molecular.Sequence;
21
import eu.etaxonomy.taxeditor.editor.EditorUtil;
22
import eu.etaxonomy.taxeditor.molecular.AppModelId;
23
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditorInput;
24
import eu.etaxonomy.taxeditor.molecular.editor.e4.AlignmentEditorE4;
25
import eu.etaxonomy.taxeditor.molecular.l10n.Messages;
26

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

    
37
    @Execute
38
    public void execute(@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
39
            EPartService partService, EModelService modelService, MApplication application) {
40
        Sequence sequence = (Sequence) ((TreeNode) selection.getFirstElement()).getValue();
41
        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.
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
        }
51
    }
52

    
53
    @CanExecute
54
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem) {
55
        boolean canExecute = false;
56
        canExecute = selection.size()==1
57
                && selection.getFirstElement() instanceof TreeNode
58
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof Sequence;
59
        menuItem.setVisible(canExecute);
60
        return canExecute;
61
    }
62
}
(8-8/17)