merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / handler / EditSequenceHandler.java
1 package eu.etaxonomy.taxeditor.editor.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.editor.molecular.AlignmentEditorInput;
15
16
17
18 /**
19 * Opens the alignment editor from the CDM tree.
20 *
21 * @author Ben Stöver
22 * @author pplitzner
23 */
24 public class EditSequenceHandler extends AbstractHandler {
25 @Override
26 public Object execute(ExecutionEvent event) throws ExecutionException {
27 ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
28 TreeNode treeNodeOfSelection = EditorUtil.getTreeNodeOfSelection(currentSelection);
29 if(treeNodeOfSelection != null && treeNodeOfSelection.getValue() instanceof Sequence){
30 AlignmentEditorInput input = new AlignmentEditorInput((Sequence)treeNodeOfSelection.getValue()); //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.
31 try {
32 EditorUtil.open(input);
33 }
34 catch (PartInitException e) {
35 // TODO Auto-generated catch block
36 e.printStackTrace();
37 }
38 }
39
40 return null;
41 }
42 }