Project

General

Profile

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

    
3

    
4
import org.eclipse.core.commands.AbstractHandler;
5
import org.eclipse.core.commands.ExecutionEvent;
6
import org.eclipse.core.commands.ExecutionException;
7
import org.eclipse.jface.viewers.ISelection;
8
import org.eclipse.jface.viewers.TreeNode;
9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.handlers.HandlerUtil;
11

    
12
import eu.etaxonomy.cdm.model.molecular.Sequence;
13
import eu.etaxonomy.taxeditor.editor.EditorUtil;
14
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
15
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
16
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditorInput;
17

    
18

    
19

    
20
/**
21
 * Opens the alignment editor from the CDM tree.
22
 *
23
 * @author Ben Stöver
24
 * @author pplitzner
25
 */
26
public class EditSequenceHandler extends AbstractHandler {
27

    
28
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EditSequenceHandler.class);
29

    
30
    @Override
31
    public Object execute(ExecutionEvent event) throws ExecutionException {
32
        ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
33
        TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
34
        if(treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence){
35
            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.
36
            try {
37
                TaxeditorMolecularPlugin.getDefault().getWorkbench()
38
                .getActiveWorkbenchWindow().getActivePage().openEditor(input, AlignmentEditor.ID);
39
            }
40
            catch (PartInitException e) {
41
                logger.error("Could not open AlignmentEditor", e);
42
            }
43
        }
44
        return null;
45
    }
46
}
(7-7/18)