Project

General

Profile

Download (2.02 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.Messages;
15
import eu.etaxonomy.taxeditor.molecular.TaxeditorMolecularPlugin;
16
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
17
import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditorInput;
18

    
19

    
20

    
21
/**
22
 * Opens the alignment editor from the CDM tree.
23
 *
24
 * @author Ben Stöver
25
 * @author pplitzner
26
 */
27
public class EditSequenceHandler extends AbstractHandler {
28
    private org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(EditSequenceHandler.class);
29

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